home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 8 (DVD) / XENIADVD08.iso / Fragzone / Files / AOM_MiniCampaign.exe / AI / mc04p3.xs < prev   
Encoding:
Text File  |  2002-12-09  |  4.0 KB  |  120 lines

  1. //==============================================================================
  2. // .xs     A very simplistic 'getting started' script for Hello World.scn
  3. //==============================================================================
  4. /*
  5.    Scenario:  
  6.    AI owner:  Mike Kidd
  7.    Scenario owner: Jeff Brown
  8.  
  9. This computer player simply controls a group of myth units that guard its 
  10. temples.  Each temple will have a defend plan to control the myth units 
  11. near it.
  12.  
  13. */
  14.  
  15. float templeRadius = 30.0;    // Radius to search for myth units
  16. float defendRadius = 30.0;    // Radius for the defend plan
  17. float attackResponseRange = 20.0;  // Unit call-for-help response radius
  18.  
  19.  
  20. //==============================================================================
  21. // setup()
  22. //
  23. // This function generates a list of all temples.
  24. // For each temple, it counts the nearby myth units, then creates
  25. // a defend plan centered on that temple for the local myth units.
  26. //
  27. //==============================================================================
  28.  
  29. void   setup( void )
  30. {
  31.    int   templeCount = -1;
  32.     int   templeQueryID = kbUnitQueryCreate("temple");
  33.    int   mythCount = -1;
  34.    int   mythQueryID = kbUnitQueryCreate("mythUnit");
  35.  
  36.     // Define a query to get all temples
  37.     if (templeQueryID != -1)
  38.     {
  39.         kbUnitQuerySetPlayerID(templeQueryID, cMyID);         // only my temples
  40.           kbUnitQuerySetUnitType(templeQueryID, cUnitTypeTemple);   // only if specified
  41.         kbUnitQuerySetState(templeQueryID, cUnitStateAlive);
  42.     }
  43.     else
  44.    {
  45.       return();
  46.    }
  47.  
  48.    if (mythQueryID != -1)
  49.    {
  50.       kbUnitQuerySetPlayerID(mythQueryID, cMyID);  // My units;
  51.       kbUnitQuerySetUnitType(mythQueryID, cUnitTypeMythUnit);  // Myth units
  52.       kbUnitQuerySetState(mythQueryID, cUnitStateAlive);    // No dead ones, please.
  53.    }
  54.    else
  55.    {
  56.       return();
  57.    }
  58.  
  59.     kbUnitQueryResetResults(templeQueryID);
  60.     templeCount = kbUnitQueryExecute(templeQueryID);
  61.    aiEcho("We found "+templeCount+" temples.");
  62.  
  63.    int temple = -1;
  64.    for (temple=0; < templeCount)
  65.    {
  66.         int templeID = kbUnitQueryGetResult(templeQueryID, temple);
  67.         vector templeLocation = kbUnitGetPosition(templeID);
  68.         aiEcho("Temple "+temple+" is ID #"+templeID+" and is at "+templeLocation);
  69.       kbUnitQuerySetPosition(mythQueryID, templeLocation);  
  70.       kbUnitQuerySetMaximumDistance(mythQueryID, templeRadius);
  71.       kbUnitQueryResetResults(mythQueryID);
  72.       mythCount = kbUnitQueryExecute(mythQueryID);
  73.       aiEcho("At temple #"+temple+" there are "+mythCount+" myth units.");
  74.  
  75.       // Init low-priority defend plan to manage spare units
  76.       int defendPlan =aiPlanCreate("Defend Plan "+temple, cPlanDefend);
  77.       if (defendPlan >= 0)
  78.       {
  79.          aiPlanAddUnitType(defendPlan, cUnitTypeMythUnit, 0, mythCount, mythCount);    // All myth units near this temple
  80.          aiPlanSetDesiredPriority(defendPlan, 10);                       // Way low
  81.          aiPlanSetVariableVector(defendPlan, cDefendPlanDefendPoint, 0, templeLocation);
  82.          aiPlanSetVariableFloat(defendPlan, cDefendPlanEngageRange, 0, defendRadius);
  83.  
  84.          aiPlanSetVariableFloat(defendPlan, cDefendPlanGatherDistance, 0, defendRadius);
  85.          aiPlanSetInitialPosition(defendPlan, templeLocation);
  86.          aiPlanSetUnitStance(defendPlan, cUnitStanceDefensive);
  87.  
  88.          aiPlanSetVariableBool(defendPlan, cDefendPlanPatrol, 0, false);
  89.  
  90.          aiPlanSetVariableInt(defendPlan, cDefendPlanRefreshFrequency, 0, 5);
  91.          aiPlanSetNumberVariableValues(defendPlan, cDefendPlanAttackTypeID, 2, true);
  92.          aiPlanSetVariableInt(defendPlan, cDefendPlanAttackTypeID, 0, cUnitTypeUnit);
  93.          aiPlanSetVariableInt(defendPlan, cDefendPlanAttackTypeID, 1, cUnitTypeBuilding);
  94.          aiPlanSetActive(defendPlan); 
  95.          aiEcho("Activating defend plan #"+temple+".");
  96.       }
  97.    }
  98. }
  99.  
  100.  
  101.  
  102. void changeStance(int ignoreMe = -1)
  103. {
  104.    setup();
  105. }
  106.  
  107.  
  108.  
  109.  
  110. void main()
  111. {
  112.    aiEcho("MC-4");
  113.    kbAreaCalculate(1200.0);
  114.  
  115.    aiSetAttackResponseDistance(attackResponseRange);   
  116.  
  117.  
  118. }
  119.  
  120.