~ares-developers/ares/gd03

« back to all changes in this revision

Viewing changes to src/Misc/SWTypes.h

  • Committer: Renegade
  • Date: 2010-05-29 08:12:17 UTC
  • Revision ID: git-v1:0a1bb6321f04d723afe64d1b843dc87b4da783ec
Creating /trunk/src.

git-svn-id: svn://svn.renegadeprojects.com/ares/trunk@622 859b54a9-7a54-0410-aeb3-f8d2f1fa40fd

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef NEW_SW_TYPE_H
 
2
#define NEW_SW_TYPE_H
 
3
 
 
4
#include "../Ext/SWType/Body.h"
 
5
 
 
6
class SWTypeExt;
 
7
 
 
8
// New SW Type framework. See SWTypes/*.h for examples of implemented ones. Don't touch yet, still WIP.
 
9
class NewSWType
 
10
{
 
11
        protected:
 
12
                int TypeIndex;
 
13
                bool Registered;
 
14
 
 
15
                void Register()
 
16
                        { Array.AddItem(this); this->TypeIndex = Array.Count; }
 
17
 
 
18
        public:
 
19
                NewSWType()
 
20
                        { Registered = 0; Register(); };
 
21
 
 
22
                virtual ~NewSWType()
 
23
                        { };
 
24
 
 
25
                static void Init();
 
26
 
 
27
                virtual bool CanFireAt(CellStruct* pCoords)
 
28
                        { return 1; }
 
29
                virtual bool Launch(SuperClass* pSW, CellStruct* pCoords, byte IsPlayer) = 0;
 
30
 
 
31
                virtual void LoadFromINI(
 
32
                        SWTypeExt::ExtData *pData,
 
33
                        SuperWeaponTypeClass *pSW, CCINIClass *pINI) = 0;
 
34
 
 
35
                virtual const char * GetTypeString()
 
36
                        { return ""; }
 
37
                virtual const int GetTypeIndex()
 
38
                        { return TypeIndex; }
 
39
 
 
40
        static DynamicVectorClass<NewSWType *> Array;
 
41
 
 
42
        static NewSWType * GetNthItem(int i)
 
43
                { return Array.GetItem(i - FIRST_SW_TYPE); }
 
44
 
 
45
        static int FindIndex(const char *Type) {
 
46
                for(int i = 0; i < Array.Count; ++i) {
 
47
                        if(!strcmp(Array.GetItem(i)->GetTypeString(), Type)) {
 
48
                                return FIRST_SW_TYPE + i;
 
49
                        }
 
50
                }
 
51
                return -1;
 
52
        }
 
53
};
 
54
 
 
55
// state machines - create one to use delayed effects [create a child class per NewSWType, obviously]
 
56
// i.e. start anim/sound 1 frame after clicking, fire a damage wave 25 frames later, and play second sound 50 frames after that...
 
57
class SWStateMachine {
 
58
        public:
 
59
                static DynamicVectorClass<SWStateMachine *> Array;
 
60
        protected:
 
61
                TimerStruct  Clock;
 
62
                SuperClass * Super;
 
63
                NewSWType  * Type;
 
64
                CellStruct   Coords;
 
65
        public:
 
66
                bool Finished() { return Clock.IsDone(); }
 
67
 
 
68
                int TimePassed() { return Unsorted::CurrentFrame - Clock.StartTime; }
 
69
 
 
70
                SWStateMachine(int Duration, CellStruct XY, SuperClass *pSuper, NewSWType * pSWType)
 
71
                        : Type(pSWType), Super(pSuper), Coords(XY) {
 
72
                        Clock.Start(Duration);
 
73
                        Array.AddItem(this);
 
74
                }
 
75
 
 
76
                virtual ~SWStateMachine() {
 
77
                        auto t = this;
 
78
                        Array.RemoveItem(Array.FindItemIndex(&t));
 
79
                }
 
80
 
 
81
                virtual void Update() {};
 
82
 
 
83
                static void UpdateAll();
 
84
 
 
85
                SWTypeExt::ExtData * FindExtData () {
 
86
                        return SWTypeExt::ExtMap.Find(this->Super->Type);
 
87
                }
 
88
};
 
89
 
 
90
class UnitDeliveryStateMachine : public SWStateMachine {
 
91
        public:
 
92
                UnitDeliveryStateMachine(int Duration, CellStruct XY, SuperClass *pSuper, NewSWType * pSWType)
 
93
                        : SWStateMachine(Duration, XY, pSuper, pSWType) {};
 
94
                virtual void Update();
 
95
 
 
96
                void PlaceUnits();
 
97
};
 
98
 
 
99
#endif