~ares-developers/ares/gd03

« back to all changes in this revision

Viewing changes to Ext/SWType/Body.cpp

  • 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
 
#include "Body.h"
2
 
#include "../../Misc/SWTypes.h"
3
 
 
4
 
template<> const DWORD Extension<SuperWeaponTypeClass>::Canary = 0x55555555;
5
 
Container<SWTypeExt> SWTypeExt::ExtMap;
6
 
 
7
 
template<> SWTypeExt::TT *Container<SWTypeExt>::SavingObject = NULL;
8
 
template<> IStream *Container<SWTypeExt>::SavingStream = NULL;
9
 
 
10
 
SuperWeaponTypeClass *SWTypeExt::CurrentSWType = NULL;
11
 
 
12
 
void SWTypeExt::ExtData::InitializeConstants(SuperWeaponTypeClass *pThis)
13
 
{
14
 
        if(!NewSWType::Array.Count) {
15
 
                NewSWType::Init();
16
 
        }
17
 
 
18
 
        MouseCursor *Cursor = &this->SW_Cursor;
19
 
        Cursor->Frame = 53; // Attack
20
 
        Cursor->Count = 5;
21
 
        Cursor->Interval = 5; // test?
22
 
        Cursor->MiniFrame = 52;
23
 
        Cursor->MiniCount = 1;
24
 
        Cursor->HotX = hotspx_center;
25
 
        Cursor->HotY = hotspy_middle;
26
 
 
27
 
        Cursor = &this->SW_NoCursor;
28
 
        Cursor->Frame = 0;
29
 
        Cursor->Count = 1;
30
 
        Cursor->Interval = 5;
31
 
        Cursor->MiniFrame = 1;
32
 
        Cursor->MiniCount = 1;
33
 
        Cursor->HotX = hotspx_center;
34
 
        Cursor->HotY = hotspy_middle;
35
 
}
36
 
 
37
 
void SWTypeExt::ExtData::InitializeRuled(SuperWeaponTypeClass *pThis)
38
 
{
39
 
        this->SpyPlane_TypeIndex = AircraftTypeClass::FindIndex("SPYP");
40
 
        this->Nuke_Siren = RulesClass::Global()->DigSound;
41
 
}
42
 
 
43
 
void SWTypeExt::ExtData::LoadFromINIFile(SuperWeaponTypeClass *pThis, CCINIClass *pINI)
44
 
{
45
 
        const char * section = pThis->get_ID();
46
 
 
47
 
        if(!pINI->GetSection(section)) {
48
 
                return;
49
 
        }
50
 
 
51
 
        INI_EX exINI(pINI);
52
 
 
53
 
        this->SpyPlane_Count.Read(&exINI, section, "SpyPlane.Count");
54
 
 
55
 
        this->SpyPlane_TypeIndex.Read(&exINI, section, "SpyPlane.Type");
56
 
 
57
 
        this->SpyPlane_Mission.Read(&exINI, section, "SpyPlane.Mission");
58
 
 
59
 
        this->Nuke_Siren.Read(&exINI, section, "Nuke.Sound");
60
 
        this->EVA_Ready.Read(&exINI, section, "EVA.Ready");
61
 
        this->EVA_Activated.Read(&exINI, section, "EVA.Activated");
62
 
        this->EVA_Detected.Read(&exINI, section, "EVA.Detected");
63
 
 
64
 
        if(exINI.ReadString(section, "Action") && !strcmp(exINI.value(), "Custom")) {
65
 
                pThis->Action = SW_YES_CURSOR;
66
 
        }
67
 
 
68
 
        if(exINI.ReadString(section, "Type")) {
69
 
                int customType = NewSWType::FindIndex(exINI.value());
70
 
                if(customType > -1) {
71
 
                        pThis->Type = customType;
72
 
                }
73
 
        }
74
 
 
75
 
        this->SW_FireToShroud.Read(&exINI, section, "Super.FireIntoShroud");
76
 
        this->SW_AutoFire.Read(&exINI, section, "Super.AutoFire");
77
 
        this->SW_RadarEvent.Read(&exINI, section, "Super.CreateRadarEvent");
78
 
 
79
 
        this->Money_Amount.Read(&exINI, section, "Money.Amount");
80
 
 
81
 
        this->SW_Anim.Parse(&exINI, section, "SW.Animation");
82
 
        this->SW_AnimHeight.Read(&exINI, section, "SW.AnimationHeight");
83
 
 
84
 
        this->SW_Sound.Read(&exINI, section, "SW.Sound");
85
 
 
86
 
        this->SW_Cursor.Read(&exINI, section, "Cursor");
87
 
        this->SW_NoCursor.Read(&exINI, section, "NoCursor");
88
 
 
89
 
        int Type = pThis->Type - FIRST_SW_TYPE;
90
 
        if(Type >= 0 && Type < NewSWType::Array.Count ) {
91
 
                NewSWType *swt = NewSWType::GetNthItem(pThis->Type);
92
 
                swt->LoadFromINI(this, pThis, pINI);
93
 
        }
94
 
 
95
 
        this->CameoPal.LoadFromINI(pINI, pThis->ID, "SidebarPalette");
96
 
}
97
 
 
98
 
