home *** CD-ROM | disk | FTP | other *** search
- //==============================================================================
- // .xs A very simplistic 'getting started' script for Hello World.scn
- //==============================================================================
- /*
- Scenario:
- AI owner: Mike Kidd
- Scenario owner: Jeff Brown
-
- This computer player simply controls a group of myth units that guard its
- temples. Each temple will have a defend plan to control the myth units
- near it.
-
- */
-
- float templeRadius = 30.0; // Radius to search for myth units
- float defendRadius = 30.0; // Radius for the defend plan
- float attackResponseRange = 20.0; // Unit call-for-help response radius
-
-
- //==============================================================================
- // setup()
- //
- // This function generates a list of all temples.
- // For each temple, it counts the nearby myth units, then creates
- // a defend plan centered on that temple for the local myth units.
- //
- //==============================================================================
-
- void setup( void )
- {
- int templeCount = -1;
- int templeQueryID = kbUnitQueryCreate("temple");
- int mythCount = -1;
- int mythQueryID = kbUnitQueryCreate("mythUnit");
-
- // Define a query to get all temples
- if (templeQueryID != -1)
- {
- kbUnitQuerySetPlayerID(templeQueryID, cMyID); // only my temples
- kbUnitQuerySetUnitType(templeQueryID, cUnitTypeTemple); // only if specified
- kbUnitQuerySetState(templeQueryID, cUnitStateAlive);
- }
- else
- {
- return();
- }
-
- if (mythQueryID != -1)
- {
- kbUnitQuerySetPlayerID(mythQueryID, cMyID); // My units;
- kbUnitQuerySetUnitType(mythQueryID, cUnitTypeMythUnit); // Myth units
- kbUnitQuerySetState(mythQueryID, cUnitStateAlive); // No dead ones, please.
- }
- else
- {
- return();
- }
-
- kbUnitQueryResetResults(templeQueryID);
- templeCount = kbUnitQueryExecute(templeQueryID);
- aiEcho("We found "+templeCount+" temples.");
-
- int temple = -1;
- for (temple=0; < templeCount)
- {
- int templeID = kbUnitQueryGetResult(templeQueryID, temple);
- vector templeLocation = kbUnitGetPosition(templeID);
- aiEcho("Temple "+temple+" is ID #"+templeID+" and is at "+templeLocation);
- kbUnitQuerySetPosition(mythQueryID, templeLocation);
- kbUnitQuerySetMaximumDistance(mythQueryID, templeRadius);
- kbUnitQueryResetResults(mythQueryID);
- mythCount = kbUnitQueryExecute(mythQueryID);
- aiEcho("At temple #"+temple+" there are "+mythCount+" myth units.");
-
- // Init low-priority defend plan to manage spare units
- int defendPlan =aiPlanCreate("Defend Plan "+temple, cPlanDefend);
- if (defendPlan >= 0)
- {
- aiPlanAddUnitType(defendPlan, cUnitTypeMythUnit, 0, mythCount, mythCount); // All myth units near this temple
- aiPlanSetDesiredPriority(defendPlan, 10); // Way low
- aiPlanSetVariableVector(defendPlan, cDefendPlanDefendPoint, 0, templeLocation);
- aiPlanSetVariableFloat(defendPlan, cDefendPlanEngageRange, 0, defendRadius);
-
- aiPlanSetVariableFloat(defendPlan, cDefendPlanGatherDistance, 0, defendRadius);
- aiPlanSetInitialPosition(defendPlan, templeLocation);
- aiPlanSetUnitStance(defendPlan, cUnitStanceDefensive);
-
- aiPlanSetVariableBool(defendPlan, cDefendPlanPatrol, 0, false);
-
- aiPlanSetVariableInt(defendPlan, cDefendPlanRefreshFrequency, 0, 5);
- aiPlanSetNumberVariableValues(defendPlan, cDefendPlanAttackTypeID, 2, true);
- aiPlanSetVariableInt(defendPlan, cDefendPlanAttackTypeID, 0, cUnitTypeUnit);
- aiPlanSetVariableInt(defendPlan, cDefendPlanAttackTypeID, 1, cUnitTypeBuilding);
- aiPlanSetActive(defendPlan);
- aiEcho("Activating defend plan #"+temple+".");
- }
- }
- }
-
-
-
- void changeStance(int ignoreMe = -1)
- {
- setup();
- }
-
-
-
-
- void main()
- {
- aiEcho("MC-4");
- kbAreaCalculate(1200.0);
-
- aiSetAttackResponseDistance(attackResponseRange);
-
-
- }
-
-