/********************************************************************** * Copyright (c)2000-2002 Sony Online Entertainment Inc. * All Rights Reserved * * Title: destructible_building * Description: script that goes destructible buildings. * * @author $Author:$ * @version $Revision:$ **********************************************************************/ /***** INCLUDES ********************************************************/ include library.battlefield; include library.player_structure; /***** CONSTANTS *******************************************************/ /***** TRIGGERS ********************************************************/ trigger OnFollowMoving(obj_id target) { // Check to make sure the critter stays in the battlefield. If not, destroy it. region bf = battlefield.getBattlefield(self); if (bf == null) destroyObject(self); return SCRIPT_CONTINUE; } trigger OnIncapacitated(obj_id killer) { LOG("LOG_CHANNEL", "battlefield.battlefield_object::OnIncapacitated -- " + self + " " + killer); if (battlefield.isBattlefieldSpawned(self)) { region bf = battlefield.getBattlefield(self); obj_id master_object = battlefield.getMasterObjectFromRegion(bf); battlefield.registerBattlefieldKill(killer, self, master_object); } return SCRIPT_CONTINUE; } trigger OnDestroy() { // LOG("LOG_CHANNEL", "battlefield.battlefield_object::OnDestroy -- " + self); // If the object was a mob spawned by the battlefield, we must update the spawner upon it's destruction // if the battlefield is still active. if (battlefield.isBattlefieldSpawned(self)) { obj_id master_object = getObjIdObjVar(self, battlefield.VAR_SPAWNED_BATTLEFIELD); if (master_object == null) { LOG("LOG_CHANNEL", "battlefield.battlefield_object::OnDestroy (" + self + ") -- Battlefield object is null."); return SCRIPT_CONTINUE; } if (battlefield.isBattlefieldActive(master_object)) { obj_id spawner = getObjIdObjVar(self, battlefield.VAR_SPAWNED_BY); if (spawner == null) { LOG("LOG_CHANNEL", "battlefield.battlefield_object::OnDestroy (" + self + ") -- Spawned_by is null."); } else { if (spawner.isLoaded()) { // This should always be loaded, but check just to make sure. if (hasObjVar(spawner, battlefield.VAR_SPAWNER_CURRENT_POPULATION)) { // If the spawner isn't keeping track of current population, don't decrement the counter. int population = getIntObjVar(spawner, battlefield.VAR_SPAWNER_CURRENT_POPULATION); setObjVar(spawner, battlefield.VAR_SPAWNER_CURRENT_POPULATION, population - 1); LOG("LOG_CHANNEL", "population ->" + population); } } else LOG("LOG_CHANNEL", "battlefield.battlefield_object::OnDestroy -- spawner " + spawner + " is not loaded."); } // Clear the reference of the spawned mob from the battlefield. If the battlefield is active, // the spawned mob was destroyed through the death/decay mechanics and not removeBattlefieldObject. battlefield.removeFromBattlefieldObjectList(master_object, self); } } return SCRIPT_CONTINUE; } /***** MESSAGEHANDLERS *************************************************/ messageHandler msgDestroyBattlefieldObject() { //LOG("LOG_CHANNEL", "battlefield.battlefield_object::msgDestroyBattlefieldObject -- " + self); if (player_structure.isBuilding(self)) { // If we are in a building, we need to kick everyone out of it before destroying. obj_id[] players = player_structure.getPlayersInBuilding(self); if (players != null) { for (int i = 0; i < players.length; i++) expelFromBuilding(players[i]); } } destroyObject(self); return SCRIPT_CONTINUE; } /***** COMMANDHANDLERS *************************************************/ /***** FUNCTIONS *******************************************************/