bool __stdcall SWTypeExt::SuperClass_Launch(SuperClass* pThis, CellStruct* pCoords, byte IsPlayer)
99
 
{
100
 
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pThis->Type);
101
 
 
102
 
        if(pData->EVA_Activated != -1) {
103
 
                VoxClass::PlayIndex(pData->EVA_Activated);
104
 
        }
105
 
 
106
 
        int Money_Amount = pData->Money_Amount;
107
 
        if(Money_Amount > 0) {
108
 
                DEBUGLOG("House %d gets %d credits\n", pThis->Owner->ArrayIndex, Money_Amount);
109
 
                pThis->Owner->GiveMoney(Money_Amount);
110
 
        } else if(Money_Amount < 0) {
111
 
                DEBUGLOG("House %d loses %d credits\n", pThis->Owner->ArrayIndex, -Money_Amount);
112
 
                pThis->Owner->TakeMoney(-Money_Amount);
113
 
        }
114
 
 
115
 
        CoordStruct coords;
116
 
        MapClass::Instance->GetCellAt(pCoords)->GetCoords(&coords);
117
 
 
118
 
        if(pData->SW_Anim != NULL) {
119
 
                coords.Z += pData->SW_AnimHeight;
120
 
                AnimClass *placeholder;
121
 
                GAME_ALLOC(AnimClass, placeholder, pData->SW_Anim, &coords);
122
 
        }
123
 
 
124
 
        if(pData->SW_Sound != -1) {
125
 
                VocClass::PlayAt(pData->SW_Sound, &coords, NULL);
126
 
        }
127
 
 
128
 
        if(pData->SW_RadarEvent) {
129
 
                RadarEventClass::Create(RADAREVENT_SUPERWEAPONLAUNCHED, *pCoords);
130
 
        }
131
 
 
132
 
        int TypeIdx = pThis->Type->Type;
133
 
        RET_UNLESS(TypeIdx >= FIRST_SW_TYPE);
134
 
        return NewSWType::GetNthItem(TypeIdx)->Launch(pThis, pCoords, IsPlayer);
135
 
}
136
 
 
137
 
void Container<SWTypeExt>::InvalidatePointer(void *ptr) {
138
 
        AnnounceInvalidPointer(SWTypeExt::CurrentSWType, ptr);
139
 
}
140
 
 
141
 
// =============================
142
 
// load/save
143
 
 
144
 
void Container<SWTypeExt>::Load(SuperWeaponTypeClass *pThis, IStream *pStm) {
145
 
        SWTypeExt::ExtData* pData = this->LoadKey(pThis, pStm);
146
 
 
147
 
        SWIZZLE(pData->SW_Anim);
148
 
}
149
 
 
150
 
// =============================
151
 
// container hooks
152
 
 
153
 
DEFINE_HOOK(6CE6F6, SuperWeaponTypeClass_CTOR, 5)
154
 
{
155
 
        GET(SuperWeaponTypeClass*, pItem, EAX);
156
 
 
157
 
        SWTypeExt::ExtMap.FindOrAllocate(pItem);
158
 
        return 0;
159
 
}
160
 
 
161
 
DEFINE_HOOK(6CEFE0, SuperWeaponTypeClass_DTOR, 8)
162
 
{
163
 
        GET(SuperWeaponTypeClass*, pItem, ECX);
164
 
 
165
 
        SWTypeExt::ExtMap.Remove(pItem);
166
 
        return 0;
167
 
}
168
 
 
169
 
DEFINE_HOOK(6CE800, SuperWeaponTypeClass_SaveLoad_Prefix, A)
170
 
DEFINE_HOOK_AGAIN(6CE8D0, SuperWeaponTypeClass_SaveLoad_Prefix, 8)
171
 
{
172
 
        GET_STACK(SWTypeExt::TT*, pItem, 0x4);
173
 
        GET_STACK(IStream*, pStm, 0x8);
174
 
 
175
 
        Container<SWTypeExt>::SavingObject = pItem;
176
 
        Container<SWTypeExt>::SavingStream = pStm;
177
 
 
178
 
        return 0;
179
 
}
180
 
 
181
 
DEFINE_HOOK(6CE8BE, SuperWeaponTypeClass_Load_Suffix, 7)
182
 
{
183
 
        SWTypeExt::ExtMap.LoadStatic();
184
 
        return 0;
185
 
}
186
 
 
187
 
DEFINE_HOOK(6CE8EA, SuperWeaponTypeClass_Save_Suffix, 3)
188
 
{
189
 
        SWTypeExt::ExtMap.SaveStatic();
190
 
        return 0;
191
 
}
192
 
 
193
 
DEFINE_HOOK(6CEE43, SuperWeaponTypeClass_LoadFromINI, A)
194
 
DEFINE_HOOK_AGAIN(6CEE50, SuperWeaponTypeClass_LoadFromINI, A)
195
 
{
196
 
        GET(SuperWeaponTypeClass*, pItem, EBP);
197
 
        GET_STACK(CCINIClass*, pINI, 0x3FC);
198
 
 
199
 
        SWTypeExt::ExtMap.LoadFromINI(pItem, pINI);
200
 
        return 0;
201
 
}