223
223
// generate random coords if the passed ones are empty
224
224
if(Coords.X == 0 && Coords.Y == 0) {
225
for(; !MapClass::Instance->CellExists(&Coords);) {
225
while(!MapClass::Instance->CellExists(&Coords)) {
226
226
Coords.X = (short)ScenarioClass::Instance->Random.RandomRanged(0, MapClass::Instance->unknown_12C);
227
227
Coords.Y = (short)ScenarioClass::Instance->Random.RandomRanged(0, MapClass::Instance->unknown_130);
292
292
// this is a complete rewrite of LightningStorm::Update.
293
293
DEFINE_HOOK(53A6C0, LightningStorm_Update, 5) {
294
294
if(SuperClass* pSuper = SW_LightningStorm::CurrentLightningStorm) {
296
// switch lightning (most likely for nuke)
297
int* tmp1 = (int*)0x827FC8;
298
int* tmp2 = (int*)0x827FCC;
300
int a = *tmp1 + *tmp2;
301
if(a < Unsorted::CurrentFrame) {
296
// switch lightning for nuke
297
if(NukeFlash::Duration() != -1) {
298
if(NukeFlash::StartTime() + NukeFlash::Duration() < Unsorted::CurrentFrame) {
302
299
int status = LightningStorm::Status();
303
300
if(status == 1) {
304
301
LightningStorm::Status(2);
305
*tmp1 = Unsorted::CurrentFrame;
302
NukeFlash::StartTime(Unsorted::CurrentFrame);
303
NukeFlash::Duration(15);
307
304
ScenarioClass::Instance->UpdateLighting();
308
305
MapClass::Instance->RedrawSidebar(1);
309
306
} else if(status == 2) {
317
314
PsyDom::Update();
318
315
ChronoScreenEffect::Update();
320
// remove all clouds from list that did strike already
321
DynamicVectorClass<AnimClass*>* pAnims0 = (DynamicVectorClass<AnimClass*>*)(0xA9FA18);
322
if(pAnims0->Count > 0) {
323
for(int i=pAnims0->Count-1; i>=0; --i) {
324
if(AnimClass *pAnim = pAnims0->GetItem(i)) {
317
// remove all bolts from the list that are halfway done
318
if(LightningStorm::BoltsPresent->Count > 0) {
319
for(int i=LightningStorm::BoltsPresent->Count-1; i>=0; --i) {
320
if(AnimClass *pAnim = LightningStorm::BoltsPresent->GetItem(i)) {
325
321
if(pAnim->CurrentFrame >= pAnim->Type->GetImage()->Frames / 2) {
326
pAnims0->RemoveItem(i);
322
LightningStorm::BoltsPresent->RemoveItem(i);
332
328
// find the clouds that should strike right now
333
DynamicVectorClass<AnimClass*>* pAnims1 = (DynamicVectorClass<AnimClass*>*)(0xA9FA60);
334
for(int i=pAnims1->Count-1; i>=0; --i) {
335
if(AnimClass *pAnim = pAnims1->GetItem(i)) {
329
for(int i=LightningStorm::CloudsManifesting->Count-1; i>=0; --i) {
330
if(AnimClass *pAnim = LightningStorm::CloudsManifesting->GetItem(i)) {
336
331
if(pAnim->CurrentFrame >= pAnim->Type->GetImage()->Frames / 2) {
337
332
CoordStruct crdStrike;
338
333
pAnim->GetCoords(&crdStrike);
339
334
LightningStorm::Strike2(crdStrike);
340
pAnims1->RemoveItem(i);
335
LightningStorm::CloudsManifesting->RemoveItem(i);
345
DynamicVectorClass<AnimClass*>* pAnims2 = (DynamicVectorClass<AnimClass*>*)(0xA9F9D0);
346
if(pAnims2->Count <= 0) {
340
// all currently present clouds have to disappear first
341
if(LightningStorm::CloudsPresent->Count <= 0) {
347
342
// end the lightning storm
348
343
if(LightningStorm::TimeToEnd()) {
349
344
if(LightningStorm::Active()) {
357
352
LightningStorm::TimeToEnd(false);
360
for(int i=pAnims2->Count-1; i>=0; --i) {
361
if(AnimClass *pAnim = pAnims2->GetItem(i)) {
355
for(int i=LightningStorm::CloudsPresent->Count-1; i>=0; --i) {
356
if(AnimClass *pAnim = LightningStorm::CloudsPresent->GetItem(i)) {
362
357
if(pAnim->CurrentFrame >= pAnim->Type->GetImage()->Frames - 1) {
363
pAnims2->RemoveItem(i);
358
LightningStorm::CloudsPresent->RemoveItem(i);
462
457
// is this spot far away from another cloud?
463
458
if(pData->Weather_Separation > 0) {
464
DynamicVectorClass<AnimClass*>* pAnims = (DynamicVectorClass<AnimClass*>*)(0xA9F9D0);
465
for(int k=0; k<pAnims->Count; ++k) {
459
for(int k=0; k<LightningStorm::CloudsPresent->Count; ++k) {
466
460
// assume success and disprove.
467
CellStruct *pCell2 = &pAnims->GetItem(k)->GetCell()->MapCoords;
461
CellStruct *pCell2 = &LightningStorm::CloudsPresent->GetItem(k)->GetCell()->MapCoords;
468
462
int dist = std::abs(pCell2->X - cell.X) + std::abs(pCell2->Y - cell.Y);
469
463
if(dist < pData->Weather_Separation.Get()) {
515
509
pCell->GetCoordsWithBridge(&Coords);
517
511
// create a cloud animation
518
if(Coords != *(CoordStruct*)(0xA9FA30)) {
512
if(Coords != LightningStorm::EmptyCoords) {
519
513
// select the anim
520
514
AnimTypeClass* pAnimType = pData->Weather_Clouds.GetItem(ScenarioClass::Instance->Random.Random() % pData->Weather_Clouds.Count);
523
517
if(pData->Weather_CloudHeight < 0) {
524
518
if(pData->Weather_Bolts.Count) {
525
519
AnimTypeClass* pBoltAnim = pData->Weather_Bolts.GetItem(0);
526
pData->Weather_CloudHeight = (int)Game::F2I(((pBoltAnim->GetImage()->Height / 2) - 0.5) * *(double*)(0xB0CDD8));
520
pData->Weather_CloudHeight = (int)Game::F2I(((pBoltAnim->GetImage()->Height / 2) - 0.5) * LightningStorm::CloudHeightFactor);
529
523
Coords.Z += pData->Weather_CloudHeight;
531
// create it and do hacky book keeping.
525
// create the cloud and do some book keeping.
532
526
AnimClass* pAnim = NULL;
533
527
GAME_ALLOC(AnimClass, pAnim, pAnimType, &Coords);
536
DynamicVectorClass<AnimClass*>* pAnims1 = (DynamicVectorClass<AnimClass*>*)(0xA9FA60);
537
DynamicVectorClass<AnimClass*>* pAnims2 = (DynamicVectorClass<AnimClass*>*)(0xA9F9D0);
539
pAnims1->AddItem(pAnim);
540
pAnims2->AddItem(pAnim);
530
LightningStorm::CloudsManifesting->AddItem(pAnim);
531
LightningStorm::CloudsPresent->AddItem(pAnim);
561
552
CellClass* pCell = MapClass::Instance->GetCellAt(&Coords);
562
553
pCell->GetCoordsWithBridge(&Coords);
564
if(Coords != *(CoordStruct*)(0xA9FA30)) {
555
if(Coords != LightningStorm::EmptyCoords) {
566
557
// create a bolt animation
567
558
if(pData->Weather_Bolts.Count) {
572
563
GAME_ALLOC(AnimClass, pAnim, pAnimType, &Coords);
575
DynamicVectorClass<AnimClass*>* pAnims = (DynamicVectorClass<AnimClass*>*)(0xA9FA18);
576
pAnims->AddItem(pAnim);
566
LightningStorm::BoltsPresent->AddItem(pAnim);
844
834
ScenarioClass::Instance->Timer4.unknown = R->Stack<int>(0x28);
845
835
ScenarioClass::Instance->Timer4.TimeLeft = 1;
848
*(int*)0x827FC8 = Unsorted::CurrentFrame;
849
*(int*)0x827FCC = 30;
837
// enable the nuke flash
838
NukeFlash::StartTime(Unsorted::CurrentFrame);
839
NukeFlash::Duration(30);
851
841
SWTypeExt::ChangeLighting(pData->NukeSW);
852
842
MapClass::Instance->RedrawSidebar(1);