Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ai.h

Go to the documentation of this file.
00001 /* Definitions common to all AIs.
00002    Copyright (C) 1992-1997, 1999-2000 Stanley T. Shebs.
00003    Copyright (C) 2005 Eric A. McDonald.
00004 
00005 Xconq is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2, or (at your option)
00008 any later version.  See the file COPYING.  */
00009 
00017 typedef enum a_game_class {
00018     gc_none,                    
00019     gc_standard,                
00020     gc_time,                    
00021     gc_advanced         
00022 } GameClass;
00023 
00025 typedef struct a_ai_op {
00026     char *name;
00027     char *help;
00028     int (*to_test_compat)(void);
00029     void (*to_init)(Side *side);
00030     void (*to_init_turn)(Side *side);
00031     void (*to_decide_plan)(Side *side, Unit *unit);
00032     void (*to_react_to_task_result)(Side *side, Unit *unit,
00033                                     Task *task, TaskOutcome rslt);
00034     void (*to_react_to_new_side)(Side *side, Side *side2);
00035     int (*to_adjust_plan)(Side *side, Unit *unit);
00036     void (*to_finish_movement)(Side *side);
00037     Obj *(*to_save_state)(Side *side);
00038     int (*region_at)(Side *side, int x, int y);
00039     char *(*at_desig)(Side *side, int x, int y);
00040 } AI_ops;
00041 
00042 /* Definition common to all ai types. (?) */
00043 
00044 typedef struct a_ai {
00045   int dummy;
00046 } AI;
00047 
00048 #define side_ai_type(s) ((s)->aitype)
00049 
00050 /* Limit on the number of goals that a side may have. */
00051 
00052 #define MAXGOALS 30
00053 
00054 /* Limit on the number of theaters a single side may have. */
00055 
00056 #define MAXTHEATERS 98
00057 
00058 /* Strategy is what a side uses to make decisions. */
00059 
00060 typedef struct a_strategy {
00061     int trytowin;
00062     int report_not_understood;
00063     int creationdate;
00064     short *strengths[MAXSIDES + 1];     /* estimated numbers of units */
00065     short points[MAXSIDES + 1];         /* estimated point value */
00066     short *alstrengths[MAXSIDES + 1];   /* numbers in alliances */
00067     short alpoints[MAXSIDES + 1];       /* points in alliances */
00068     short initial_strengths_computed;
00069     short *strengths0[MAXSIDES + 1];    /* initial estimated numbers of units */
00070     short points0[MAXSIDES + 1];        /* initial estimated point value */
00071     short *alstrengths0[MAXSIDES + 1];  /* initial numbers in alliances */
00072     short alpoints0[MAXSIDES + 1];      /* initial points in alliances */
00073     short contacted[MAXSIDES+1];
00074     short homefound[MAXSIDES+1];
00075     int analyzegame;
00076     struct a_theater *theaters;
00077     struct a_theater **theatertable;
00078     short numtheaters;
00079     char *areatheaters;
00080     struct a_theater *homefront;
00081     struct a_theater *perimeters[NUMDIRS];
00082     struct a_theater *midranges[NUMDIRS];
00083     struct a_theater *remotes[NUMDIRS];
00084     int numgoals;
00085     struct a_goal *goals[MAXGOALS];
00086     /* Exploration and search slots. */
00087     int zonewidth, zoneheight;
00088     int numzonex, numzoney;     /* dimensions of search zone array */
00089     int numzones;
00090     struct a_searchzone *searchzones;
00091     short *explorertypes;
00092     short explorersneeded;
00093     short *terrainguess;
00094     short cx, cy;               /* "centroid" of all our units */
00095     short *demand;              /* worth of each utype w.r.t. strategy */
00096     int explore_priority;
00097     int defend_priority;
00098     int attack_priority;
00099     struct a_unit **unitlist;   /* lists to help mplay efficiency */
00100     short *unitlistcount;       /* counts of above lists */
00101     short *actualmix;
00102     short *expectedmix;
00103     short *idealmix;
00104     short *develop_status;      /* specific to the "time" game */
00105     short *develop_on;          /* specific to the "time" game */
00106     Obj *writable_state;
00107 } Strategy;
00108 
00109 /* A Theater is a sub-area that can be planned for all at once. */
00110 
00111 /* To save space in theater layer, no more than 127 theaters may exist
00112    at once.  This should be sufficient, even a Napoleon would have
00113    trouble keeping track of that much activity. */
00114 
00115 typedef struct a_theater {
00116     short id;
00117     char *name;                 /* an informative name for this theater */
00118     short x, y;                 /* center of the theater */
00119     short xmin, ymin;
00120     short xmax, ymax;
00121     int size;                   /* number of cells in the theater */
00122     short importance;           /* 0 = shrug, 100 = critical */
00123     Goal *maingoal;
00124     short allied_units;         /* How many units on our side here. */
00125     short makers;               /* Total number of makers */
00126     short unexplored;           /* number of unseen cells in theater */
00127     short allied_bases;         /* total number of our bases, includes towns */
00128     short border;               /* true if this is a border theater. */
00129     short reinforce;            /* priority on request for units. */
00130     short *numassigned;         /* num of each type assigned to theater */
00131     short *numneeded;           /* units we should move to theater. */
00132     short *numtotransport;      /* types needing transportation. */
00133     short *numenemies;
00134     short *numsuspected;
00135     short *numsuspectedmax;
00136     int *people;                /* number of populated cells seen */
00137     int enemystrengthmin;       /* estimate of enemy unit strength */
00138     int enemystrengthmax;       /* estimate of enemy unit strength */
00139     short units_lost;           /* How many units have we lost here. */
00140     struct a_theater *next;     /* pointer to the next theater */
00141 } Theater;
00142 
00143 #define ai(s) ((Strategy *) (s)->ai)
00144 
00145 #define strength_est(side,side2,u) ((ai(side)->strengths[side2->id])[u])
00146 #define allied_strength_est(side,side2,u) ((ai(side)->alstrengths[side2->id])[u])
00147 #define strength0_est(side,side2,u) ((ai(side)->strengths0[side2->id])[u])
00148 #define allied_strength0_est(side,side2,u) ((ai(side)->alstrengths0[side2->id])[u])
00149   
00150 #define for_all_theaters(s,th) \
00151         for ((th) = ai(s)->theaters; (th) != NULL; (th) = (th)->next) \
00152 
00153 #define theater_at(s,x,y)  \
00154   (ai(s)->theaters ? ai(s)->theatertable[((int) ai(s)->areatheaters[(x)+area.width*(y)])] : NULL)
00155 
00156 #define set_theater_at(s,x,y,th)  \
00157   ((ai(s)->areatheaters[(x)+area.width*(y)]) = (th)->id)
00158 
00159 #define for_all_cells_in_theater(s,x,y,th) { \
00160   for ((x) = theater->xmin; (x) < theater->xmax; ++(x))  \
00161     for ((y) = theater->ymin; (y) < theater->ymax; ++(y))  \
00162       if (theater_at((s), (x), (y)) == (th))  }
00163 
00164 #define unit_theater(unit) ((Theater *) (unit)->aihook)
00165 
00166 #define set_unit_theater(unit,theater) ((unit)->aihook = (char *) (theater))
00167 
00168 /* utype-specific develop status codes for the "time" game */
00169 
00170 #define RS_DEVELOP_NEEDED 4
00171 #define RS_DEVELOP_ASSIGNED 3
00172 #define RS_UPGRADE_NEEDED 1
00173 
00174 struct weightelt {
00175     int weight;
00176     long data;
00177 };
00178 
00179 extern GameClass game_class;
00180 extern int bhw_max;
00181 
00182 /* Common functions shared between ai.c and specific AIs. */
00183 
00184 extern void try_to_draw(Side *side, int flag, char *ainame);
00185 extern void give_up(Side *side, char *ainame);
00186 extern int goal_truth(Side *side, Goal *goal);
00187 extern int accelerable(int u);
00188 extern int accelerator(int u1, int u2);
00189 extern GameClass find_game_class(void);
00190 extern void update_unit_plans(Side *side);
00191 extern void update_unit_plans_randomly(Side *side);
00192 extern int need_this_type_to_collect(Side *side, int u, int m);
00193 extern void assign_to_collection(Side *side, Unit *unit, int m);
00194 extern void assign_to_improve(Side *side, Unit *unit);
00195 extern int assign_to_colonize(Side *side, Unit *unit);
00196 extern void assign_to_defend_unit(Unit *unit, Unit *unit2);
00197 extern void assign_to_exploration(Side *side, Unit *unit);
00198 extern void assign_explorer_to_theater(
00199     Side *side, Unit *unit, Theater *theater);
00200 extern void assign_to_explorer_construction(Side *side, Unit *unit);
00201 extern void assign_to_offense(Side *side, Unit *unit);
00202 extern void assign_to_offense_support(Side *side, Unit *unit);
00203 extern void assign_to_colonization_support(Side *side, Unit *unit);
00204 extern void assign_to_defense(Side *side, Unit *unit);
00205 extern void assign_to_defense_support(Side *side, Unit *unit);
00206 extern int preferred_build_type(Side *side, Unit *unit, int plantype);
00207 extern int can_develop_on(int u, int u2);
00208 extern int needs_develop(Side *side, int u);
00209 extern int assign_to_develop_on(Side *side, Unit *unit, int u2);
00210 extern int build_depot_for_self(Unit *unit);
00211 extern int desired_direction_impassable(Unit *unit, int x, int y);
00212 extern int could_be_ferried(Unit *unit, int x, int y);
00213 extern int blocked_by_enemy(Unit *unit, int x, int y, int shortest);
00214 extern int attack_blockage(Side *side, Unit *unit, int x, int y, int shortest);
00215 extern int enemy_close_by(Side *side, Unit *unit, int dist, int *xp, int *yp);
00216 extern int suitable_port(Unit *unit);
00217 extern int need_more_transportation(Side *side);
00218 extern int need_explorers(Side *side);
00219 extern void add_goal(Side *side, Goal *goal);
00220 extern Goal *has_goal(Side *side, GoalType goaltype);
00221 extern Goal *has_unsatisfied_goal(Side *side, GoalType goaltype);
00222 
00223 #if 0           /* Unused functions. */
00224 
00225 extern void assign_to_defend_cell(Unit *unit, int x, int y);
00226 extern void assign_to_defend_vicinity(Unit *unit, int x, int y, int w, int h);
00227 extern void assign_to_defend_theater(Unit *unit, Theater *theater);
00228 extern int build_base_for_self(Side *side, Unit *unit);
00229 extern int build_base_for_others(Side *side, Unit *unit);
00230 
00231 #endif

Generated on Sat Sep 17 10:28:52 2005 for XconqKernel by doxygen 1.3.6