2
#include "../../Misc/SWTypes.h"
4
template<> const DWORD Extension<SuperWeaponTypeClass>::Canary = 0x55555555;
5
Container<SWTypeExt> SWTypeExt::ExtMap;
7
template<> SWTypeExt::TT *Container<SWTypeExt>::SavingObject = NULL;
8
template<> IStream *Container<SWTypeExt>::SavingStream = NULL;
10
SuperWeaponTypeClass *SWTypeExt::CurrentSWType = NULL;
12
void SWTypeExt::ExtData::InitializeConstants(SuperWeaponTypeClass *pThis)
14
if(!NewSWType::Array.Count) {
18
MouseCursor *Cursor = &this->SW_Cursor;
19
Cursor->Frame = 53; // Attack
21
Cursor->Interval = 5; // test?
22
Cursor->MiniFrame = 52;
23
Cursor->MiniCount = 1;
24
Cursor->HotX = hotspx_center;
25
Cursor->HotY = hotspy_middle;
27
Cursor = &this->SW_NoCursor;
31
Cursor->MiniFrame = 1;
32
Cursor->MiniCount = 1;
33
Cursor->HotX = hotspx_center;
34
Cursor->HotY = hotspy_middle;
37
void SWTypeExt::ExtData::InitializeRuled(SuperWeaponTypeClass *pThis)
39
this->SpyPlane_TypeIndex = AircraftTypeClass::FindIndex("SPYP");
40
this->Nuke_Siren = RulesClass::Global()->DigSound;
43
void SWTypeExt::ExtData::LoadFromINIFile(SuperWeaponTypeClass *pThis, CCINIClass *pINI)
45
const char * section = pThis->get_ID();
47
if(!pINI->GetSection(section)) {
53
this->SpyPlane_Count.Read(&exINI, section, "SpyPlane.Count");
55
this->SpyPlane_TypeIndex.Read(&exINI, section, "SpyPlane.Type");
57
this->SpyPlane_Mission.Read(&exINI, section, "SpyPlane.Mission");
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");
64
if(exINI.ReadString(section, "Action") && !strcmp(exINI.value(), "Custom")) {
65
pThis->Action = SW_YES_CURSOR;
68
if(exINI.ReadString(section, "Type")) {
69
int customType = NewSWType::FindIndex(exINI.value());
71
pThis->Type = customType;
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");
79
this->Money_Amount.Read(&exINI, section, "Money.Amount");
81
this->SW_Anim.Parse(&exINI, section, "SW.Animation");
82
this->SW_AnimHeight.Read(&exINI, section, "SW.AnimationHeight");
84
this->SW_Sound.Read(&exINI, section, "SW.Sound");
86
this->SW_Cursor.Read(&exINI, section, "Cursor");
87
this->SW_NoCursor.Read(&exINI, section, "NoCursor");
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);
95
this->CameoPal.LoadFromINI(pINI, pThis->ID, "SidebarPalette");
98
bool __stdcall SWTypeExt::SuperClass_Launch(SuperClass* pThis, CellStruct* pCoords, byte IsPlayer)
100
SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pThis->Type);
102
if(pData->EVA_Activated != -1) {
103
VoxClass::PlayIndex(pData->EVA_Activated);
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);
116
MapClass::Instance->GetCellAt(pCoords)->GetCoords(&coords);
118
if(pData->SW_Anim != NULL) {
119
coords.Z += pData->SW_AnimHeight;
120
AnimClass *placeholder;
121
GAME_ALLOC(AnimClass, placeholder, pData->SW_Anim, &coords);
124
if(pData->SW_Sound != -1) {
125
VocClass::PlayAt(pData->SW_Sound, &coords, NULL);
128
if(pData->SW_RadarEvent) {
129
RadarEventClass::Create(RADAREVENT_SUPERWEAPONLAUNCHED, *pCoords);
132
int TypeIdx = pThis->Type->Type;
133
RET_UNLESS(TypeIdx >= FIRST_SW_TYPE);
134
return NewSWType::GetNthItem(TypeIdx)->Launch(pThis, pCoords, IsPlayer);
137
void Container<SWTypeExt>::InvalidatePointer(void *ptr) {
138
AnnounceInvalidPointer(SWTypeExt::CurrentSWType, ptr);
141
// =============================
144
void Container<SWTypeExt>::Load(SuperWeaponTypeClass *pThis, IStream *pStm) {
145
SWTypeExt::ExtData* pData = this->LoadKey(pThis, pStm);
147
SWIZZLE(pData->SW_Anim);
150
// =============================
153
DEFINE_HOOK(6CE6F6, SuperWeaponTypeClass_CTOR, 5)
155
GET(SuperWeaponTypeClass*, pItem, EAX);
157
SWTypeExt::ExtMap.FindOrAllocate(pItem);
161
DEFINE_HOOK(6CEFE0, SuperWeaponTypeClass_DTOR, 8)
163
GET(SuperWeaponTypeClass*, pItem, ECX);
165
SWTypeExt::ExtMap.Remove(pItem);
169
DEFINE_HOOK(6CE800, SuperWeaponTypeClass_SaveLoad_Prefix, A)
170
DEFINE_HOOK_AGAIN(6CE8D0, SuperWeaponTypeClass_SaveLoad_Prefix, 8)
172
GET_STACK(SWTypeExt::TT*, pItem, 0x4);
173
GET_STACK(IStream*, pStm, 0x8);
175
Container<SWTypeExt>::SavingObject = pItem;
176
Container<SWTypeExt>::SavingStream = pStm;
181
DEFINE_HOOK(6CE8BE, SuperWeaponTypeClass_Load_Suffix, 7)
183
SWTypeExt::ExtMap.LoadStatic();
187
DEFINE_HOOK(6CE8EA, SuperWeaponTypeClass_Save_Suffix, 3)
189
SWTypeExt::ExtMap.SaveStatic();
193
DEFINE_HOOK(6CEE43, SuperWeaponTypeClass_LoadFromINI, A)
194
DEFINE_HOOK_AGAIN(6CEE50, SuperWeaponTypeClass_LoadFromINI, A)
196
GET(SuperWeaponTypeClass*, pItem, EBP);
197
GET_STACK(CCINIClass*, pINI, 0x3FC);
199
SWTypeExt::ExtMap.LoadFromINI(pItem, pINI);