/**************************************************************************** * KGen.SNL * Base logic for Kewlett Generator * DAVIDE Jan 19 2003 ****************************************************************************/ ///////////////////////////////////////////////////////////////////// // Globals ///////////////////////////////////////////////////////////////////// VAR g_GenX, g_GenY, g_GenZ; VAR g_Pump1, g_Pump2, g_Pump3, g_Pump4; VAR g_EngineerSP, g_GuardSP1, g_GuardSP2, g_GuardSP3, g_GuardSP4; VAR g_NeedFixing, g_FixTime; VAR g_PumpToFix; VAR g_EngineerAlive; VAR g_CalledEngineer; VAR g_RespawnTimerStarted; VAR g_RespawnTimer; VAR g_MaxRespawnTime; VAR g_TurretsOn; ///////////////////////////////////////////////////////////////////// // Prototypes ///////////////////////////////////////////////////////////////////// CreatePump( pumpCode ); OnDestroyPump(); /**************************************************************************** * Called when the KGen are first created * DAVIDE Jan 19 2003 ****************************************************************************/ OnCreate() { g_GenX = GetX(THIS); g_GenY = GetY(THIS); g_GenZ = GetZ(THIS); g_Pump1 = 0; g_Pump2 = 0; g_Pump3 = 0; g_Pump4 = 0; g_EngineerSP = 0; g_NeedFixing = 0; g_PumpToFix = -1; g_EngineerAlive = 0; g_CalledEngineer = 0; g_GuardSP1 = 0; g_GuardSP2 = 0; g_GuardSP3 = 0; g_GuardSP4 = 0; g_RespawnTimerStarted = 0; g_RespawnTimer = 0; g_MaxRespawnTime = 60 * 4; g_TurretsOn = 1; AddProperty1( THIS, "NeedFixing", g_NeedFixing ); } /***************************************************************************/ /**************************************************************************** * Called when the Level starts * DAVIDE Jan 19 2003 ****************************************************************************/ OnBeginScript() { // create the generator pumps CreatePump( 0 ); CreatePump( 1 ); CreatePump( 2 ); CreatePump( 3 ); /* // create the engineer spawn point g_EngineerSP = CreateObject( "OBL\SpawnPoint.OBL", (g_GenX + 180), g_GenY, g_GenZ ); if(g_EngineerSP != 0) { SetDirection( g_EngineerSP, 270 ); //SetProperty1( g_EngineerSP, "SpawnDelay", g_SpawnDelay ); SetProperty1( g_EngineerSP, "CurrentDelay", 5 ); SetProperty1( g_EngineerSP, "MaxSpawn", 1 ); //SetProperty1( g_EngineerSP, "SpawnRange", 0 ); SetProperty1( g_EngineerSP, "SpawnOffset", 0 ); SetProperty1( g_EngineerSP, "CanSpawn", 0 ); SetProperty1( g_EngineerSP, "SpawnHeightOffset", 800 ); // add properties that will allow the designer to determine what type of kewletts // will be spawned by this spawnpoint. //SetPropertyString(g_EngineerSP, "Personality", "Aggressive"); SetPropertyString(g_EngineerSP, "Colour", "AICOLOUR_ENGINEER"); SetProperty1( g_EngineerSP, "HasVisor", 0 ); //SetProperty1(g_EngineerSP, "MaximumDistanceConsidered", 300, "AI"); OnFinishedLoading(g_EngineerSP); } // create the 4 guard spawn points g_GuardSP1 = CreateObject( "OBL\SpawnPoint.OBL", (g_GenX + 150), g_GenY, (g_GenZ + 150) ); if(g_GuardSP1 != 0) { SetDirection( g_GuardSP1, 45 ); SetProperty1( g_GuardSP1, "CurrentDelay", 10 ); SetProperty1( g_GuardSP1, "MaxSpawn", 1 ); SetProperty1( g_GuardSP1, "SpawnOffset", 0 ); SetProperty1( g_GuardSP1, "CanSpawn", 0 ); SetProperty1( g_GuardSP1, "SpawnHeightOffset", 800 ); OnFinishedLoading(g_GuardSP1); } g_GuardSP2 = CreateObject( "OBL\SpawnPoint.OBL", (g_GenX + 150), g_GenY, (g_GenZ - 150) ); if(g_GuardSP2 != 0) { SetDirection( g_GuardSP2, 135 ); SetProperty1( g_GuardSP2, "CurrentDelay", 10 ); SetProperty1( g_GuardSP2, "MaxSpawn", 1 ); SetProperty1( g_GuardSP2, "SpawnOffset", 0 ); SetProperty1( g_GuardSP2, "CanSpawn", 0 ); SetProperty1( g_GuardSP2, "SpawnHeightOffset", 800 ); OnFinishedLoading(g_GuardSP2); } g_GuardSP3 = CreateObject( "OBL\SpawnPoint.OBL", (g_GenX - 150), g_GenY, (g_GenZ - 150) ); if(g_GuardSP3 != 0) { SetDirection( g_GuardSP3, 225 ); SetProperty1( g_GuardSP3, "CurrentDelay", 10 ); SetProperty1( g_GuardSP3, "MaxSpawn", 1 ); SetProperty1( g_GuardSP3, "SpawnOffset", 0 ); SetProperty1( g_GuardSP3, "CanSpawn", 0 ); SetProperty1( g_GuardSP3, "SpawnHeightOffset", 800 ); OnFinishedLoading(g_GuardSP3); } g_GuardSP4 = CreateObject( "OBL\SpawnPoint.OBL", (g_GenX - 150), g_GenY, (g_GenZ + 150) ); if(g_GuardSP4 != 0) { SetDirection( g_GuardSP4, 315 ); SetProperty1( g_GuardSP4, "CurrentDelay", 10 ); SetProperty1( g_GuardSP4, "MaxSpawn", 1 ); SetProperty1( g_GuardSP4, "SpawnOffset", 0 ); SetProperty1( g_GuardSP4, "CanSpawn", 0 ); SetProperty1( g_GuardSP4, "SpawnHeightOffset", 800 ); OnFinishedLoading(g_GuardSP4); } */ } /***************************************************************************/ /**************************************************************************** * Called each Tick * DAVIDE Jan 28 2003 ****************************************************************************/ /* OnTick(seconds) if(g_RespawnTimerStarted == 1) { g_RespawnTimer = g_RespawnTimer - seconds; if(g_RespawnTimer <= 0) { // time to call the engineer g_CalledEngineer = 0; OnDestroyPump(); g_RespawnTimerStarted = 0; } } } */ /***************************************************************************/ /**************************************************************************** * CreatePump * Creates the specified pump * DAVIDE Jan 19 2003 ****************************************************************************/ CreatePump( pumpCode ) { if(pumpCode == 0) { g_Pump1 = CreateObject( "KGen_Pump.OBL", (g_GenX + 26), (g_GenY + 83), (g_GenZ + 40) ); SetObjectName(g_Pump1, "Pump1"); SetDirectionXYZ(g_Pump1, 90, 0, 0); SetOrientationOfChildObject(THIS, g_Pump1); return; } if(pumpCode == 1) { g_Pump2 = CreateObject( "KGen_Pump.OBL", (g_GenX - 26), (g_GenY + 83), (g_GenZ + 40) ); SetObjectName(g_Pump2, "Pump2"); SetDirectionXYZ(g_Pump2, 90, 0, 0); SetOrientationOfChildObject(THIS, g_Pump2); return; } if(pumpCode == 2) { g_Pump3 = CreateObject( "KGen_Pump.OBL", (g_GenX - 26), (g_GenY + 50), (g_GenZ - 87) ); SetObjectName(g_Pump3, "Pump3"); SetDirectionXYZ(g_Pump3, 0, 0, 0); SetOrientationOfChildObject(THIS, g_Pump3); return; } if(pumpCode == 3) { g_Pump4 = CreateObject( "KGen_Pump.OBL", (g_GenX + 26), (g_GenY + 50), (g_GenZ - 87) ); SetObjectName(g_Pump4, "Pump4"); SetDirectionXYZ(g_Pump4, 0, 0, 0); SetOrientationOfChildObject(THIS, g_Pump4); return; } } /***************************************************************************/ /**************************************************************************** * Called when destroyed * DAVIDE Jan 19 2003 ****************************************************************************/ OnDestroyPump() { VAR pumpHealth; VAR fixPump; VAR spawnEngineer; VAR pumpCnt; fixPump = -1; pumpCnt = 0; // determine which pump needs to be fixed if(g_Pump1 != 0) { pumpHealth = QueryProperty_Number(g_Pump1, "Health"); if(pumpHealth <= 0) { g_Pump1 = 0; fixPump = 0; pumpCnt = pumpCnt + 1; } } else { fixPump = 0; pumpCnt = pumpCnt + 1; } if(g_Pump2 != 0) { pumpHealth = QueryProperty_Number(g_Pump2, "Health"); if(pumpHealth <= 0) { g_Pump2 = 0; fixPump = 1; pumpCnt = pumpCnt + 1; } } else { fixPump = 1; pumpCnt = pumpCnt + 1; } if(g_Pump3 != 0) { pumpHealth = QueryProperty_Number(g_Pump3, "Health"); if(pumpHealth <= 0) { g_Pump3 = 0; fixPump = 2; pumpCnt = pumpCnt + 1; } } else { fixPump = 2; pumpCnt = pumpCnt + 1; } if(g_Pump4 != 0) { pumpHealth = QueryProperty_Number(g_Pump4, "Health"); if(pumpHealth <= 0) { g_Pump4 = 0; fixPump = 3; pumpCnt = pumpCnt + 1; } } else { fixPump = 3; pumpCnt = pumpCnt + 1; } // activate the spawn point if needed. if((pumpCnt == 4) || (g_NeedFixing == 1)) { //if((pumpCnt == 4) && (g_RespawnTimerStarted == 0)) if((pumpCnt == 4) && (g_TurretsOn == 1)) { OnLosePower(THIS); g_TurretsOn = 0; MISSION_OnObjectDestroyed(THIS); } /* if(g_CalledEngineer == 0) { ActivateSpawnPoint(g_EngineerSP); ActivateSpawnPoint(g_GuardSP1); ActivateSpawnPoint(g_GuardSP2); ActivateSpawnPoint(g_GuardSP3); ActivateSpawnPoint(g_GuardSP4); g_CalledEngineer = 1; g_NeedFixing = 1; g_PumpToFix = fixPump; g_RespawnTimerStarted = 0; // Add trigger to force the engineer into the goal // to fix the generator. AddTrigger("TRIGGER_TYPE_RepairMachine", 0, THIS, g_GenX, g_GenY, g_GenZ, 1000, -1, 0, 1); } */ } } /***************************************************************************/ /**************************************************************************** * Called when one pump was fixed * DAVIDE Jan 19 2003 ****************************************************************************/ OnPumpFixed() { // recreate one of the missing pumps CreatePump(g_PumpToFix); g_NeedFixing = 0; g_PumpToFix = -1; // now determine if the Engineer should keep working. if(g_Pump1 == 0) g_PumpToFix = 0; if(g_Pump2 == 0) g_PumpToFix = 1; if(g_Pump3 == 0) g_PumpToFix = 2; if(g_Pump4 == 0) g_PumpToFix = 3; if(g_PumpToFix > -1) { g_NeedFixing = 1; // Add another trigger to force the engineer to keep // fixing the generator. AddTrigger("TRIGGER_TYPE_RepairMachine", 0, THIS, g_GenX, g_GenY, g_GenZ, 1000, -1, 0, 1); } else { // fixed all pumps, therefore generator fixed OnReceivePower(THIS); g_TurretsOn = 1; } } /***************************************************************************/ /**************************************************************************** * Called when the engineer dies, so that the generator can initiate * the respawn later. * DAVIDE Jan 28 2003 ****************************************************************************/ ResetTimer() { g_RespawnTimerStarted = 1; g_RespawnTimer = g_MaxRespawnTime; } /***************************************************************************/