00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __AI_LOCAL_H__
00030 #define __AI_LOCAL_H__
00031
00033
00034
00035
00036
00037
00038 #include <vector>
00039
00040 #include "upgrade_structs.h"
00041 #include "unit.h"
00042
00043
00044
00045
00046
00047 class CUnit;
00048 class CUnitType;
00049 class CPlayer;
00050
00054 class CAiType {
00055 public:
00056 CAiType() {}
00057
00058 std::string Name;
00059 std::string Class;
00060
00061 #if 0
00062
00063 unsigned char AllExplored : 1;
00064 unsigned char AllVisbile : 1;
00065 #endif
00066
00067 std::string Script;
00068 };
00069
00073 class AiRequestType {
00074 public:
00075 AiRequestType() : Count(0), Type(NULL) {}
00076
00077 int Count;
00078 CUnitType *Type;
00079 };
00080
00084 class AiUnitType {
00085 public:
00086 AiUnitType() : Want(0), Type(NULL) {}
00087
00088 int Want;
00089 CUnitType *Type;
00090 };
00091
00095 enum AiForceRole {
00096 AiForceRoleAttack,
00097 AiForceRoleDefend,
00098 };
00099
00100
00106 class AiForce {
00107 public:
00108 AiForce() : Completed(false), Defending(false), Attacking(false), Role(0),
00109 State(0), GoalX(0), GoalY(0), MustTransport(false) {}
00110
00111 void Reset() {
00112 Completed = false;
00113 Defending = false;
00114 Attacking = false;
00115 Role = 0;
00116 UnitTypes.clear();
00117 Units.clear();
00118 State = 0;
00119 GoalX = GoalY = 0;
00120 MustTransport = false;
00121 }
00122
00123 bool Completed;
00124 bool Defending;
00125 bool Attacking;
00126 char Role;
00127
00128 std::vector<AiUnitType> UnitTypes;
00129 std::vector<CUnit *> Units;
00130
00131
00132
00133
00134 int State;
00135 int GoalX;
00136 int GoalY;
00137 bool MustTransport;
00138 };
00139
00145 class AiBuildQueue {
00146 public:
00147 AiBuildQueue() : Want(0), Made(0), Type(NULL), Wait(0) {}
00148
00149 int Want;
00150 int Made;
00151 CUnitType *Type;
00152 unsigned long Wait;
00153 };
00154
00158 class AiExplorationRequest {
00159 public:
00160 AiExplorationRequest() : X(0), Y(0), Mask(0) {}
00161
00162 int X;
00163 int Y;
00164 int Mask;
00165 };
00166
00170 class AiTransportRequest {
00171 public:
00172 AiTransportRequest() : Unit(NULL) {}
00173
00174 CUnit *Unit;
00175 COrder Order;
00176 };
00177
00181 class PlayerAi {
00182 public:
00183 PlayerAi() : Player(NULL), AiType(NULL), ScriptDebug(false),
00184 SleepCycles(0), NeededMask(0), NeedSupply(false),
00185 LastExplorationGameCycle(0), LastCanNotMoveGameCycle(0),
00186 LastRepairBuilding(0)
00187 {
00188 memset(Needed, 0, sizeof(Needed));
00189 memset(TriedRepairWorkers, 0, sizeof(TriedRepairWorkers));
00190 }
00191
00192 CPlayer *Player;
00193 CAiType *AiType;
00194
00195 std::string Script;
00196 bool ScriptDebug;
00197 unsigned long SleepCycles;
00198
00199
00200 #define AI_MAX_FORCES 10
00201 #define AI_MAX_ATTACKING_FORCES 30
00202 AiForce Force[AI_MAX_ATTACKING_FORCES];
00203
00204
00205 int Needed[MaxCosts];
00206 int NeededMask;
00207 bool NeedSupply;
00208
00209 std::vector<AiExplorationRequest> FirstExplorationRequest;
00210 unsigned long LastExplorationGameCycle;
00211 std::vector<AiTransportRequest> TransportRequests;
00212 unsigned long LastCanNotMoveGameCycle;
00213 std::vector<AiRequestType> UnitTypeRequests;
00214 std::vector<AiBuildQueue> UnitTypeBuilt;
00215 int LastRepairBuilding;
00216 unsigned TriedRepairWorkers[UnitMax];
00217 };
00218
00226 class AiHelper {
00227 public:
00232 std::vector<std::vector<CUnitType *> > Train;
00237 std::vector<std::vector<CUnitType *> > Build;
00242 std::vector<std::vector<CUnitType *> > Repair;
00247 std::vector<std::vector<CUnitType *> > UnitLimit;
00252 std::vector<std::vector<CUnitType *> > Equiv;
00253 };
00254
00255
00256
00257
00258
00259 extern std::vector<CAiType *> AiTypes;
00260 extern AiHelper AiHelpers;
00261
00262 extern int UnitTypeEquivs[UnitTypeMax + 1];
00263 extern PlayerAi *AiPlayer;
00264
00265
00266
00267
00268
00269
00270
00271
00273 extern void AiAddUnitTypeRequest(CUnitType *type, int count);
00275 extern void AiResourceManager(void);
00277 extern void AiExplore(int x, int y, int exploreMask);
00279 extern void AiNewUnitTypeEquiv(CUnitType *a, CUnitType *b);
00281 extern void AiResetUnitTypeEquiv(void);
00283 extern int AiFindUnitTypeEquiv(const CUnitType *i, int *result);
00285 extern int AiFindAvailableUnitTypeEquiv(const CUnitType *i,
00286 int *result);
00287
00288
00289
00290
00292 extern int AiFindBuildingPlace(const CUnit *worker,
00293 const CUnitType *type, int *dx, int *dy);
00294
00295
00296
00297
00299 extern void AiCleanForces(void);
00301 extern void AiAssignToForce(CUnit *unit);
00303 extern void AiAssignFreeUnitsToForce(void);
00305 extern void AiAttackWithForceAt(int force, int x, int y);
00307 extern void AiAttackWithForce(int force);
00309 extern void AiForceManager(void);
00310
00311
00312
00313
00315 extern int AiPlanAttack(AiForce *force);
00317 extern void AiSendExplorers(void);
00319 extern int AiEnemyUnitsInDistance(const CPlayer *player, const CUnitType *type,
00320 int x, int y, unsigned range);
00321
00322
00323
00324
00326 extern void AiCheckMagic(void);
00327
00329
00330 #endif // !__AI_LOCAL_H__