| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name ai_local.h - The local AI header file. */ |
| 11 |
// |
| 12 |
// (c) Copyright 2000-2007 by Lutz Sammer and Antonis Chaniotis. |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
// |
| 28 |
|
| 29 |
#ifndef __AI_LOCAL_H__ |
| 30 |
#define __AI_LOCAL_H__ |
| 31 |
|
| 32 |
//@{ |
| 33 |
|
| 34 |
/*---------------------------------------------------------------------------- |
| 35 |
-- Includes |
| 36 |
----------------------------------------------------------------------------*/ |
| 37 |
|
| 38 |
#include <vector> |
| 39 |
|
| 40 |
#include "upgrade_structs.h" |
| 41 |
#include "unit.h" |
| 42 |
|
| 43 |
/*---------------------------------------------------------------------------- |
| 44 |
-- Declarations |
| 45 |
----------------------------------------------------------------------------*/ |
| 46 |
|
| 47 |
class CUnit; |
| 48 |
class CUnitType; |
| 49 |
class CPlayer; |
| 50 |
|
| 51 |
/** |
| 52 |
** Ai Type structure. |
| 53 |
*/ |
| 54 |
class CAiType { |
| 55 |
public: |
| 56 |
CAiType() {} |
| 57 |
|
| 58 |
std::string Name; /// Name of this ai |
| 59 |
}; |
| 60 |
|
| 61 |
/** |
| 62 |
** AI unit-type table with counter in front. |
| 63 |
*/ |
| 64 |
class AiRequestType { |
| 65 |
public: |
| 66 |
AiRequestType() : Count(0), Type(NULL) {} |
| 67 |
|
| 68 |
int Count; /// elements in table |
| 69 |
CUnitType *Type; /// the type |
| 70 |
}; |
| 71 |
|
| 72 |
/** |
| 73 |
** Ai unit-type in a force. |
| 74 |
*/ |
| 75 |
class AiUnitType { |
| 76 |
public: |
| 77 |
AiUnitType() : Want(0), Type(NULL) {} |
| 78 |
|
| 79 |
int Want; /// number of this unit-type wanted |
| 80 |
CUnitType *Type; /// unit-type self |
| 81 |
}; |
| 82 |
|
| 83 |
/** |
| 84 |
** Roles for forces |
| 85 |
*/ |
| 86 |
enum AiForceRole { |
| 87 |
AiForceRoleAttack, /// Force should attack |
| 88 |
AiForceRoleDefend, /// Force should defend |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
** Define an AI force. |
| 94 |
** |
| 95 |
** A force is a group of units belonging together. |
| 96 |
*/ |
| 97 |
class AiForce { |
| 98 |
public: |
| 99 |
AiForce() : Completed(false), Defending(false), Attacking(false), Role(0), |
| 100 |
State(0), GoalX(0), GoalY(0) {} |
| 101 |
|
| 102 |
void Reset() { |
| 103 |
Completed = false; |
| 104 |
Defending = false; |
| 105 |
Attacking = false; |
| 106 |
Role = 0; |
| 107 |
UnitTypes.clear(); |
| 108 |
Units.clear(); |
| 109 |
State = 0; |
| 110 |
GoalX = GoalY = 0; |
| 111 |
} |
| 112 |
|
| 113 |
bool Completed; /// Flag saying force is complete build |
| 114 |
bool Defending; /// Flag saying force is defending |
| 115 |
bool Attacking; /// Flag saying force is attacking |
| 116 |
char Role; /// Role of the force |
| 117 |
|
| 118 |
std::vector<AiUnitType> UnitTypes; /// Count and types of unit-type |
| 119 |
std::vector<CUnit *> Units; /// Units in the force |
| 120 |
|
| 121 |
// |
| 122 |
// If attacking |
| 123 |
// |
| 124 |
int State; /// Attack state |
| 125 |
int GoalX; /// Attack point X tile map position |
| 126 |
int GoalY; /// Attack point Y tile map position |
| 127 |
}; |
| 128 |
|
| 129 |
/** |
| 130 |
** AI build queue. |
| 131 |
** |
| 132 |
** List of orders for the resource manager to handle |
| 133 |
*/ |
| 134 |
class AiBuildQueue { |
| 135 |
public: |
| 136 |
AiBuildQueue() : Want(0), Made(0), Type(NULL), Wait(0) {} |
| 137 |
|
| 138 |
int Want; /// requested number |
| 139 |
int Made; /// built number |
| 140 |
CUnitType *Type; /// unit-type |
| 141 |
unsigned long Wait; /// wait until this cycle |
| 142 |
}; |
| 143 |
|
| 144 |
/** |
| 145 |
** AI exploration request |
| 146 |
*/ |
| 147 |
class AiExplorationRequest { |
| 148 |
public: |
| 149 |
AiExplorationRequest() : X(0), Y(0), Mask(0) {} |
| 150 |
|
| 151 |
int X; /// x pos on map |
| 152 |
int Y; /// y pos on map |
| 153 |
int Mask; /// mask ( ex: MapFieldLandUnit ) |
| 154 |
}; |
| 155 |
|
| 156 |
/** |
| 157 |
** AI transport request |
| 158 |
*/ |
| 159 |
class AiTransportRequest { |
| 160 |
public: |
| 161 |
AiTransportRequest() : Unit(NULL) {} |
| 162 |
|
| 163 |
CUnit *Unit; |
| 164 |
COrder Order; |
| 165 |
}; |
| 166 |
|
| 167 |
/** |
| 168 |
** AI variables. |
| 169 |
*/ |
| 170 |
class PlayerAi { |
| 171 |
public: |
| 172 |
PlayerAi() : Player(NULL), AiType(NULL), ScriptDebug(false), |
| 173 |
SleepCycles(0), NeededMask(0), |
| 174 |
LastCanNotMoveGameCycle(0), LastRepairBuilding(0) |
| 175 |
{ |
| 176 |
memset(Needed, 0, sizeof(Needed)); |
| 177 |
memset(TriedRepairWorkers, 0, sizeof(TriedRepairWorkers)); |
| 178 |
} |
| 179 |
|
| 180 |
CPlayer *Player; /// Engine player structure |
| 181 |
CAiType *AiType; /// AI type of this player AI |
| 182 |
// controller |
| 183 |
bool ScriptDebug; /// Flag script debuging on/off |
| 184 |
unsigned long SleepCycles; /// Cycles to sleep |
| 185 |
|
| 186 |
// forces |
| 187 |
#define AI_MAX_FORCES 10 /// How many forces are supported |
| 188 |
#define AI_MAX_ATTACKING_FORCES 30 /// Attacking forces |
| 189 |
AiForce Force[AI_MAX_ATTACKING_FORCES]; /// Forces controlled by AI |
| 190 |
|
| 191 |
// resource manager |
| 192 |
int Needed[MaxCosts]; /// Needed resources |
| 193 |
int NeededMask; /// Mask for needed resources |
| 194 |
|
| 195 |
unsigned long LastCanNotMoveGameCycle; /// Last can not move cycle |
| 196 |
std::vector<AiRequestType> UnitTypeRequests; /// unit-types to build/train request,priority list |
| 197 |
std::vector<AiBuildQueue> UnitTypeBuilt; /// What the resource manager should build |
| 198 |
int LastRepairBuilding; /// Last building checked for repair in this turn |
| 199 |
unsigned TriedRepairWorkers[UnitMax]; /// No. workers that failed trying to repair a building |
| 200 |
}; |
| 201 |
|
| 202 |
/** |
| 203 |
** AI Helper. |
| 204 |
** |
| 205 |
** Contains informations needed for the AI. If the AI needs a unit or |
| 206 |
** building or upgrade or spell, it could lookup in this tables to find |
| 207 |
** where it could be trained or built. |
| 208 |
*/ |
| 209 |
class AiHelper { |
| 210 |
public: |
| 211 |
/** |
| 212 |
** The index is the unit that should be trained, giving a table of all |
| 213 |
** units/buildings which could train this unit. |
| 214 |
*/ |
| 215 |
std::vector<std::vector<CUnitType *> > Train; |
| 216 |
/** |
| 217 |
** The index is the unit that should be build, giving a table of all |
| 218 |
** units/buildings which could build this unit. |
| 219 |
*/ |
| 220 |
std::vector<std::vector<CUnitType *> > Build; |
| 221 |
/** |
| 222 |
** The index is the unit that should be repaired, giving a table of all |
| 223 |
** units/buildings which could repair this unit. |
| 224 |
*/ |
| 225 |
std::vector<std::vector<CUnitType *> > Repair; |
| 226 |
/** |
| 227 |
** The index is the unit-limit that should be solved, giving a table of all |
| 228 |
** units/buildings which could reduce this unit-limit. |
| 229 |
*/ |
| 230 |
std::vector<std::vector<CUnitType *> > UnitLimit; |
| 231 |
/** |
| 232 |
** The index is the unit that should be made, giving a table of all |
| 233 |
** units/buildings which are equivalent. |
| 234 |
*/ |
| 235 |
std::vector<std::vector<CUnitType *> > Equiv; |
| 236 |
}; |
| 237 |
|
| 238 |
/*---------------------------------------------------------------------------- |
| 239 |
-- Variables |
| 240 |
----------------------------------------------------------------------------*/ |
| 241 |
|
| 242 |
extern std::vector<CAiType *> AiTypes; /// List of all AI types |
| 243 |
extern AiHelper AiHelpers; /// AI helper variables |
| 244 |
|
| 245 |
extern int UnitTypeEquivs[UnitTypeMax + 1]; /// equivalence between unittypes |
| 246 |
extern PlayerAi *AiPlayer; /// Current AI player |
| 247 |
|
| 248 |
/*---------------------------------------------------------------------------- |
| 249 |
-- Functions |
| 250 |
----------------------------------------------------------------------------*/ |
| 251 |
|
| 252 |
// |
| 253 |
// Resource manager |
| 254 |
// |
| 255 |
/// Add unit-type request to resource manager |
| 256 |
extern void AiAddUnitTypeRequest(CUnitType *type, int count); |
| 257 |
/// Periodic called resource manager handler |
| 258 |
extern void AiResourceManager(void); |
| 259 |
/// Make two unittypes be considered equals |
| 260 |
extern void AiNewUnitTypeEquiv(CUnitType *a, CUnitType *b); |
| 261 |
/// Remove any equivalence between unittypes |
| 262 |
extern void AiResetUnitTypeEquiv(void); |
| 263 |
/// Finds all equivalents units to a given one |
| 264 |
extern int AiFindUnitTypeEquiv(const CUnitType *i, int *result); |
| 265 |
/// Finds all available equivalents units to a given one, in the prefered order |
| 266 |
extern int AiFindAvailableUnitTypeEquiv(const CUnitType *i, int *result); |
| 267 |
|
| 268 |
// |
| 269 |
// Buildings |
| 270 |
// |
| 271 |
/// Find nice building place |
| 272 |
extern int AiFindBuildingPlace(const CUnit *worker, const CUnitType *type, int *dx, int *dy); |
| 273 |
|
| 274 |
// |
| 275 |
// Forces |
| 276 |
// |
| 277 |
/// Cleanup units in force |
| 278 |
extern void AiCleanForces(); |
| 279 |
/// Assign a new unit to a force |
| 280 |
extern void AiAssignToForce(CUnit *unit); |
| 281 |
/// Assign a free units to a force |
| 282 |
extern void AiAssignFreeUnitsToForce(); |
| 283 |
/// Attack with force at position |
| 284 |
extern void AiAttackWithForceAt(int force, int x, int y); |
| 285 |
/// Attack with force |
| 286 |
extern void AiAttackWithForce(int force); |
| 287 |
/// Periodic called force manager handler |
| 288 |
extern void AiForceManager(); |
| 289 |
|
| 290 |
// |
| 291 |
// Plans |
| 292 |
// |
| 293 |
/// Enemy units in distance |
| 294 |
extern int AiEnemyUnitsInDistance(const CPlayer *player, const CUnitType *type, |
| 295 |
int x, int y, unsigned range); |
| 296 |
|
| 297 |
// |
| 298 |
// Magic |
| 299 |
// |
| 300 |
/// Check for magic |
| 301 |
extern void AiCheckMagic(void); |
| 302 |
|
| 303 |
//@} |
| 304 |
|
| 305 |
#endif // !__AI_LOCAL_H__ |