/** * * Title: master.script * Description: master poi object script: POI = gangwar */ //------------------------------------------------ // Includes //------------------------------------------------ include library.ai_lib; include library.scenario; include library.poi; include library.locations; //------------------------------------------------ // Inherits //------------------------------------------------ inherits theme_park.poi.base; //------------------------------------------------ // Constants //------------------------------------------------ const string SCENARIO_NAME = "tusken_attack"; const string LOG_NAME = "poiTuskenAttack Master"; const string BASE_PATH = "poi." + SCENARIO_NAME; const string SCRIPT_ANTAGONIST = BASE_PATH + ".antagonist"; const string SCRIPT_BEAST = BASE_PATH + ".beast"; const string SCRIPT_MEDIATOR = BASE_PATH + ".mediator"; const string TBL = "datatables/poi/" + SCENARIO_NAME + "/setup.iff"; const string MEDIATOR_THUG_TYPE = "MEDIATOR_THUG_TYPE"; const string MEDIATOR_LEADER_TYPE = "MEDIATOR_LEADER_TYPE"; const string MEDIATOR_BEAST_TYPE = "MEDIATOR_BEAST_TYPE"; const string MEDIATOR_COUNT = "MEDIATOR_COUNT"; const string ANTAGONIST_THUG_TYPE = "ANTAGONIST_THUG_TYPE"; const string ANTAGONIST_LEADER_TYPE = "ANTAGONIST_LEADER_TYPE"; const string ANTAGONIST_BEAST_TYPE = "ANTAGONIST_BEAST_TYPE"; const string ANTAGONIST_COUNT = "ANTAGONIST_COUNT"; const string THEATER_FILE = "THEATER_FILE"; const int DEFAULT_ANTAGONIST_COUNT = 1; const int MAX_DIFF = 70; const string joyEmotes[] = { "cheer", "applaud", "laugh", "yes", "glow" }; //------------------------------------------------ // Methods //------------------------------------------------ //------------------------------------------------ // OnAttach //------------------------------------------------ trigger OnAttach() { if ( !scenario.initScenario( self, TBL ) ) scenario.cleanup( self ); return SCRIPT_CONTINUE; } //------------------------------------------------ // OnInitialize //------------------------------------------------ trigger OnInitialize() { scenario.cleanup( self ); return SCRIPT_CONTINUE; } //------------------------------------------------ // OnUnloadedFromMemory //------------------------------------------------ trigger OnUnloadedFromMemory() { scenario.cleanup( self ); return SCRIPT_CONTINUE; } //------------------------------------------------ // cleanupScenario //------------------------------------------------ messageHandler cleanupScenario() { scenario.cleanup( self ); return SCRIPT_CONTINUE; } //------------------------------------------------ // destroySelf //------------------------------------------------ messageHandler destroySelf() { destroyObject( self ); return SCRIPT_CONTINUE; } //------------------------------------------------ // initScenario // // Called by message from OnAttach. // This calls all methods necessary to set up the POI. //------------------------------------------------ messageHandler initScenario() { // Validate parameters. if ( (params == null) || (params.isEmpty()) ) { scenario.cleanup(self); return SCRIPT_CONTINUE; } /* Environment Setup */ // Get our mediator types. setObjVar( self, MEDIATOR_THUG_TYPE, params.getString( MEDIATOR_THUG_TYPE ) ); setObjVar( self, MEDIATOR_LEADER_TYPE, params.getString( MEDIATOR_LEADER_TYPE ) ); setObjVar( self, MEDIATOR_BEAST_TYPE, params.getString( MEDIATOR_BEAST_TYPE ) ); setObjVar( self, MEDIATOR_COUNT, params.getInt( MEDIATOR_COUNT ) ); // Get our antagonist type. setObjVar( self, ANTAGONIST_THUG_TYPE, params.getString( ANTAGONIST_THUG_TYPE ) ); setObjVar( self, ANTAGONIST_LEADER_TYPE,params.getString( ANTAGONIST_LEADER_TYPE ) ); setObjVar( self, ANTAGONIST_BEAST_TYPE, params.getString( ANTAGONIST_BEAST_TYPE ) ); setObjVar( self, ANTAGONIST_COUNT, params.getInt( ANTAGONIST_COUNT ) ); // Get our theater file setObjVar( self, THEATER_FILE, params.getString( THEATER_FILE ) ); // Create teams. scenario.createTeam( self, "mediator", self.toString() + "_mediator" ); scenario.createTeam( self, "antagonist", self.toString() + "_antagonist" ); /* Spawn Theaters */ if ( !createTheater( self ) ) { scenario.cleanup( self ); return SCRIPT_CONTINUE; } /* Spawn Antagonist */ if ( !createAntagonist( self ) ) { scenario.cleanup( self ); return SCRIPT_CONTINUE; } if ( !createAntagonistMinions( self ) ) { scenario.cleanup( self ); return SCRIPT_CONTINUE; } /* Spawn Mediators */ if ( !createMediator( self ) ) { scenario.cleanup( self ); return SCRIPT_CONTINUE; } if ( !createMediatorMinions( self ) ) { scenario.cleanup( self ); return SCRIPT_CONTINUE; } obj_id a = poi.findObject( "antagonist_0" ); messageTo( a, "startAttack", null, 90, false ); return SCRIPT_CONTINUE; } //------------------------------------------------ // createTheater // // Spawns the theater for the scenario. //------------------------------------------------ boolean createTheater( obj_id self ) { string theater_file = getStringObjVar(self, THEATER_FILE); if (theater_file == null || theater_file.equals("")) return false; // Create the theater. obj_id theater = poi.createObject( theater_file, 0, 0 ); if ( (theater == null) || (theater == obj_id.NULL_ID) ) return false; // Store theater reference. setObjVar( self, "theater", theater ); return true; } //------------------------------------------------ // handleTheaterComplete // // Called when the theaters load. //------------------------------------------------ messageHandler handleTheaterComplete() { /* Finalize theater. */ return SCRIPT_CONTINUE; } //------------------------------------------------ // createAntagonist //------------------------------------------------ boolean createAntagonist( obj_id self ) { // Spawn the scenario antagonist. string type = getStringObjVar( self, ANTAGONIST_LEADER_TYPE ); string ident = "antagonist_0"; location baseloc = getLocation(self); baseloc.z += 60; location loc = null; int i = 0; while (i < 10) { loc = locations.getGoodLocationAroundLocation(baseloc, 10, 10, 75, 25); if (loc != null) break; i++; } if (loc == null) return false; obj_id antagonist = scenario.createTeamNpc( self, "antagonist", type, ident, loc ); if ( (antagonist == null) || (antagonist == obj_id.NULL_ID) ) return false; // Assign initial behavior to the antagonist. ai_lib.setDefaultCalmBehavior( antagonist, ai_lib.BEHAVIOR_SENTINEL ); attachScript( antagonist, SCRIPT_ANTAGONIST ); return true; } //------------------------------------------------ // createAntagonistMinions // // Creates the rest of the antagonist group. //------------------------------------------------ boolean createAntagonistMinions(obj_id self) { location baseloc = getLocation(self); location leaderloc = getLocation(scenario.getRandomTeamMember(self, "antagonist")); string type = getStringObjVar(self, ANTAGONIST_THUG_TYPE); string beasttype = getStringObjVar(self, ANTAGONIST_BEAST_TYPE); int count = getIntObjVar(self, ANTAGONIST_COUNT); if ( !type.equals("") ) { for (int i = 0; i < count; i++) { string ident = "antagonist_" + (i + 1); location minionloc = new location(leaderloc); minionloc.x += (rand(-6,6) * 5); minionloc.z += (rand(-6,6) * 5); obj_id minion = scenario.createTeamNpc(self, "antagonist", type, ident, minionloc); if ((minion == null) || (minion == obj_id.NULL_ID)) { LOG(LOG_NAME, "Couldn't create antagonist minion."); } else { ai_lib.setDefaultCalmBehavior(minion, ai_lib.BEHAVIOR_SENTINEL); attachScript(minion, SCRIPT_ANTAGONIST); } } for (int i = -1; i <= 1; i++) { string ident = "antagonist_" + (count + i + 2); location beastloc = new location(leaderloc); beastloc.x += 5; beastloc.z += 5; float xdelta = baseloc.x - beastloc.x; float zdelta = baseloc.z - beastloc.z; beastloc.x += ((10 * i) * (xdelta/zdelta)); beastloc.z += (10 * i); obj_id beast = scenario.createTeamNpc( self, "antagonist", beasttype, ident, beastloc ); if ((beast== null) || (beast== obj_id.NULL_ID)) { LOG(LOG_NAME, "Couldn't create antagonist beast."); } else { ai_lib.setDefaultCalmBehavior( beast, ai_lib.BEHAVIOR_SENTINEL ); attachScript( beast, SCRIPT_BEAST ); } } } return true; } //------------------------------------------------ // createMediator //------------------------------------------------ boolean createMediator( obj_id self ) { // Spawn the scenario mediator (prisoner leader). string type = getStringObjVar( self, MEDIATOR_LEADER_TYPE ); string ident = "mediator_0"; location loc = getLocation( self ); loc.z += 15; obj_id mediator = scenario.createTeamNpc( self, "mediator", type, ident, loc ); if ( (mediator == null) || (mediator == obj_id.NULL_ID) ) return false; // Assign initial behavior to the mediator. setYaw( mediator, 180 ); ai_lib.setDefaultCalmBehavior( mediator, ai_lib.BEHAVIOR_SENTINEL ); attachScript( mediator, SCRIPT_MEDIATOR ); return true; } //------------------------------------------------ // createMediatorMinions // // Creates the rest of the mediator group. //------------------------------------------------ boolean createMediatorMinions( obj_id self ) { location baseloc = getLocation( self ); string type = getStringObjVar( self, MEDIATOR_THUG_TYPE ); string beasttype = getStringObjVar( self, MEDIATOR_BEAST_TYPE ); if ( !type.equals("") ) { int count = getIntObjVar( self, MEDIATOR_COUNT ); for ( int i = 0; i < count; i++ ) { string ident = "mediator_" + (i + 1); float xdelta = rand(-15,15) * 2; float zdelta = 15 + (rand(-3,5) * 2); location loiterloc = new location( baseloc ); loiterloc.x += xdelta; loiterloc.z += zdelta; obj_id mediator; if ( (i==4) && !beasttype.equals("none") ) mediator = scenario.createTeamNpc( self, "mediator", beasttype, ident, loiterloc ); else mediator = scenario.createTeamNpc( self, "mediator", type, ident, loiterloc ); if ( (mediator == null) || (mediator == obj_id.NULL_ID) ) { LOG( LOG_NAME, "Couldn't create mediator minion." ); } else { setYaw( mediator, 180 ); ai_lib.setDefaultCalmBehavior( mediator, ai_lib.BEHAVIOR_SENTINEL ); attachScript( mediator, SCRIPT_MEDIATOR ); } } } return true; } //------------------------------------------------ // handleActorDeath //------------------------------------------------ messageHandler handleActorDeath() { // Get antagonists obj_id[] antagonists = scenario.getTeamMembers( "antagonist" ); if ( antagonists == null ) return SCRIPT_CONTINUE; // Get mediators. obj_id[] mediators = scenario.getTeamMembers( "mediator" ); if ( mediators == null ) return SCRIPT_CONTINUE; // Are all antagonists dead? int deadcount = scenario.getDeadTeamMemberCount( self, "antagonist" ); if ( (deadcount) == antagonists.length ) { // All antagonists are dead. celebrateVictory( mediators, "m_victory" ); return SCRIPT_CONTINUE; } // Are all mediators dead? deadcount = scenario.getDeadTeamMemberCount( self, "mediator" ); if ( (deadcount) == mediators.length ) { // Everyone is dead. celebrateVictory( antagonists, "a_victory" ); return SCRIPT_CONTINUE; } return SCRIPT_CONTINUE; } //------------------------------------------------ // celebrateVictory //------------------------------------------------ void celebrateVictory( obj_id[] team, string comment ) { int j = 0; for ( int i=0; i