1 /* Definitions for sides in Xconq. 2 Copyright (C) 1987-1989, 1991-1997, 1999-2000 Stanley T. Shebs. 3 Copyright (C) 2004 Eric A. McDonald. 4 5 Xconq is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. See the file COPYING. */ 9 10 /*! \file kernel/side.h 11 * \brief Definitions for sides in Xconq. 12 * 13 * \note Many of the side macros check for a null side pointer. This 14 * is due to a null pointer being used to indicate that the unit was 15 * independant. That has been changed, now the independant units are 16 * assigned to side 0. The check for a null side pointer should not 17 * be needed any longer, but has been left in for the time being. 18 * In particular, the Side Mask equates a null side pointer and the 19 * side 0 as being the same thing. 20 */ 21 22 #include "parambox.h" 23 24 #if MAXSIDES < 31 25 /*! \brief Side mask. 26 * 27 * A side mask is a bit vector, where the bit position corresponds to the 28 * side number. It currently is implemented on tha basis of a 32 bit 29 * integer, so it cannot support more than 30 players. 30 */ 31 typedef int SideMask; 32 /*! \brief No Sides are all zero bits. */ 33 #define NOSIDES (0) 34 /*! \brief All Sides is all ones. */ 35 #define ALLSIDES (-1) 36 /*! \brief Add Side to vector. 37 * 38 * Sets the bit corresponding to the Side number, or the 39 * zero'th bit if the \Side pointer is nil. 40 * \param side is the pointer to the \Side. 41 * \param mask is the side mask. 42 * \return the modified side mask. 43 */ 44 #define add_side_to_set(side,mask) ((mask) | (1 << ((side) ? (side)->id : 0))) 45 46 /*! \brief Remove side from mask. 47 * 48 * Resets the bit corresponding to the Side number, or the 49 * zero'th bit if the \Side pointer is nil. 50 * \param side is the pointer to the \Side. 51 * \param mask is the side mask. 52 * \return the side mask. 53 */ 54 #define remove_side_from_set(side,mask) \ 55 ((mask) & ~(1 << ((side) ? (side)->id : 0))) 56 57 /*! \brief Side in set. 58 * 59 * This returns a non-zero value if the Side is set. 60 * \param side is a pointer to the \Side. 61 * \param mask is the side mask. 62 * \return non-zero if the side is in the set. 63 */ 64 #define side_in_set(side,mask) ((mask) & (1 << ((side) ? (side)->id : 0))) 65 #else 66 not implemented yet 67 #endif /* MAXSIDES */ 68 69 /*! \brief Doctine. 70 * 71 * Doctrine is policy info that Units and Players use to help decide 72 * behavior. 73 */ 74 typedef struct a_doctrine { 75 short id; /*!< a unique id */ 76 char *name; /*!< a distinguishing name for the doctrine */ 77 short resupply_percent; /*!< do resupply task if below this */ 78 short rearm_percent; /*!< do resupply of ammo if below this */ 79 short repair_percent; /*!< do repairs if hp at or below this */ 80 short resupply_complete; /*!< cease resupply if % at or above this */ 81 short rearm_complete; /*!< cease rearming if % at or above this */ 82 short repair_complete; /*!< cease repairs if hp at or above this */ 83 short min_turns_food; /*!< minimal number of turns for which we 84 should have food-type supplies */ 85 short min_distance_fuel; /*!< minimal distance in cells for which we 86 should have fuel-type supplies */ 87 short *construction_run; /*!< number of each type to build usually */ 88 short locked; /*!< true if values can't be changed */ 89 struct a_doctrine *next; /*!< pointer to next doctrine defined */ 90 } Doctrine; 91 92 /*! \brief Standing order conditions. 93 * This modifies a standing order to be limited to a 94 * particular location/unit. 95 */ 96 enum sordercond { 97 sorder_always, /*!< always */ 98 sorder_at, /*!< when at */ 99 sorder_in, /*!< when in */ 100 sorder_near /*!< when near */ 101 }; 102 103 /*! \brief Standing order. 104 * 105 * A standing order is a conditional order that applies to any matching 106 * unit not already doing a task. 107 */ 108 typedef struct a_standing_order { 109 char *types; /*!< unit types to which order applies */ 110 enum sordercond condtype; /*!< type of condition to trigger on */ 111 int a1; /*!< first parameter to test (x, y, etc). */ 112 int a2; /*!< second parameter to test (x, y, etc). */ 113 int a3; /*!< third parameters to test (x, y, etc). */ 114 struct a_task *task; /*!< \ref a_task "Task" to perform */ 115 struct a_standing_order *next; /*!< link to next standing order for 116 side */ 117 } StandingOrder; 118 119 namespace Xconq { 120 namespace AI { 121 struct AI_Side; 122 } 123 } 124 typedef Xconq::AI::AI_Side AI_Side; 125 126 /*! \brief Side. 127 * 128 * Each Xconq player is a "side" - more or less one country. A side 129 * may or may not be played by a person, and may or may not have a 130 * display attached to it. Each side has a different view of the 131 * world. Side 0 is for independant units. 132 */ 133 typedef struct a_side { 134 int id; /*!< a unique id */ 135 Obj *symbol; /*!< a symbol bound to side's id */ 136 char *name; /*!< This is the proper name of a side, 137 * as a country or alliance name. Examples 138 * include "Axis" and "Hyperborea". */ 139 char *longname; /*!< This is the long form of a side's name, 140 * as in "People's Republic of Hyperborea". 141 * Defaults to be the same as the side's 142 * name. */ 143 char *shortname; /*!< This is an short name or acronym for the 144 * side, often just the letters of the long 145 * name, as in "PRH". */ 146 char *noun; /*!< This is the name of an individual unit or 147 * person belonging to the side. Defaults 148 * to "", which suppresses any mention of 149 * the side when (textually) describing the 150 * individual. */ 151 char *pluralnoun; /*!< This is what you would call a group of 152 * individuals. Defaults to the most common 153 * plural form of the noun (in English, 154 * the default pluralizer adds an "s"), so 155 * any alternative plural noun, such as 156 * "Chinese", will need an explicit 157 * plural-noun value. */ 158 char *adjective; /*!< This is an adjective that can be used of 159 * individuals on the side, as in "Spanish". 160 * Defaults to "", which suppresses use of 161 * the adjective. As a complete example, a 162 * side named "Poland" would have a long 163 * name "Kingdom of Poland", short name 164 * "Po", noun "Pole", plural noun "Poles", 165 * and adjective "Polish". */ 166 char *colorscheme; /*!< This is a comma-separated list of colors 167 * that represents the side. Defaults to 168 * "black". */ 169 char *default_color; /*!< default color used in the absence of 170 * emblems and at low magnifications 171 * <I>name</I> */ 172 char *emblemname; /*!< This property is the name of a graphical 173 * icon that represents the side. An emblem 174 * name of "none" suppresses any emblem 175 * display for the side. Defaults to "", 176 * which gives the side a randomly-selected 177 * emblem. */ 178 char **unitnamers; /*!< This specifies which namers will be used 179 * with which types that the side starts out 180 * with or creates new units. These will not 181 * be run automatically on captured units or 182 * gifts. */ 183 Obj *featurenamers; /*!< This specifies which namers to use with 184 * which geographical features in the side's 185 * initial country (if if has one). */ 186 short nameslocked; /*!< True if names may not be changed by 187 * player. */ 188 char *sideclass; /*!< This is a side's class, which is a 189 * keyword that characterizes the side. Any 190 * number of sides may be in the same 191 * class. */ 192 struct a_unit *self_unit; /*!< This identifies a unit that represents 193 * the side itself. The value may be a unit 194 * id, number, string, or symbol. Defaults 195 * to 0, which means that no unit represents 196 * the side. See \ref selfUnit for more 197 * information. */ 198 short self_unit_id; /*!< Id of the self_unit. */ 199 struct a_side *controlled_by; /*!< side controlling this one 200 * <I>relationship</I> */ 201 short controlled_by_id; /*!< id of controlling side 202 * <I>relationship</I> */ 203 SideMask knows_about; /*!< true if side knows about another side 204 * <I>relationship</I> */ 205 short *trusts; /*!< true if side trusts another side 206 * <I>relationship</I> */ 207 short *trades; /*!< true if side trades with another side. 208 * <I>relationship</I> */ 209 short *startwith; /*!< how many units of each type at start of 210 * game <I>relationship</I> */ 211 short *counts; /*!< array of numbers for identifying units 212 * <I>relationship</I> */ 213 short *tech; /*!< tech level for each unit type 214 * <I>relationship</I> */ 215 short *inittech; /*!< tech level at beginning of turn 216 * <I>relationship</I> */ 217 short *action_priorities; /*!< action priority for each unit type 218 * <I>relationship</I> */ 219 short *already_seen; /*!< chance that other units already seen 220 * <I>relationship</I> */ 221 short *already_seen_indep; /*!< chance that independent units already 222 * seen <I>relationship</I> */ 223 Doctrine *default_doctrine; /*!< fallback \ref a_doctrine "Doctrine" 224 * <I>relationship</I> */ 225 Doctrine **udoctrine; /*!< array of per-unit-type \ref a_doctrine 226 * "Doctrines" <I>relationship</I> */ 227 short doctrines_locked; /*!< true if all doctrines locked 228 * <I>relationship</I> */ 229 StandingOrder *orders; /*!< list of \ref a_standing_order 230 * "Standing Orders" for the side 231 * <I>relationship</I> */ 232 StandingOrder *last_order; /*!< Pointer to last \ref a_standing_order 233 * "Standing Order" in list 234 * <I>relationship</I> */ 235 char *uorders; /*!< bit vector of types that have orders 236 * <I>relationship</I> */ 237 Obj *possible_units; /*!< list of \ref a_unit "Units" to give to 238 * side <I>relationship</I> */ 239 short ai_may_resign; /*!< true if AI may draw or resign on its own 240 * <I>relationship</I> */ 241 short *advance; /*!< State of research (accum pts) for each 242 * Advance. Set to -1 when completed. 243 * <I>relationship</I> */ 244 short research_topic; /*!< Advance that the side is working on 245 * <I>relationship</I> */ 246 short autoresearch; /*!< TRUE if next research topic autoselected 247 * <I>relationship</I> */ 248 short research_goal; /*!< Research goal for the side. */ 249 long *treasury; /*!< globally available supply of each material 250 * type <I>relationship</I> */ 251 short *c_rates; /*!< material conversion rates 252 * <I>relationship</I> */ 253 char *terrview; /*!< ptr to view of terrain <I>view</I>*/ 254 char **auxterrview; /*!< ptr to view of aux terrain <I>view</I>*/ 255 short *terrviewdate; /*!< ptr to dates of view of terrain 256 * <I>view</I> */ 257 short **auxterrviewdate; /*!< ptr to dates of view of aux terrain 258 * <I>view</I>*/ 259 struct a_unit_view **unit_views; /*!< ptr to table of views of units 260 * <I>view</I>*/ 261 short **materialview; /*!< ptr to view of cell materials <I>view</I>*/ 262 short **materialviewdate; /*!< ptr to dates of view of cell materials 263 * <I>view</I>*/ 264 short *tempview; /*!< ptr to view of temperature <I>view</I>*/ 265 short *tempviewdate; /*!< ptr to dates of view of temperature 266 * <I>view</I>*/ 267 short *cloudview; /*!< ptr to view of clouds <I>view</I>*/ 268 short *cloudbottomview; /*!< ptr to view of cloud bottoms <I>view</I>*/ 269 short *cloudheightview; /*!< ptr to view of cloud heights <I>view</I>*/ 270 short *cloudviewdate; /*!< ptr to dates of view of clouds 271 * <I>view</I>*/ 272 short *windview; /*!< ptr to view of winds <I>view</I>*/ 273 short *windviewdate; /*!< ptr to dates of view of winds <I>view</I>*/ 274 short ingame; /*!< true if side participating in game 275 * <I>status</I>*/ 276 short everingame; /*!< true if side ever participated in a turn 277 * <I>status</I>*/ 278 short priority; /*!< overall action priority of this side 279 * <I>status</I>*/ 280 short status; /*!< -1/0/1 for lost/draw/won <I>status</I>*/ 281 short *scores; /*!< array of scores managed by scorekeepers 282 * <I>status</I>*/ 283 Obj *rawscores; /*!< score data as read from file 284 * <I>status</I>*/ 285 short willingtodraw; /*!< will this side go along with quitters? 286 * <I>status</I>*/ 287 short autofinish; /*!< turn done when all units acted 288 * <I>status</I>*/ 289 short finishedturn; /*!< true when side wants to go to next turn 290 * <I>status</I>*/ 291 short turntimeused; /*!< seconds used this turn <I>status</I>*/ 292 short totaltimeused; /*!< total seconds used <I>status</I>*/ 293 short timeouts; /*!< total timeouts used <I>status</I>*/ 294 short timeoutsused; /*!< total timeouts used <I>status</I>*/ 295 short curactor_pos; /*!< index in actionvector to current unit 296 * <I>status</I>*/ 297 struct a_unit *curactor; /*!< pointer to current unit acting. 298 * <I>status</I>*/ 299 short curactor_id; /*!< Id of current unit acting. <I>status</I>*/ 300 short advantage; /*!< actual advantage <I>setup</I>*/ 301 short minadvantage; /*!< min advantage requestable during init 302 * <I>setup</I>*/ 303 short maxadvantage; /*!< max of same <I>setup</I>*/ 304 short init_center_x; /*!< center of preferred initial view, 305 * x<I>setup</I>*/ 306 short init_center_y; /*!< center of preferred initial view, 307 * y<I>setup</I>*/ 308 Obj *instructions; /*!< notes to player about the game 309 * <I>setup</I>*/ 310 short last_notice_date; /*!< last turn during which notice was posted */ 311 short realtimeout; /*!< how long to wait before just going ahead */ 312 long startbeeptime; /*!< after this time, beep to signal next 313 * turn */ 314 short *gaincounts; /*!< array of counts of unit gains by the 315 * side */ 316 short *losscounts; /*!< array of counts of losses by the side */ 317 long **atkstats; /*!< array of counts of attacks by units */ 318 long **hitstats; /*!< array of damage done by unit attacks */ 319 struct a_player *player; /*!< pointer to data about the player */ 320 short playerid; /*!< numeric id of the player */ 321 struct a_ui *ui; /*!< pointer to all the user interface data */ 322 Obj *uidata; /*!< read/write form of user interface state */ 323 short aitype; /*!< type of AI making decisions */ 324 struct a_ai *ai; /*!< pointer to the AI making decisions */ 325 Obj *aidata; /*!< readable/writable form of AI state */ 326 struct a_rui *rui; /*!< pointer to interface data if remote */ 327 struct a_rai *rai; /*!< pointer to AI data if remote */ 328 //! Pointer to side's master AI struct. 329 AI_Side *master_ai; 330 short startx, starty; /*!< approx center of side's "country" */ 331 short busy; /*!< true when side state not saveable */ 332 short finalradius; /*!< ??? */ 333 short willingtosave; /*!< will this side go along with saving 334 * game? */ 335 short see_all; /*!< True if the side sees everything. Right 336 * now this is just a cache for g_see_all(). 337 * Note in particular that becoming a 338 * designer should not change this value. */ 339 short show_all; /*!< True if the side's interface should 340 * display everything. This is seeded from 341 * side->see_all, and also becomes true when 342 * designing or when the game is over. */ 343 short may_set_show_all; /*!< True if the value of show_all can be 344 * changed by the player. This is normally 345 * off, but can be toggled while designing or 346 * after the game is over. */ 347 short unit_view_restored; /*!< true if unit view was read in */ 348 #ifdef DESIGNERS 349 short designer; /*!< true if side is doing scenario design */ 350 #endif /* DESIGNERS */ 351 short *uavail; /*!< vector of types allowed on this side 352 * (as determined by u_possible_sides)*/ 353 short *canbuild; /*!< vector of unit types that side has 354 * advances to build */ 355 short *candevelop; /*!< vector of unit types that side has 356 * advances to develop */ 357 short *cancarry; /*!< vector of unit types that side has 358 * transports to carry */ 359 short *canresearch; /*!< vector of advances that side has advances 360 * to research */ 361 short *research_precluded; /*!< Vector of advances that can no longer 362 * be researched by the side because they 363 * have been precluded by other researched 364 * advances. */ 365 struct a_unit *unithead; /*!< points to list of all units on this side */ 366 struct a_unitvector *actionvector; /*!< vector of acting units */ 367 short numwaiting; /*!< number of units waiting to get orders */ 368 short *coverage; /*!< indicates how many looking at this cell */ 369 short *alt_coverage; /*!< indicates minimum altitude visible */ 370 short *numunits; /*!< number of units the side has */ 371 short numacting; /*!< number of units that can do things */ 372 short numfinished; /*!< number of units that have finished 373 * acting */ 374 long turnstarttime; /*!< real time at start of turn */ 375 long lasttime; /*!< when clock started counting down again */ 376 long turnfinishtime; /*!< real time when we've finished 377 * interacting */ 378 long laststarttime; /*!< ??? */ 379 int point_value_cache; /*!< current score. ??? */ 380 int point_value_valid; /*!< true if point_value_cache is valid. ??? */ 381 int prefixarg; /*!< cache of UI prefixarg, for generic cmds */ 382 struct a_side *next; /*!< pointer to next in list */ 383 } Side; 384 385 /* Side parameter box. */ 386 struct ParamBoxSide : public ParamBox { 387 Side *side; ParamBoxSideParamBoxSide388 ParamBoxSide() { pboxtype = PBOX_TYPE_SIDE; side = NULL; } 389 }; 390 391 /* Some convenient macros. */ 392 393 /*! \brief Is side playing? 394 * 395 * Check to see if \Side is in game and playing. 396 * \param side is a pointer to the \Side to check. 397 */ 398 #define side_in_play(side) (side->ingame) 399 400 /* Iteration over all sides. */ 401 402 /*! \brief Iterate real \Sides.. 403 * 404 * This is the old for_all_sides which does not include indepside. 405 * 406 * \param v is the side iteration variable. It is a pointer to a \Side. 407 */ 408 #define for_all_real_sides(v) \ 409 for (v = (sidelist ? sidelist->next : NULL); v != NULL; v = v->next) 410 411 /*! \brief Iterate all sides. 412 * 413 * This is the new indepside-including version of for_all_sides. 414 * It has replaced for_all_side_plus_indep everywhere. 415 * \param v is the side iteration variable. It is a pointer to a \Side. 416 */ 417 #define for_all_sides(v) \ 418 for (v = sidelist; v != NULL; v = v->next) 419 420 /* Macros for accessing and setting a side's view data. In general, 421 interfaces should go through these macros instead of accessing the 422 world's state directly. */ 423 424 /*! \brief Terrain view. 425 * 426 * If the \ref viewTerrainType exists for a \Side, return the View Terrain Type. 427 * If it doesn't, return the the View Terrain Type from the terrain. 428 * \see aref, buildtview, terrain_at. 429 * \param s is the pointer to the \Side. 430 * \param x is the x-coordinate of the cell to view. 431 * \param y is the y-coordinate of the cell to view. 432 * \return the value for the \ref viewTerrainType at the co-ordinates. 433 */ 434 #define terrain_view(s,x,y) \ 435 ((s)->terrview ? aref((s)->terrview, x, y) : buildtview(terrain_at(x, y))) 436 437 /*! \brief Set View Terrain view. 438 * 439 * Sets the value of the \ref viewTerrainType at a cell, if a \Side has a view 440 * defined. Otherwise does nothing. 441 * \see aset. 442 * \param s is a pointer to the \Side. 443 * \param x is the cell's x co-ordinate to set. 444 * \param y is the cell's y co-ordinate to set. 445 * \param v is the view terain type to which to set the cell. 446 * \return the view type of the terrain, or 0. 447 */ 448 #define set_terrain_view(s,x,y,v) \ 449 ((s)->terrview ? aset((s)->terrview, x, y, v) : 0) 450 451 /*! \brief Convert Terrain to View Terrain type. 452 * 453 * Take the Terrain type, and convert it to a \ref viewTerrainType 454 * by adding 1 to it. 455 * \param t is the Terrain type. 456 * \return the View Terrain type. 457 */ 458 #define buildtview(t) ((t) + 1) 459 460 /*! \brief Convert View Terrain type to Terrain type. 461 * 462 * Take a \ref viewTerrainType and convert it to a Terrain type by 463 * subtracting 1 from it. 464 * \param v is the View Terrain type. 465 * \return the Terrain type. 466 */ 467 #define vterrain(v) ((v) - 1) 468 469 /*! \brief a cell which has not been seen by a side. */ 470 #define UNSEEN (0) 471 472 /*! \brief Terrain view on date. 473 * 474 * If the \ref viewTerrainType on date exists for a side, return the \ref viewTerrainType. 475 * If it doesn't, return UNSEEN. 476 * \see aref. 477 * \param s is the pointer to the \Side. 478 * \param x is the x-coordinate of the cell to view. 479 * \param y is the y-coordinaof of the cell to view. 480 * \return 481 * - the value for the \ref viewTerrainType at the co-ordinates, 482 * - zero if side->terrviewdate is NULL 483 */ 484 #define terrain_view_date(s,x,y) \ 485 ((s)->terrviewdate ? aref((s)->terrviewdate, x, y) : 0) 486 487 /*! \brief Set View Terrain type on date. 488 * 489 * Sets the value of the \ref viewTerrainType on date at a cell, if a 490 * \Side has a view on date defined. Otherwise does nothing. 491 * \see aset. 492 * \param s is a pointer to the \Side. 493 * \param x is the cell's x co-ordinate to set. 494 * \param y is the cell's y co-ordinate to set. 495 * \param v is the view terain type to which to set the cell. 496 * \return 497 * - the new value for the \ref viewTerrainType at the co-ordinates, 498 * - zero if side->terrviewdate is NULL 499 */ 500 #define set_terrain_view_date(s,x,y,v) \ 501 ((s)->terrviewdate ? aset((s)->terrviewdate, x, y, v) : 0) 502 503 /*! \brief Auxillary Terrain view. 504 * 505 * If the auxillary \ref viewTerrainType exists for a \Side, 506 * and exits for this Terrain type, return the auxillary \ref viewTerrainType. 507 * If a global auxillary view for a terrain type exits, return the global 508 * auxillary \ref viewTerrainType. 509 * If it doesn't, return UNSEEN. 510 * \see aref. 511 * \param s is the pointer to the \Side. 512 * \param x is the x-coordinate of the cell to view. 513 * \param y is the y-coordinaof of the cell to view. 514 * \param t is the terrain of the cell. 515 * \return 516 * - the value for the \ref viewTerrainType at the co-ordinates, 517 * - zero if side->terrviewdate is NULL 518 */ 519 #define aux_terrain_view(s,x,y,t) \ 520 (((s)->auxterrview && (s)->auxterrview[t]) ? \ 521 aref((s)->auxterrview[t], x, y) : \ 522 (aux_terrain_defined(t) ? aux_terrain_at(x, y, t) : 0)) 523 524 /*! \brief Set auxillary Terrain view. 525 * 526 * Sets the value of the auxillary \ref viewTerrainType at a cell, if a 527 * \Side has auxillary view defined. Otherwise does nothing. 528 * \see aset, aux_terrain_view. 529 * \param s is a pointer to the \Side. 530 * \param x is the cell's x co-ordinate to set. 531 * \param y is the cell's y co-ordinate to set. 532 * \param t is the terrain of the cell. 533 * \param v is the \ref viewTerrainType to which to set the cell. 534 * \return 535 * - the new value for the \ref viewTerrainType at the co-ordinates, 536 * - zero if side->terrviewdate is NULL 537 */ 538 #define set_aux_terrain_view(s,x,y,t,v) \ 539 (((s)->auxterrview && (s)->auxterrview[t]) ? aset((s)->auxterrview[t], x, y, v) : 0) 540 541 /*! \brief Auxillary Terrain view on date. 542 * 543 * If the auxillary \ref viewTerrainType exists for a \Side, and exits for this 544 * Terrain type at the current date, return the auxillary View Terrain Type. 545 * If a global auxillary view for a terrain type exits, return the global 546 * auxillary View Terrain Type. 547 * If it doesn't, return UNSEEN. 548 * \see aref, aux_terrain_view. 549 * \param s is the pointer to the \Side. 550 * \param x is the x-coordinate of the cell to view. 551 * \param y is the y-coordinaof of the cell to view. 552 * \param t is the Terrain of the cell. 553 * \return 554 * - the value for the \ref viewTerrainType at the co-ordinates, 555 * - zero if side->terrviewdate is NULL 556 */ 557 #define aux_terrain_view_date(s,x,y,t) \ 558 (((s)->auxterrviewdate && (s)->auxterrviewdate[t]) ? aref((s)->auxterrviewdate[t], x, y) : 0) 559 560 /*! \brief Set auxillary Terrain view. 561 * 562 * Sets the value of the auxillary Terrain view type at a cell, if a side has 563 * auxillary view defined on this date. Otherwise does nothing. 564 * \see aset, aux_terrain_view. 565 * \param s is a pointer to the \Side. 566 * \param x is the cell's x co-ordinate to set. 567 * \param y is the cell's y co-ordinate to set. 568 * \param t is the terrain of the cell. 569 * \param v is the view terain type to which to set the cell. 570 * \return 571 * - the new value for the \ref viewTerrainType at the co-ordinates, 572 * - zero if \Side->terrviewdate is NULL 573 */ 574 #define set_aux_terrain_view_date(s,x,y,t,v) \ 575 (((s)->auxterrviewdate && (s)->auxterrviewdate[t]) ? aset((s)->auxterrviewdate[t], x, y, v) : 0) 576 577 /*! \brief Iteration over all Unit views. 578 * 579 * For header to iterat through all \UnitViews. 580 *\param v is the \UnitView vector list iteration variable. 581 */ 582 #define for_all_unit_views(v) \ 583 for (v = viewlist; v != NULL; v = v->vnext) 584 585 /*! \brief Find next unit view. 586 * 587 * Find unit_view_next for top units, (uv)->nexthere for occs. 588 * \param s is a pointer to the \Side. 589 * \param x is the x location. 590 * \param y is the y location. 591 * \param uv is the Unit view iteration variable. 592 */ 593 #define nextview(s,x,y,uv) \ 594 ((uv)->transport == NULL ? unit_view_next((s), (x), (y), (uv)) : (uv)->nexthere) 595 596 /*! \brief Iterate Unit views at cell. 597 * 598 * Iterate over all unit views at a given location. 599 * \see unit_view_at, unit_view_next. 600 * \param s is a pointer to the \Side. 601 * \param x is the x co-ordinate of the cell. 602 * \param y is the y co-ordinate of the cell. 603 * \param uv is the Unit view iteration variable. 604 */ 605 #define for_all_view_stack(s,x,y,uv) \ 606 for ((uv) = unit_view_at(s,x,y); (uv) != NULL; (uv) = unit_view_next(s,x,y,uv)) 607 608 /* Iterate over all uviews in a given uvstack. */ 609 #define for_all_uvstack(uvs,uv) \ 610 for ((uv) = (uvs); (uv); \ 611 (uv) = unit_view_next((uvs)->observer == -1 \ 612 ? NULL : side_n((uvs)->observer), \ 613 (uvs)->x, (uvs)->y, (uv))) 614 615 /*! \brief Iterate Unit stack and occupants. 616 * 617 * Iterate through all unit views in this cell including occs within occs 618 * within occs. 619 * This nifty little macro will climb the occupant : nexthere tree and 620 * follow all branches four levels down to find all the occs within 621 * occs within occs within units in the stack. 622 * \param x is the x location. 623 * \param y is the y location. 624 * \param var is the Unit view pointer. 625 */ 626 #define for_all_view_stack_with_occs(s, x,y,uv) \ 627 for ((uv) = unit_view_at((s), (x), (y)); \ 628 (uv) != NULL; \ 629 (uv) = ((uv)->occupant != NULL ? \ 630 (uv)->occupant : \ 631 (nextview((s), (x), (y), (uv)) != NULL ? \ 632 nextview((s), (x), (y), (uv)) : \ 633 ((uv)->transport != NULL && \ 634 nextview((s), (x), (y), (uv)->transport) != NULL ? \ 635 nextview((s), (x), (y), (uv)->transport) : \ 636 ((uv)->transport != NULL && \ 637 (uv)->transport->transport != NULL && \ 638 nextview((s), (x), (y), (uv)->transport->transport) != NULL ? \ 639 nextview((s), (x), (y), (uv)->transport->transport) : \ 640 ((uv)->transport != NULL && \ 641 (uv)->transport->transport != NULL && \ 642 (uv)->transport->transport->transport != NULL && \ 643 nextview((s), (x), (y), (uv)->transport->transport->transport) != NULL ? \ 644 nextview((s), (x), (y), (uv)->transport->transport->transport) : NULL)))))) 645 646 /*! \brief Iterate views of occupants. 647 * 648 * Iterate over all views of occupants. 649 * \param uv is the unit view of the transport. 650 * \param v is the occupant view iteration variable. 651 */ 652 #define for_all_occupant_views(uv,v) \ 653 for (v = (uv)->occupant; v != NULL; v = v->nexthere) 654 655 /*! \brief Iterate over ALL components. 656 * 657 * Iterate through all occupants including occupents within occupents within 658 * occupents within a unit view. 659 * This nifty little macro will climb the occupant : nexthere tree and 660 * follow all branches three levels below (uv) to find all the occs 661 * within occs within occs within (uv). The test for (var) != 662 * (uv)->nexthere is to stop the macro from climbing up above (uv). 663 * \param uv is a pointer to the unit view. 664 * \param var is the iteration varable. 665 */ 666 #define for_all_occupant_views_with_occs(uv,var) \ 667 for ((var) = (uv)->occupant; \ 668 (var) != NULL && (var) != (uv)->nexthere; \ 669 (var) = ((var)->occupant != NULL ? \ 670 (var)->occupant : \ 671 ((var)->nexthere != NULL ? \ 672 (var)->nexthere : \ 673 ((var)->transport != NULL && \ 674 (var)->transport->nexthere != NULL ? \ 675 (var)->transport->nexthere : \ 676 ((var)->transport != NULL && \ 677 (var)->transport->transport != NULL && \ 678 (var)->transport->transport->nexthere != NULL ? \ 679 (var)->transport->transport->nexthere : NULL))))) 680 681 /* Get a pointer to the actual unit being viewed if possible. */ 682 683 /*! \brief View Unit Unit pointer. 684 * 685 * Given a unit view pointer, return the actual Unit. 686 * \param uv is the pointer to the unit view. 687 * \return 688 * - NULL if 689 * - pointer to unit is NULL, 690 * - view unit id is not the same as the actual Unit id. 691 * - pointer to actual Unit. 692 */ 693 #define view_unit(uv) \ 694 (((uv)->unit != NULL && (uv)->id == (uv)->unit->id) ? (uv)->unit : NULL) 695 696 /* Manipulation of view of cell materials. */ 697 698 /*! \brief Material view. 699 * 700 * Show viewable Material at cell. 701 * \see aref, cell_material_defined, material_at. 702 * \param s is the pointer to the \Side. 703 * \param x is the x co-ordiate of the cell. 704 * \param y is the y co-ordiate of the cell. 705 * \param m is the Material type. 706 * \return the Material viewable at cell. 707 */ 708 #define material_view(s,x,y,m) \ 709 (((s)->materialview && (s)->materialview[m]) ? aref((s)->materialview[m], x, y) : (cell_material_defined(m) ? material_at(x, y, m) : 0)) 710 711 /*! \brief Set Material view. 712 * 713 * Set viewable Material at cell. 714 * \see aset. 715 * \param s is the pointer to the \Side. 716 * \param x is the x co-ordiate of the cell. 717 * \param y is the y co-ordiate of the cell. 718 * \param m is the Material type. 719 * \param v is the viewable Material at cell. 720 * \return the Material viewable at cell or zero if not setable. 721 */ 722 #define set_material_view(s,x,y,m,v) \ 723 (((s)->materialview && (s)->materialview[m]) ? aset((s)->materialview[m], x, y, v) : 0) 724 725 /*! \brief Material view on date. 726 * 727 * Show viewable Material at cell at date. 728 * \see aref. 729 * \param s is the pointer to the \Side. 730 * \param x is the x co-ordiate of the cell. 731 * \param y is the y co-ordiate of the cell. 732 * \param m is the Material type. 733 * \return the Material viewable at cell at date. 734 */ 735 #define material_view_date(s,x,y,m) \ 736 (((s)->materialviewdate && (s)->materialviewdate[m]) ? aref((s)->materialviewdate[m], x, y) : 0) 737 738 /*! \brief Set Material view at date. 739 * 740 * Set viewable Material at cell on date. 741 * \see aset. 742 * \param s is the pointer to the \Side. 743 * \param x is the x co-ordiate of the cell. 744 * \param y is the y co-ordiate of the cell. 745 * \param m is the Material type. 746 * \param v is the viewable Material at cell. 747 * \return the Material viewable at cell on date or zero if not setable. 748 */ 749 #define set_material_view_date(s,x,y,m,v) \ 750 (((s)->materialviewdate && (s)->materialviewdate[m]) ? aset((s)->materialviewdate[m], x, y, v) : 0) 751 752 /* Manipulation of view of weather. */ 753 754 /*! \brief Show temperture view. 755 * 756 * Show viewable temperature at cell. 757 * \see aref, temperature_defined, temperature_at. 758 * \param s is the pointer to the \Side. 759 * \param x is the x co-ordiate of the cell. 760 * \param y is the y co-ordiate of the cell. 761 * \return the temperature viewable at cell. 762 */ 763 #define temperature_view(s,x,y) \ 764 ((s)->tempview ? aref((s)->tempview, x, y) : (temperatures_defined() ? temperature_at(x, y) : 0)) 765 766 /*! \brief Set temperture view. 767 * 768 * Set the viewable temperature at cell. 769 * \see aset. 770 * \param s is the pointer to the \Side. 771 * \param x is the x co-ordiate of the cell. 772 * \param y is the y co-ordiate of the cell. 773 * \param v is the value of the temperature. 774 * \return the temperature viewable at cell. 775 */ 776 #define set_temperature_view(s,x,y,v) \ 777 ((s)->tempview ? aset((s)->tempview, x, y, v) : 0) 778 779 /*! \brief Show temperture view on date. 780 * 781 * Show viewable temperature at cell on this date. 782 * \see aref. 783 * \param s is the pointer to the \Side. 784 * \param x is the x co-ordiate of the cell. 785 * \param y is the y co-ordiate of the cell. 786 * \return the temperature viewable at cell. 787 */ 788 #define temperature_view_date(s,x,y) \ 789 ((s)->tempviewdate ? aref((s)->tempviewdate, x, y) : 0) 790 791 /*! \brief Set temperture view on date. 792 * 793 * Set the viewable temperature at cell on this date. 794 * \see aset. 795 * \param s is the pointer to the \Side. 796 * \param x is the x co-ordiate of the cell. 797 * \param y is the y co-ordiate of the cell. 798 * \param v is the value of the temperature. 799 * \return the temperature viewable at cell. 800 */ 801 #define set_temperature_view_date(s,x,y,v) \ 802 ((s)->tempviewdate ? aset((s)->tempviewdate, x, y, v) : 0) 803 804 /*! \brief Show cloud view. 805 * 806 * Show viewable cloud at cell. 807 * \see aref, clouds_defined, raw_clouds_at. 808 * \param s is the pointer to the \Side. 809 * \param x is the x co-ordiate of the cell. 810 * \param y is the y co-ordiate of the cell. 811 * \return the clouds viewable at cell. 812 */ 813 #define cloud_view(s,x,y) \ 814 ((s)->cloudview ? aref((s)->cloudview, x, y) : (clouds_defined() ? raw_cloud_at(x, y) : 0)) 815 816 /*! \brief Set cloud view. 817 * 818 * Set the viewable cloud at cell. 819 * \see aset. 820 * \param s is the pointer to the \Side. 821 * \param x is the x co-ordiate of the cell. 822 * \param y is the y co-ordiate of the cell. 823 * \param v is the value of the cloud. 824 * \return the cloud viewable at cell. 825 */ 826 #define set_cloud_view(s,x,y,v) \ 827 ((s)->cloudview ? aset((s)->cloudview, x, y, v) : 0) 828 829 /*! \brief Show cloud view on date. 830 * 831 * Show viewable cloud at cell on this date. 832 * \see aref. 833 * \param s is the pointer to the \Side. 834 * \param x is the x co-ordiate of the cell. 835 * \param y is the y co-ordiate of the cell. 836 * \return the clouds viewable at cell. 837 */ 838 #define cloud_view_date(s,x,y) \ 839 ((s)->cloudviewdate ? aref((s)->cloudviewdate, x, y) : 0) 840 841 /*! \brief Set cloud view on date. 842 * 843 * Set the viewable cloud at cell on this date. 844 * \see aset. 845 * \param s is the pointer to the \Side. 846 * \param x is the x co-ordiate of the cell. 847 * \param y is the y co-ordiate of the cell. 848 * \param v is the value of the cloud. 849 * \return the cloud viewable at cell. 850 */ 851 #define set_cloud_view_date(s,x,y,v) \ 852 ((s)->cloudviewdate ? aset((s)->cloudviewdate, x, y, v) : 0) 853 854 /*! \brief Get cloud bottom. 855 * 856 * Get cloud bottom value. 857 * \see aref, cloud_bottoms_defined, raw_cloud_bottom_at. 858 * \param s is the pointer to the \Side. 859 * \param x is the x co-ordiate of the cell. 860 * \param y is the y co-ordiate of the cell. 861 * \return the clouds viewable at cell. 862 */ 863 #define cloud_bottom_view(s,x,y) \ 864 ((s)->cloudbottomview ? aref((s)->cloudbottomview, x, y) : (cloud_bottoms_defined() ? raw_cloud_bottom_at(x, y) : 0)) 865 866 /*! \brief Set cloud bottom. 867 * 868 * Set the cloud bottom at cell. 869 * \see aset. 870 * \param s is the pointer to the \Side. 871 * \param x is the x co-ordiate of the cell. 872 * \param y is the y co-ordiate of the cell. 873 * \param v is the value of the cloud bottom. 874 * \return the cloud bottom at cell. 875 */ 876 #define set_cloud_bottom_view(s,x,y,v) \ 877 ((s)->cloudbottomview ? aset((s)->cloudbottomview, x, y, v) : 0) 878 879 /*! \brief Get cloud bottom on date. 880 * 881 * Get cloud bottom value on this date. 882 * \see aref. 883 * \param s is the pointer to the \Side. 884 * \param x is the x co-ordiate of the cell. 885 * \param y is the y co-ordiate of the cell. 886 * \return the clouds viewable at cell. 887 */ 888 #define cloud_bottom_view_date(s,x,y) \ 889 ((s)->cloudbottomviewdate ? aref((s)->cloudbottomviewdate, x, y) : 0) 890 891 /*! \brief Set cloud bottom on date. 892 * 893 * Set the cloud bottom at cell on this date. 894 * \see aset. 895 * \param s is the pointer to the \Side. 896 * \param x is the x co-ordiate of the cell. 897 * \param y is the y co-ordiate of the cell. 898 * \param v is the value of the cloud bottom. 899 * \return the cloud bottom at cell. 900 */ 901 #define set_cloud_bottom_view_date(s,x,y,v) \ 902 ((s)->cloudbottomviewdate ? aset((s)->cloudbottomviewdate, x, y, v) : 0) 903 904 /*! \brief Get cloud height. 905 * 906 * Get cloud height value. 907 * \see aref, cloud_heights_defined, raw_cloud_height_at. 908 * \param s is the pointer to the \Side. 909 * \param x is the x co-ordiate of the cell. 910 * \param y is the y co-ordiate of the cell. 911 * \return the clouds viewable at cell. 912 */ 913 #define cloud_height_view(s,x,y) \ 914 ((s)->cloudheightview ? aref((s)->cloudheightview, x, y) : (cloud_heights_defined() ? raw_cloud_height_at(x, y) : 0)) 915 916 /*! \brief Set cloud height. 917 * 918 * Set the cloud height at cell. 919 * \see aset. 920 * \param s is the pointer to the \Side. 921 * \param x is the x co-ordiate of the cell. 922 * \param y is the y co-ordiate of the cell. 923 * \param v is the value of the cloud height. 924 * \return the cloud height at cell. 925 */ 926 #define set_cloud_height_view(s,x,y,v) \ 927 ((s)->cloudheightview ? aset((s)->cloudheightview, x, y, v) : 0) 928 929 /*! \brief Get cloud height on date. 930 * 931 * Get cloud height value on this date. 932 * \see aref. 933 * \param s is the pointer to the \Side. 934 * \param x is the x co-ordiate of the cell. 935 * \param y is the y co-ordiate of the cell. 936 * \return the clouds viewable at cell. 937 */ 938 #define cloud_height_view_date(s,x,y) \ 939 ((s)->cloudheightviewdate ? aref((s)->cloudheightviewdate, x, y) : 0) 940 941 /*! \brief Set cloud height on date. 942 * 943 * Set the cloud height at cell on this date. 944 * \see aset. 945 * \param s is the pointer to the \Side. 946 * \param x is the x co-ordiate of the cell. 947 * \param y is the y co-ordiate of the cell. 948 * \param v is the value of the cloud height. 949 * \return the cloud height at cell. 950 */ 951 #define set_cloud_height_view_date(s,x,y,v) \ 952 ((s)->cloudheightviewdate ? aset((s)->cloudheightviewdate, x, y, v) : 0) 953 954 /*! \brief Get wind view. 955 * 956 * Get wind view. 957 * \see aref, winds_defined, raw_wind_at. 958 * \param s is the pointer to the \Side. 959 * \param x is the x co-ordiate of the cell. 960 * \param y is the y co-ordiate of the cell. 961 * \return the wind viewable at cell. 962 */ 963 #define wind_view(s,x,y) \ 964 ((s)->windview ? aref((s)->windview, x, y) : (winds_defined() ? raw_wind_at(x, y) : CALM)) 965 966 /*! \brief Set wind view. 967 * 968 * Set the wind at cell. 969 * \see aset. 970 * \param s is the pointer to the \Side. 971 * \param x is the x co-ordiate of the cell. 972 * \param y is the y co-ordiate of the cell. 973 * \param v is the value of the wind. 974 * \return the wind at cell. 975 */ 976 #define set_wind_view(s,x,y,v) \ 977 ((s)->windview ? aset((s)->windview, x, y, v) : 0) 978 979 /*! \brief Get wind on date. 980 * 981 * Get wind value on this date. 982 * \see aref. 983 * \param s is the pointer to the \Side. 984 * \param x is the x co-ordiate of the cell. 985 * \param y is the y co-ordiate of the cell. 986 * \return the wind viewable at cell. 987 */ 988 #define wind_view_date(s,x,y) \ 989 ((s)->windviewdate ? aref((s)->windviewdate, x, y) : 0) 990 991 /*! \brief Set wind on date. 992 * 993 * Set the wind at cell on this date. 994 * \see aset. 995 * \param s is the pointer to the \Side. 996 * \param x is the x co-ordiate of the cell. 997 * \param y is the y co-ordiate of the cell. 998 * \param v is the value of the wind. 999 * \return the wind at cell. 1000 */ 1001 #define set_wind_view_date(s,x,y,v) \ 1002 ((s)->windviewdate ? aset((s)->windviewdate, x, y, v) : 0) 1003 1004 /* Basic manipulation of vision coverage cache layer. */ 1005 1006 /*! \brief Get vision coverage. 1007 * 1008 * Get vision coverate at cell. 1009 * \see aref. 1010 * \param s is the pointer to the \Side. 1011 * \param x is the x co-ordiate of the cell. 1012 * \param y is the y co-ordiate of the cell. 1013 * \return the vision coverage at cell. 1014 */ 1015 #define cover(s,x,y) \ 1016 ((s)->coverage ? aref((s)->coverage, x, y) : 0) 1017 1018 /*! \brief Set vision coverage. 1019 * 1020 * Set the vision coverage at cell. 1021 * \see aset. 1022 * \param s is the pointer to the \Side. 1023 * \param x is the x co-ordiate of the cell. 1024 * \param y is the y co-ordiate of the cell. 1025 * \param v is the value of the vision coverage. 1026 * \return the vision coverage at cell. 1027 */ 1028 #define set_cover(s,x,y,v) \ 1029 ((s)->coverage ? aset((s)->coverage, x, y, v) : 0) 1030 1031 /*! \brief Add vision coverage. 1032 * 1033 * Add vision coverate at cell. 1034 * \see aref. 1035 * \param s is the pointer to the \Side. 1036 * \param x is the x co-ordiate of the cell. 1037 * \param y is the y co-ordiate of the cell. 1038 * \param v is the value of the vision coverage. 1039 * \return the vision coverage at cell. 1040 */ 1041 #define add_cover(s,x,y,v) \ 1042 ((s)->coverage ? aadd((s)->coverage, (x), (y), (v)) : 0) 1043 1044 /*! \brief Get alternate vision coverage. 1045 * 1046 * Get alternate vision coverate at cell. 1047 * \see aref. 1048 * \param s is the pointer to the \Side. 1049 * \param x is the x co-ordiate of the cell. 1050 * \param y is the y co-ordiate of the cell. 1051 * \return the alternate vision coverage at cell. 1052 */ 1053 #define alt_cover(s,x,y) \ 1054 ((s)->alt_coverage ? aref((s)->alt_coverage, x, y) : 0) 1055 1056 /*! \brief Set alternate vision coverage. 1057 * 1058 * Set the alternate vision coverage at cell. 1059 * \see aset. 1060 * \param s is the pointer to the \Side. 1061 * \param x is the x co-ordiate of the cell. 1062 * \param y is the y co-ordiate of the cell. 1063 * \param v is the value of the alternate vision coverage. 1064 * \return the alternate vision coverage at cell. 1065 */ 1066 #define set_alt_cover(s,x,y,v) \ 1067 ((s)->alt_coverage ? aset((s)->alt_coverage, x, y, v) : 0) 1068 1069 /*! \brief Has treasury? 1070 * 1071 * Tests both that s can have a treasury and that m can be stored in it. 1072 * \see m_treasury, g_indepside_has_treasury. 1073 * \param s is the pointer to the \Side. 1074 * \param m is the Material. 1075 */ 1076 #define side_has_treasury(s,m) (s != indepside ? m_treasury(m) : g_indepside_has_treasury() ? m_treasury(m) : FALSE) 1077 1078 /* Tests of who/what runs the side. */ 1079 1080 /*! \brief Side wants display? 1081 * 1082 * Determine if \Side needs a display. 1083 * \param s is the pointer to the \Side. 1084 * \return TRUE is side's player pointer and side's player display name are not NULL. 1085 */ 1086 #define side_wants_display(s) ((s)->player && (s)->player->displayname) 1087 1088 /*! \brief Side wants AI? 1089 * 1090 * Determin if a \Side needs AI. 1091 * \param s is the pointer to the \Side. 1092 * \return TRUE if the side's player pointer and the side's player ai type 1093 * name are not NULL. 1094 */ 1095 #define side_wants_ai(s) ((s)->player && (s)->player->aitypename) 1096 1097 /*! \brief Side has display? 1098 * 1099 * See if \Side has a display. 1100 * \param s is the pointer to the \Side. 1101 * \return TRUE if the side's user interface pointer and the side's remote 1102 * user interface pointer are not NULL. 1103 */ 1104 #define side_has_display(s) (((s)->ui) != NULL || ((s)->rui) != NULL) 1105 1106 /*! \brief Side has local display? 1107 * 1108 * See if \Side has a local display. 1109 * \param s is the pointer to the \Side. 1110 * \return TRUE if the side's user interface pointer is not NULL. 1111 */ 1112 #define side_has_local_display(s) ((s)->ui != NULL) 1113 1114 /*! \brief Side has AI? 1115 * 1116 * See if the \Side has an AI running. 1117 * \param s is the pointer to the \Side. 1118 * \return TRUE if the side's AI pointer and the remote AI pointer 1119 * are not NULL. 1120 */ 1121 #define side_has_ai(s) (((s)->ai) != NULL || ((s)->rai) != NULL) 1122 1123 /*! \brief Side has local AI? 1124 * 1125 * See if the \Side has an AI running locally. 1126 * \param s is the pointer to the \Side. 1127 * \return TRUE if the side's AI pointer is not NULL. 1128 */ 1129 #define side_has_local_ai(s) ((s)->ai != NULL) 1130 1131 /* Tests of side state. */ 1132 1133 /*! \brief Has side lost? 1134 * 1135 * \param s is the pointer to the \Side. 1136 * \return TRUE if the side pointer is not NULL, the ingame status is 1137 * FALSE, and the status is less than 0. 1138 */ 1139 #define side_lost(s) ((s) != NULL && !(s)->ingame && (s)->status < 0) 1140 1141 /*! \brief Has side drawn? 1142 * 1143 * \param s is the pointer to the \Side. 1144 * \return TRUE if the side pointer is not NULL, the ingame status is 1145 * FALSE, and the status is 0. 1146 */ 1147 #define side_drew(s) ((s) != NULL && !(s)->ingame && (s)->status == 0) 1148 1149 /*! \brief Has side won? 1150 * 1151 * \param s is the pointer to the \Side. 1152 * \return TRUE if the side pointer is not NULL, the ingame status is 1153 * FALSE, and the status is greater than 0. 1154 */ 1155 #define side_won(s) ((s) != NULL && !(s)->ingame && (s)->status > 0) 1156 1157 #define side_gain_count(s,u,r) (((s)->gaincounts)[num_gain_reasons*(u)+(r)]) 1158 1159 #define side_loss_count(s,u,r) (((s)->losscounts)[num_loss_reasons*(u)+(r)]) 1160 1161 #define side_atkstats(s,a,d) ((s)->atkstats[a] ? ((s)->atkstats[a])[d] : 0) 1162 1163 #define side_hitstats(s,a,d) ((s)->hitstats[a] ? ((s)->hitstats[a])[d] : 0) 1164 1165 /*! \brief Is Terrain visible? 1166 * 1167 * Can terain be seen by side at this location? 1168 * \see terrain_view. 1169 * \param side is the pointer to the \Side. 1170 * \param x is the x co-ordinate of the cell. 1171 * \param y is the y co-ordinate of the cell. 1172 * \return TRUE if side can see something at cell(x,y). 1173 */ 1174 #define terrain_visible(side, x, y) \ 1175 ((side)->see_all || (terrain_view((side), (x), (y)) != UNSEEN)) 1176 1177 /*! \brief is border visable? 1178 * 1179 * Can border be seen? 1180 * \see seen_border. 1181 * \param side is the pointer t the \Side. 1182 * \param x is the x co-ordinate of the cell. 1183 * \param y is the y co-ordiante of the cell. 1184 * \param d is the direction for which to check for the border. 1185 * \return TRUE is a border is visible. 1186 */ 1187 #define borders_visible(side, x, y, d) \ 1188 ((side)->see_all || seen_border((side), (x), (y), (d))) 1189 1190 /*! \brief Is unit visible? 1191 * Can one or more Units be seen in cell? 1192 * \see cover. 1193 * \param side is the pointer t the \Side. 1194 * \param x is the x co-ordinate of the cell. 1195 * \param y is the y co-ordiante of the cell. 1196 * \return TRUE if at least one Unit is visible. 1197 */ 1198 #define units_visible(side, x, y) \ 1199 ((side)->see_all || (cover((side), (x), (y)) >= 1)) 1200 1201 /*! \brief Does side have advance? 1202 * 1203 * Does the \Side have this advance? 1204 * \param side is the pointer t the \Side. 1205 * \param a is the Advance for which to check. 1206 * \return TRUE if side has the advance. 1207 */ 1208 #define has_advance(side,a) ((side)->advance[(a)] == DONE) 1209 1210 /* Return true if a side's units can build the given type. */ 1211 1212 /*! \brief Can side build unit type? 1213 * 1214 * Can the \Side build a Unit type? 1215 * \param side is the pointer t the \Side. 1216 * \param u is the Unit type for which to check. 1217 * \return TRUE if the unit type can be built. 1218 */ 1219 #define side_can_build(side,u) \ 1220 ((side)->canbuild != NULL ? (side)->canbuild[u] : TRUE) 1221 1222 /* Return true if a side's units can carry the given type. */ 1223 1224 /*! \brief Can side carry unit type? 1225 * 1226 * Can the \Side carry a Unit type? 1227 * \param side is the pointer t the \Side. 1228 * \param u is the Unit type for which to check. 1229 * \return TRUE if the unit type can be carried. 1230 */ 1231 #define side_can_carry(side,u) \ 1232 ((side)->cancarry != NULL ? (side)->cancarry[u] : TRUE) 1233 1234 /* Return true if a side's units can develop the given type. */ 1235 1236 /*! \brief Can side develop Unit? 1237 * 1238 * Can this side develop this Unit type? 1239 * \param side is the pointer t the \Side. 1240 * \param u is the Unit type for which to check. 1241 * \return TRUE if the Side can develp the Unit. 1242 */ 1243 #define side_can_develop(side,u) \ 1244 ((side)->candevelop != NULL ? (side)->candevelop[u] : TRUE) 1245 1246 /* Return true if a side can research the given type. */ 1247 1248 /*! \brief Can reasearch Advance? 1249 * 1250 * Can the Side research this Advance? 1251 * \param side is the pointer t the \Side. 1252 * \param a is the Advance to be reshearched. 1253 * \return TRUE if the Advance my be researched. 1254 */ 1255 #define side_can_research(side,a) \ 1256 ((side)->canresearch != NULL ? (side)->canresearch[a] : TRUE) 1257 1258 /*! Is an independant side inactive? 1259 * 1260 * Check to see if a side is both independant and inactive. 1261 * \see side_has_display. 1262 * \param side is the pointer t the \Side. 1263 * \return TRUE if the side is independant, run by AI, and has 1264 * a display. 1265 */ 1266 #define inactive_indepside(side) \ 1267 ((side) == indepside && !side_has_ai(side) && !side_has_display(side)) 1268 1269 #ifdef DESIGNERS 1270 #define is_designer(side) (side->designer) 1271 #else /* DESIGNERS */ 1272 #define is_designer(side) (FALSE) 1273 #endif /* DESIGNERS */ 1274 1275 #define for_all_doctrines(d) \ 1276 for ((d) = doctrine_list; (d) != NULL; (d) = (d)->next) 1277 1278 /* Side-related variables. */ 1279 1280 /*! \brief List of \Sides. */ 1281 extern Side *sidelist; 1282 /*! \brief Last \Side in list. */ 1283 extern Side *lastside; 1284 /*! \brief List of independant \Sides. */ 1285 extern Side *indepside; 1286 /*! \brief Current \Side. */ 1287 extern Side *curside; 1288 /*! \brief Temporary \Side pointer. */ 1289 extern Side *tmpside; 1290 1291 /*! \brief Number of \Sides. */ 1292 extern int numsides; 1293 /*! \brief Total number of \Sides. */ 1294 extern int numtotsides; 1295 /*! \brief Number of \Players. */ 1296 extern int numplayers; 1297 #ifdef DESIGNERS 1298 /*! \brief Number of designers. */ 1299 extern int numdesigners; 1300 #endif /* DESIGNERS */ 1301 1302 #if 0 1303 1304 /*! \brief Agreement. 1305 * 1306 * Definition of an agreement between sides. */ 1307 typedef struct a_agreement { 1308 short id; /*!< a unique id */ 1309 char *agtype; /*!< a descriptive general name */ 1310 char *name; /*!< the specific name of this agreement */ 1311 int state; /*!< is this agreement in effect */ 1312 SideMask drafters; /*!< sides drafting the agreement */ 1313 SideMask proposers; /*!< sides ready to propose the draft agreement */ 1314 SideMask signers; /*!< proposed list of signers */ 1315 SideMask willing; /*!< sides that have indicated agreement so far */ 1316 SideMask knownto; /*!< sides that are aware of signed agreement */ 1317 struct a_obj *terms; /*!< list of specific terms */ 1318 short enforcement; /*!< true if program should try to enforce terms */ 1319 struct a_agreement *next; /*!< link to next agreement. */ 1320 } Agreement; 1321 1322 /*! \brief Agreement state. 1323 * 1324 * Possible states that agreements may be in. 1325 */ 1326 enum { 1327 draft, /*!< agreement is circulating among drafters */ 1328 proposed, /*!< agreement proposed to prospective signers */ 1329 in_force, /*!< agreement is active */ 1330 moribund /*!< agreement has expired */ 1331 }; 1332 1333 /* Iteration over all agreements in the game. */ 1334 1335 /*! \brief Iterate over agreements. 1336 * 1337 * for header to interate through all \ref a_agreement "Agreements". 1338 * \param v is the iteration variable (pointer to Agreement). 1339 */ 1340 #define for_all_agreements(v) for (v = agreement_list; v != NULL; v = v->next) 1341 1342 /*! \brief Is there any Agreement? 1343 * 1344 * Check for non NULL \ref a_agreement "Agreement" list. 1345 * \return TRUE if Agreement list is not NULL. 1346 */ 1347 #define any_agreements() (agreement_list != NULL) 1348 1349 /*! \brief Has side signed Agreement? 1350 * 1351 * \param side is the pointer to the \Side. 1352 * \param ag is the pointer to the \ref a_agreement "Agreement". 1353 * \return TRUE if side signed Agreement. 1354 */ 1355 #define side_signed_agreement(side,ag) ((ag)->signers[side_n(side)]) 1356 1357 #define side_willing_agreement(side,ag) ((ag)->willing[side_n(side)]) 1358 1359 /*! \brief Side knows of Agreement? 1360 * 1361 * Does the side know about the \ref a_agreement "Agreement"? 1362 * \param side is the pointer to the \ref a_sice "Side". 1363 * \param ag is the pointer to the \ref a_agreement "Agreement". 1364 * \return TRUE if side knows about the Agreement. 1365 */ 1366 #define side_knows_about_agreement(side,ag) ((ag)->knownto[side_n(side)]) 1367 1368 /* Agreement-related variables. */ 1369 1370 /*! \brief Number of agreements. */ 1371 extern int num_agreements; 1372 1373 /*! \brief List of agreements. */ 1374 extern Agreement *agreement_list; 1375 /*! \brief Last agreement in list. */ 1376 extern Agreement *last_agreement; 1377 1378 #endif 1379 1380 /* Note: Can't use the "Unit" typedef below, must use "struct a_unit". */ 1381 1382 extern int n_units_on_side(Side *side); 1383 1384 extern void init_sides(void); 1385 extern Side *create_side(void); 1386 extern void init_side_unithead(Side *side); 1387 extern int side_has_units(Side *side); 1388 extern void init_doctrine(Side *side); 1389 extern void init_self_unit(Side *side); 1390 extern int init_view(Side *side); 1391 extern void calc_start_xy(Side *side); 1392 extern char *side_name(Side *side); 1393 extern char *side_adjective(Side *side); 1394 extern int side_number(Side *side); 1395 extern Side *side_n(int n); 1396 extern Side *find_side_by_name(char *str); 1397 extern int side_controls_side(Side *side, Side *side2); 1398 extern int side_controls_unit(Side *side, struct a_unit *unit); 1399 extern int side_sees_unit(Side *side, struct a_unit *unit); 1400 extern int side_sees_image(Side *side, struct a_unit *unit); 1401 extern int occupants_visible(Side *side, struct a_unit *unit); 1402 extern int num_units_in_play(Side *side, int u); 1403 extern int num_units_incomplete(Side *side, int u); 1404 extern struct a_unit *find_next_unit(Side *side, struct a_unit *prevunit); 1405 extern struct a_unit *find_prev_unit(Side *side, struct a_unit *nextunit); 1406 extern struct a_unit *find_next_actor(Side *side, struct a_unit *prevunit); 1407 extern struct a_unit *find_prev_actor(Side *side, struct a_unit *nextunit); 1408 extern struct a_unit *find_next_mover(Side *side, struct a_unit *prevunit); 1409 extern struct a_unit *find_prev_mover(Side *side, struct a_unit *nextunit); 1410 extern struct a_unit *find_next_awake_mover(Side *side, 1411 struct a_unit *prevunit); 1412 extern struct a_unit *find_prev_awake_mover(Side *side, 1413 struct a_unit *nextunit); 1414 extern int side_initacp(Side *side); 1415 extern int side_acp(Side *side); 1416 extern int side_acp_reserved(Side *side); 1417 extern int using_tech_levels(void); 1418 extern void remove_side_from_game(Side *side); 1419 extern int num_displayed_sides(void); 1420 extern int trusted_side(Side *side1, Side *side2); 1421 extern int enemy_side(Side *s1, Side *s2); 1422 extern int allied_side(Side *s1, Side *s2); 1423 extern int neutral_side(Side *s1, Side *s2); 1424 extern void reveal_side(Side *sender, Side *recipient, int *types); 1425 extern void receive_message(Side *side, Side *sender, char *str); 1426 extern struct a_unit_view *unit_view_at(Side *side, int x, int y); 1427 extern struct a_unit_view *unit_view_next(Side *side, int x, int y, 1428 struct a_unit_view *uview); 1429 extern struct a_unit *query_unit_from_uview(struct a_unit_view *uview); 1430 extern struct a_unit_view *query_uvstack_from_unit(struct a_unit *unit); 1431 extern struct a_unit_view *query_uvstack_at(int x, int y); 1432 extern void all_see_occupy(struct a_unit *unit, int x, int y, int inopen); 1433 extern void all_see_leave(struct a_unit *unit, int x, int y, int inopen); 1434 extern void cover_area(Side *side, struct a_unit *unit, 1435 struct a_unit *oldtransport, int x0, int y0, 1436 int x1, int y1); 1437 extern void reset_coverage(void); 1438 extern void really_reset_coverage(void); 1439 extern void calc_coverage(Side *side); 1440 extern void reset_all_views(void); 1441 extern void reset_view(Side *side); 1442 extern void react_to_seen_unit(Side *side, struct a_unit *unit, int x, int y); 1443 extern void all_see_cell(int x, int y); 1444 extern int see_cell(Side *side, int x, int y); 1445 extern void see_exact(Side *side, int x, int y); 1446 extern int seen_border(Side *side, int x, int y, int dir); 1447 extern void maybe_track(struct a_unit *unit); 1448 extern void maybe_lose_track(struct a_unit *unit, int nx, int ny); 1449 extern char *side_desig(Side *side); 1450 1451 extern Side *parse_side_spec(char *str); 1452 1453 extern int actual_advantage(Side *side); 1454 1455 extern Doctrine *new_doctrine(int id); 1456 extern Doctrine *find_doctrine(int id); 1457 extern Doctrine *find_doctrine_by_name(char *name); 1458 extern Doctrine *clone_doctrine(Doctrine *doctrine); 1459 extern void set_doctrine(Side *side, char *spec); 1460 1461 extern StandingOrder *new_standing_order(void); 1462 extern void add_standing_order(Side *side, StandingOrder *sorder, int pos); 1463 extern int parse_standing_order(Side *side, char *cmdstr); 1464 extern char *parse_unit_types(Side *side, char *str, char *utypevec); 1465 extern char *parse_order_cond(Side *side, char *str, StandingOrder *sorder); 1466 extern char *get_next_arg(char *str, char *buf, char **rsltp); 1467 extern char *standing_order_desc(StandingOrder *sorder, char *buf); 1468 #if 0 1469 extern void init_agreements(void); 1470 extern Agreement *create_agreement(int id); 1471 extern Agreement *find_agreement(int id); 1472 extern char *agreement_desig(Agreement *ag); 1473 #endif 1474 extern void fn_set_terrain_view(int x, int y, int val); 1475 extern void fn_set_aux_terrain_view(int x, int y, int val); 1476 extern void fn_set_terrain_view_date(int x, int y, int val); 1477 extern void fn_set_aux_terrain_view_date(int x, int y, int val); 1478 extern void fn_set_material_view(int x, int y, int val); 1479 extern void fn_set_material_view_date(int x, int y, int val); 1480 extern void fn_set_temp_view(int x, int y, int val); 1481 extern void fn_set_temp_view_date(int x, int y, int val); 1482 extern void fn_set_cloud_view(int x, int y, int val); 1483 extern void fn_set_cloud_bottom_view(int x, int y, int val); 1484 extern void fn_set_cloud_height_view(int x, int y, int val); 1485 extern void fn_set_cloud_view_date(int x, int y, int val); 1486 extern void fn_set_wind_view(int x, int y, int val); 1487 extern void fn_set_wind_view_date(int x, int y, int val); 1488 1489 extern int load_side_config(Side *side); 1490 1491 extern void update_side_display_all_sides(Side *side, int rightnow); 1492 1493 extern int side_material_supply(Side * side, int m); 1494 extern int side_material_production(Side * side, int m); 1495 extern int side_material_storage(Side * side, int m); 1496 1497 extern int fn_test_side_in_sideclass(Obj *osclass, ParamBox *pbox); 1498 1499