1 /* Definitions relating to worlds and areas in Xconq. 2 Copyright (C) 1987-1989, 1991-2000 Stanley T. Shebs. 3 4 Xconq is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2, or (at your option) 7 any later version. See the file COPYING. */ 8 9 /*! \file kernel/world.h 10 * \brief Dfinitions relating to worlds and areas in Xconq. 11 */ 12 13 /*! \brief World. 14 * 15 * This structure contains variables which affect the entire world map. 16 */ 17 typedef struct a_world { 18 int circumference; /*!< number of cells going around the world */ 19 int daylength; /*!< number of turns in a day */ 20 int yearlength; /*!< number of turns in a year */ 21 int axial_tilt; /*!< controls extrema of seasons */ 22 int daylight_fraction; /*!< percentage of circumference that is lit */ 23 int twilight_fraction; /*!< percentage of circumference that is partly lit */ 24 int daylight_width; /*!< width of world that is lit */ 25 int twilight_width; /*!< width of world that is at least partly lit */ 26 } World; 27 28 /*! \brief Minimum Area width. 29 * 30 * This is the smallest allowable width for a map. 31 * \note Theoretically, there is no maximum size to Xconq areas, but the minimum 32 * size is set by mystical properties, and is not negotiable. */ 33 #define MINWIDTH 3 34 35 /*! \brief Minimum Area height. 36 * 37 * This is the smallest allowable height for a map. 38 * \see MINWIDTH. 39 */ 40 #define MINHEIGHT 3 41 42 /*! \brief Area. 43 * 44 * An "area" is always basically a rectangular array of positions. The 45 * hex effect can be achieved by interpreting neighborliness and direction 46 * differently, but that's all that's needed. All of the "layers" are 47 * dynamically allocated as needed, to save (considerable!) space. 48 * 49 * See the discussion of \ref layers for a more complet discussion of the 50 * various types of layers. 51 */ 52 typedef struct a_area { 53 short width; /*!< Width of the area. */ 54 short height; /*!< Height of the area */ 55 short halfwidth; /*!< width / 2 */ 56 short halfheight; /*!< height / 2 */ 57 short maxdim; /*!< max of the two dims */ 58 short xwrap; /*!< true if x coords wrap around */ 59 int numcells; /*!< number of cells in area */ 60 int latitude; /*!< position within whole world */ 61 int longitude; /*!< position within whole world */ 62 short projection; /*!< Isometric projection flag. ??? */ 63 int cellwidth; /*!< distance across one cell */ 64 short fullwidth; /*!< width of the area being used for data */ 65 short fullheight; /*!< height of the area being used for data */ 66 short fullx; /*!< x offset within full area to get data from */ 67 short fully; /*!< y offset within full area to get data from */ 68 short sunx; /*!< x location at which sun is overhead */ 69 short suny; /*!< y location at which sun is overhead */ 70 Obj *temp_year; /*!< cycle of temperatures within year */ 71 char *image_name; /*!< name of image to display for map */ 72 /*!< Pointers to the various "layers". */ 73 struct a_unit **units; /*!< pointer to units if any <I>layer</I>*/ 74 char *terrain; /*!< terrain type at this spot <I>layer</I>*/ 75 char **auxterrain; /*!< vector of extra types <I>layer</I>*/ 76 char *peopleside; /*!< the overt side alignment of the locals <I>layer</I>*/ 77 char *controlside; /*!< the side actually in charge <I>layer</I>*/ 78 short *features; /*!< layer of ids of features <I>layer</I>*/ 79 short *elevations; /*!< layer of elevations <I>layer</I>*/ 80 short avgelev; /*!< calculated average of elevations <I>layer</I>*/ 81 short minelev; /*!< calculated min/max of elevations <I>layer</I>*/ 82 short maxelev; /*!< calculated min/max of elevations <I>layer</I>*/ 83 long **materials; /*!< layer of materials in each cell <I>layer</I>*/ 84 short *temperature; /*!< layer of cell temperatures <I>layer</I>*/ 85 short *clouds; /*!< types of clouds in the layer <I>layer</I>*/ 86 short *cloudbottoms; /*!< altitudes of clouds of cloud layer <I>layer</I>*/ 87 short *cloudheights; /*!< heights of clouds in the cloud layer <I>layer</I>*/ 88 short *winds; /*!< layer of force/dir of winds. <I>layer</I>*/ 89 /* These layers are for temporary use in calculations. */ 90 short *tmp1; /*!< Temporary layer 1. <I>layer</I>*/ 91 short *tmp2; /*!< Temporary layer 2. <I>layer</I>*/ 92 short *tmp3; /*!< Temporary layer 3. <I>layer</I>*/ 93 struct a_region **terrain_regions; /*!< Region list. Area is divided by terrain types. <I>layer</I>*/ 94 struct a_region **landsea_regions; /*!< Region list. Area is devided into land and sea. <I>layer</I>*/ 95 short *user; /*!< IDs of units using materials in each cell <I>layer</I>*/ 96 } Area; 97 98 /*! \brief Feature. 99 * 100 * Named geographical features. */ 101 typedef struct a_feature { 102 int type; /*!< index of the general type */ 103 short id; /*!< which one this is */ 104 char *name; /*!< the name of the region */ 105 char *feattype; /*!< its category, such as "island" or "bay" 106 * something for syntax? "foo bay" vs "bay of foo" */ 107 struct a_feature *next; /*!< arranged in a linked list */ 108 /* caches */ 109 int size; /*!< Cache: size */ 110 int x; /*!< Cache: x co-ordinate. */ 111 int y; /*!< Cache: y co-ordinate. */ 112 short xmin; /*!< Cache: Minimum x co-ordinate. */ 113 short ymin; /*!< Cache: Minimum y co-ordinate. */ 114 short xmax; /*!< Cache: Maximum x co-ordinate. */ 115 short ymax; /*!< Cache: Maximum y co-ordinate. */ 116 int mindiam; /*!< Cache: Minimum diameter. */ 117 int maxdiam; /*!< Cache: Maximum diameter. */ 118 int relabel; /*!< Cace: re label. ??? */ 119 } Feature; 120 121 /* Paths. */ 122 123 /*! \brief Waypoint. 124 * 125 * Co-ordinate of point in path. ??? */ 126 typedef struct a_waypoint { 127 int x; /*!< x co-ordinate of point. */ 128 int y; /*!< y co-ordiante of point. */ 129 int note; /*!< note. ??? */ 130 } Waypoint; 131 132 /*! \brief Path. 133 * 134 * Array of waypoints defining path. 135 */ 136 typedef struct a_path { 137 int numwps; /*!< Number of points in path. */ 138 Waypoint wps[100]; /*!< Array of 100 points in path. */ 139 } Path; 140 141 /* Regions. */ 142 143 /*! \brief Region. */ 144 typedef struct a_region { 145 int ttype; /*!< Terrain type. */ 146 int size; /*!< Size. */ 147 short xmin; /*!< Minimum x co-ordinate. */ 148 short ymin; /*!< Minimum y co-ordinate. */ 149 short xmax; /*!< Maximum x co-ordinate. */ 150 short ymax; /*!< Maximum y co-ordinate. */ 151 struct a_region *merge; /*!< Merge with region. ??? */ 152 struct a_region_link *neighbors; /*!< List of neighbor regions. */ 153 struct a_region *next; /*!< Link to next region. */ 154 } TRegion; 155 156 /*! Terrain Region Link. */ 157 typedef struct a_region_link { 158 struct a_region *neighbor; /*! Neighbor. */ 159 struct a_region_link *next; /*! Next */ 160 } TRegionLink; 161 162 /*! \brief Allocate layer. 163 * 164 * Use this macro to get a area-spanning layer of the given type. 165 * This allocates enough memory to hold a value of TYPE for every 166 * cell in the world. 167 * \param TYPE is the type of the layer to allocate. 168 * \return pointer to allocated area. 169 */ 170 #define malloc_area_layer(TYPE) \ 171 ((TYPE *) xmalloc(area.width * area.height * sizeof(TYPE))) 172 173 /*! \brief Zero area. 174 * 175 * This sets an allocated layer to zero using memset by calculating 176 * the number of cells in the area times the size of TYPE. 177 * It uses the size of the global area to determine the area size. 178 * \param ADDR is the address of the area to zero. 179 * \param TYPE is the type of the layer to allocate. 180 * \return the return value of memset. 181 */ 182 #define zero_area_layer(ADDR, TYPE) \ 183 (memset(ADDR, 0, area.width * area.height * sizeof(TYPE))) 184 185 /* General 2D malloced area array usage. Names from Lisp. */ 186 187 /*! \brief Area refernce. 188 * 189 * Returns a value at a cell in the layer. 190 * \param m is a memory pointer to the start of a layer. 191 * \param x is the x co-ordinate of the cell. 192 * \param y is the y co-ordinate of the cell. 193 * \return the value of the cell. 194 * \Note: aref now wraps x. 195 */ 196 #define aref(m,x,y) \ 197 (in_area((x),(y)) ? (m)[area.width * (y) + wrapx((x))] : 0) 198 199 /*! \brief Area set. 200 * 201 * Set the value of a cell in a layer. 202 * \param m is a memory pointer to the start of a layer. 203 * \param x is the x co-ordinate of the cell. 204 * \param y is the y co-ordinate of the cell. 205 * \param v is the new value of the cell. 206 * \return the new value of the cell. 207 * \Note: aset now wraps x. 208 */ 209 #define aset(m,x,y,v) \ 210 (in_area((x),(y)) ? (m)[area.width * (y) + wrapx((x))] = (v) : 0) 211 212 /*! \brief Area add. 213 * 214 * Increment the value of a cell in a layer. 215 * \param m is a memory pointer to the start of a layer. 216 * \param x is the x co-ordinate of the cell. 217 * \param y is the y co-ordinate of the cell. 218 * \param v is the value to add to the cell. 219 * \return the new value of the cell. 220 * \Note: aadd now wraps x. 221 */ 222 #define aadd(m,x,y,v) \ 223 (in_area((x),(y)) ? (m)[area.width * (y) + wrapx((x))] += (v) : 0) 224 225 /* Advanced unit support. */ 226 227 /*! \brief No user id. 228 * 229 * This needs to not be the id of any unit. */ 230 #define NOUSER (0) 231 232 /*! \brief Is user area defined? 233 * 234 * \return 235 * - TRUEE if the area.user is not NULL; 236 * - FALSE otherwize. 237 */ 238 #define user_defined() (area.user != NULL) 239 240 /*! \brief User at? 241 * 242 * Get the User id at cell. 243 * \param x is the x co-ordinate of the cell. 244 * \param y is the y co-ordinate of the cell. 245 * \return the user id at cell(x,y). 246 */ 247 #define user_at(x, y) aref(area.user, x, y) 248 249 #define set_user_at(x, y, u) aset(area.user, x, y, u) 250 251 /*! \brief Number of cells covered by a radius. 252 * 253 * Calculate number of cells that could be covered by a radius sweeping 254 * from an origin. Obviously, one should not provide a radius length < 0. 255 * \param dist is the length of the radius. 256 * \return Number of cells covered by the radius. 257 */ 258 #define radius_covers_n_cells(dist) (1 + (((dist) + 1) * (dist) * 3)) 259 260 /*! \brief Is cell in range? 261 * 262 * Test if cell at (x1, y1) is within n steps from (x, y) 263 * \param x is starting x location. 264 * \param y is starting y location. 265 * \param n is the range. 266 * \param x1 is the ending x location. 267 * \param y1 is the ending y location. 268 * \return TRUE if (x1,y1) is within n units of (x,y). 269 */ 270 #define cell_is_within_range(x, y, n, x1, y1) \ 271 (( (x) - (x1) > (n) || (x1) - (x) > (n) || (y) - (y1) > (n) \ 272 || (y1) - (y) > (n) || (x) + (y) - (x1) - (y1) > (n) \ 273 || (x1) + (y1) - (x) - (y) > (n) ) ? FALSE : TRUE) 274 275 /*! \brief Is cell in reach? 276 * 277 * Test if cell at (x1, y1) is within reach of \Unit. 278 * \param u is a pointer to \Unit. 279 * \param x1 is the ending x location. 280 * \param y1 is the ending y location. 281 * \return TRUE if the unit is in reach of (x1, y1). 282 */ 283 #define cell_is_within_reach(u, x1, y1) \ 284 cell_is_within_range((u)->x, (u)->y, (u)->reach, (x1), (y1)) 285 286 /*! \brief Iterate over range. 287 * 288 * For header to repeat for all cells within range of starting cell. 289 * \param x is the starting x location. 290 * \param y is the starting y location. 291 * \param n is the range. 292 * \param x1 is the iteration x location of a cell in range. 293 * \param y1 is the iteration y location of a cell in range. 294 */ 295 #define for_all_cells_within_range(x, y, n, x1, y1) \ 296 for((x1) = (x) - (n); (x1) <= (x) + (n); (x1)++) \ 297 for((y1) = max((y) - (n), (y) - (n) + (x) - (x1)); \ 298 (y1) <= min((y) + (n), (y) + (n) + (x) - (x1)); (y1)++) 299 300 /*! \brief Iterate over all cells in range. 301 * 302 * Repeat for all cells withing reach of a unit. 303 * \see for_all_cells_within_range. 304 * \param u is a pointer to \Unit. 305 * \param x1 is the iteration x location of a cell in range. 306 * \param y1 is the iteration y location of a cell in range. 307 */ 308 #define for_all_cells_within_reach(u, x1, y1) \ 309 for_all_cells_within_range((u)->x, (u)->y, (u)->reach, (x1), (y1)) 310 311 /*! \brief Unit at cell. 312 * 313 * The \Unit is a raw pointer - this macro is used a *lot*. This could 314 * be space-optimized by using a 16-bit unit id. It uses the area.units global 315 * layer. Multiple units can be stacked by building a list using the 316 * \Unit->nexthere pointer. 317 * \see aref. 318 * \param x is the x location. 319 * \param y is the y location. 320 * \return pointer to \Unit at (x,y). 321 */ 322 #define unit_at(x,y) aref(area.units, x, y) 323 324 /*! \brief Set unit at cell. 325 * 326 * Set the pointer to the \Unit at cell(x,y). 327 * \note This macro DOES NOT link the Unit to any previous Units at 328 * the location, so it has to be done manually. 329 * \param x is the x location. 330 * \param y is the y location. 331 * \param u is the \Unit pointer. 332 */ 333 #define set_unit_at(x,y,u) aset(area.units, x, y, u) 334 335 /*! \brief Iterate Unit stack. 336 * 337 * Iterate through all \Units in this cell (but not their occs). 338 * \param x is the x location. 339 * \param y is the y location. 340 * \param var is the \Unit pointer. 341 */ 342 #define for_all_stack(x,y,var) \ 343 for ((var) = unit_at((x), (y)); (var) != NULL; (var) = (var)->nexthere) 344 345 /*! \brief Iterate Unit stack and occupants. 346 * 347 * Iterate through all units in this cell including occs within occs 348 * within occs. 349 * This nifty little macro will climb the occupant : nexthere tree and 350 * follow all branches four levels down to find all the occs within 351 * occs within occs within units in the stack. 352 * \param x is the x location. 353 * \param y is the y location. 354 * \param var is the \Unit pointer. 355 */ 356 #define for_all_stack_with_occs(x,y,var) \ 357 for ((var) = unit_at((x), (y)); \ 358 (var) != NULL; \ 359 (var) = ((var)->occupant != NULL ? \ 360 (var)->occupant : \ 361 ((var)->nexthere != NULL ? \ 362 (var)->nexthere : \ 363 ((var)->transport != NULL && \ 364 (var)->transport->nexthere != NULL ? \ 365 (var)->transport->nexthere : \ 366 ((var)->transport != NULL && \ 367 (var)->transport->transport != NULL && \ 368 (var)->transport->transport->nexthere != NULL ? \ 369 (var)->transport->transport->nexthere : \ 370 ((var)->transport != NULL && \ 371 (var)->transport->transport != NULL && \ 372 (var)->transport->transport->transport != NULL && \ 373 (var)->transport->transport->transport->nexthere != NULL ? \ 374 (var)->transport->transport->transport->nexthere : NULL)))))) 375 376 /*! \brief Is Terrain defined. 377 * 378 * Test if the terrain has been allocated yet. 379 * \return 380 * - TRUE if area.terrain is not NULL; 381 * - FALSE otherwise. 382 */ 383 #define terrain_defined() (area.terrain != NULL) 384 385 /*! \brief Terrain at. 386 * 387 * The Terrain at each cell is just the number of the Terrain type. 388 * \see aset. 389 * \param x is the x location. 390 * \param y is the y location. 391 * \return the Terrain type at the cell. 392 */ 393 #define terrain_at(x,y) aref(area.terrain, x, y) 394 395 /*! \brief Set Terrain at. 396 * 397 * Set the Terrain type at cell(x,y); 398 * \see aset. 399 * \param x is the x location. 400 * \param y is the y location. 401 * \param t is the Terran type to which to set the cell. 402 * \return the Terrain type at the cell. 403 */ 404 #define set_terrain_at(x,y,t) aset(area.terrain, x, y, t) 405 406 /* Auxiliary terrain array of layers. */ 407 408 /*! \brief Is any auxillary terrain defined? 409 * 410 * Check to see if there is any auxillary terrain defined. 411 * \return 412 * - TRUE if area.auxterrain is not NULL; 413 * - FALSE otherwise. 414 */ 415 #define any_aux_terrain_defined() (area.auxterrain != NULL) 416 417 /*! \brief Is kind of auxillary terrain defined? 418 * 419 * Check to see if a specific type of auxillary terrain is 420 * defined. 421 * \see any_aux_terrain_defined. 422 * \param at is the auxillary Terrain type. 423 * \return 424 * - TRUE if any_aux_terrain_defined() is TRUE and 425 * area.auxterrain[t] is not NULL; 426 * - FALSE otherwise. 427 */ 428 #define aux_terrain_defined(at) \ 429 (any_aux_terrain_defined() && area.auxterrain[at] != NULL) 430 431 /*! \brief Auxillary Terrain at. 432 * 433 * Get the auxillary terrain at a cell. 434 * \see aref. 435 * \param x is the x location. 436 * \param y is the y location. 437 * \param at is the auxillary Terrain type. 438 * \return the auxillary Terrain type at cell(x,y). 439 */ 440 #define aux_terrain_at(x,y,at) aref(area.auxterrain[at], x, y) 441 442 /*! \brief Set auxillary Terrain at. 443 * 444 * Set the auxillary terrain at a cell. 445 * \see aset. 446 * \param x is the x location. 447 * \param y is the y location. 448 * \param at is the auxillary Terrain type. 449 * \param v is the new value of the auxillary terrain. 450 * \return the new value of the auxillary Terrain type at cell(x,y). 451 */ 452 #define set_aux_terrain_at(x,y,at,v) aset(area.auxterrain[at], x, y, v) 453 454 /*! \brief Are there borders at? 455 * 456 * Check for a border at a given cell. 457 * \todo Not really correct, should finish. 458 * \see aux_terrain_at. 459 * \param x is the x location. 460 * \param y is the y location. 461 * \param b is the border Terrain type. 462 * \return 463 * - TRUE if the border value at cell(x,y) is non-zero; 464 * - FALSE otherwise. 465 */ 466 #define any_borders_at(x,y,b) (aux_terrain_at(x, y, b) != 0) 467 468 /*! \brief Is Border in dirction at. 469 * 470 * See if there is a border in the specified direction at cell(x,y) for 471 * the specified border type. 472 * \see aux_terrain_at. 473 * \param x is the x location. 474 * \param y is the y location. 475 * \param dir is the direction to check. 476 * \param b is the border Terrain type. 477 * \return 478 * - TRUE if the cell(x,y) has a border in a particular direction; 479 * - FALSE otherwise. 480 */ 481 #define border_at(x,y,dir,b) \ 482 (aux_terrain_defined(b) ? (aux_terrain_at(x, y, b) & (1 << (dir))) : FALSE) 483 484 /*! \brief Are there connections at? 485 * 486 * Check for a connections at a given cell. 487 * \see aux_terrain_at. 488 * \param x is the x location. 489 * \param y is the y location. 490 * \param c is the connections Terrain type. 491 * \return 492 * - TRUE if the connection value at cell(x,y) is non-zero; 493 * - FALSE otherwise. 494 */ 495 #define any_connections_at(x,y,c) (aux_terrain_at(x, y, c) != 0) 496 497 /*! \brief Is connection in dirction at. 498 * 499 * See if there is a connection in the specified direction at cell(x,y) for 500 * the specified connection type. 501 * \see aux_terrain_at. 502 * \param x is the x location. 503 * \param y is the y location. 504 * \param dir is the direction to check. 505 * \param c is the connection Terrain type. 506 * \return 507 * - TRUE if the cell(x,y) has a connection in a particular direction; 508 * - FALSE otherwise. 509 */ 510 #define connection_at(x,y,dir,c) \ 511 (aux_terrain_defined(c) ? (aux_terrain_at(x, y, c) & (1 << (dir))) : FALSE) 512 513 /* Elevation layer. */ 514 515 /*! \brief Are elevations defined? 516 * 517 * Check to see if the elevation layer has been defined. 518 * \return 519 * - TRUE if area.elevations has been allocated; 520 * - FALSE if pointer is NULL. 521 */ 522 #define elevations_defined() (area.elevations != NULL) 523 524 /*! \brief Elevation at. 525 * 526 * Get the elevation at cell(x,y). Elevations are stored in 527 * area.elevations. 528 * \see aref. 529 * \param x is the x location. 530 * \param y is the y location. 531 * \return elevation at cell(x,y). 532 */ 533 #define elev_at(x,y) aref(area.elevations, x, y) 534 535 /*! \brief Set elevation at. 536 * 537 * Set the elevation at cell(x,y). Elevations are stored in 538 * area.elevations. 539 * \see aref. 540 * \param x is the x location. 541 * \param y is the y location. 542 * \param v is the new value for the elevation. 543 * \return new elevation at cell(x,y). 544 */ 545 #define set_elev_at(x,y,v) aset(area.elevations, x, y, v) 546 547 /* Feature layer. */ 548 549 /*! \brief Are features defined? 550 * 551 * Check to see if features are defined in this game. 552 * \return 553 * - TRUE if area.features is not NULL; 554 * - FALSE otherwise. 555 */ 556 #define features_defined() (area.features != NULL) 557 558 /*! \brief Raw feature at. 559 * Get the id fo the feature at cell(x,y). 560 * The "raw feature" is its "short" identifier. 561 * \see aref. 562 * \param x is the x location. 563 * \param y is the y location. 564 * \return the short feature id. 565 */ 566 #define raw_feature_at(x,y) aref(area.features, x, y) 567 568 /*! \brief Set raw feature at. 569 * Set the id fo the feature at cell(x,y). 570 * The "raw feature" is its "short" identifier. 571 * \see aref. 572 * \param x is the x location. 573 * \param y is the y location. 574 * \param f is the feature id. 575 * \return the short feature id. 576 */ 577 #define set_raw_feature_at(x,y,f) aset(area.features, x, y, f) 578 579 /* Population layer. */ 580 581 /*! \brief Population defined? 582 * 583 * Check to see if people are assigned to sides. 584 * \return 585 * - TRUE if area.peopleside is not NULL; 586 * - FALSE otherwise. 587 */ 588 #define people_sides_defined() (area.peopleside != NULL) 589 590 /*! \brief Side of people at. 591 * 592 * Get the Side number of the people at cell(x,y). 593 * \param x is the x location. 594 * \param y is the y location. 595 * \return Side number of people at cell(x,y). 596 */ 597 #define people_side_at(x,y) aref(area.peopleside, x, y) 598 599 /*! \brief Set Side of people at. 600 * 601 * Set the Side number of the people at cell(x,y). 602 * \param x is the x location. 603 * \param y is the y location. 604 * \param s is the new Side number. 605 * \return new Side number of people at cell(x,y). 606 */ 607 #define set_people_side_at(x,y,s) aset(area.peopleside, x, y, s) 608 609 /*! \brief Nobody. 610 * 611 * A cell might be entirely uninhabited, so need an extra value to indicate. 612 * This value is chosen to be well above any possible MAXSIDES, and encodes 613 * in layers as 'X', which is convenient. 614 * \note It might be better to define this in terms of \ref MAXSIDES, to 615 * make sure there is no conflict. 616 */ 617 #define NOBODY (60) 618 619 /*! \brief Is populated? 620 * 621 * Check to see if the cell(x,y) is populated. 622 * \param x is the x location. 623 * \param y is the y location. 624 * \return 625 * - TRUE if Side number is not \ref NOBODY; 626 * _ FALSE otherwise. 627 */ 628 #define populated(x,y) (people_side_at(x,y) != NOBODY) 629 630 /* Control layer. */ 631 632 /*! \brief Is Area control defined? 633 * 634 * Check to see if the control layer is defined. 635 * \return 636 * - TRUE if araa.controlside is not NULL; 637 * - FALSE otherwise. 638 */ 639 #define control_sides_defined() (area.controlside != NULL) 640 641 /*! \brief Controled by at. 642 * 643 * Retrieve the side that controls cell(x,y). 644 * \param x is the x location. 645 * \param y is the y location. 646 * \return 647 * - Side id if controlled by a side. 648 * - NOCONTROL if not controlled by a side. 649 */ 650 #define control_side_at(x,y) aref(area.controlside, x, y) 651 652 /*! \brief Set controled by at. 653 * 654 * Set the side that controls cell(x,y). 655 * \param x is the x location. 656 * \param y is the y location. 657 * \param s is the new Side id that controls the cell. 658 * \return 659 * - Side id if controlled by a side. 660 * - NOCONTROL if not controlled by a side. 661 */ 662 #define set_control_side_at(x,y,s) aset(area.controlside, x, y, s) 663 664 /*! A cell might be entirely uncontrolled, so need an extra value to indicate. 665 * This value is chosen to be well above any possible MAXSIDES, and encodes 666 * in layers as 'X', which is convenient. 667 * 668 * \note It might be better to define this in terms of \ref MAXSIDES, to 669 * make sure there is no conflict. 670 */ 671 #define NOCONTROL (60) 672 673 /*! \brief Is Controlled? 674 * 675 * Check to see if the cell(x,y) is controlled by a side. 676 * \see control_side_at. 677 * \param x is the x location. 678 * \param y is the y location. 679 * \return 680 * - TRUE if Side number is not \ref NOCONTROL; 681 * _ FALSE otherwise. 682 */ 683 #define controlled(x,y) (control_side_at(x,y) != NOCONTROL) 684 685 /* Array of material layers. */ 686 687 /*! \brief Are cell Materials defined? 688 * 689 * Check to see if materials in cells are used. 690 * \return 691 * - TRUE if area.materials is not NULL; 692 * - FALSE otherwise. 693 */ 694 #define any_cell_materials_defined() (area.materials != NULL) 695 696 /*! \brief Is this material defined in cells? 697 * 698 * Check to see if a specific material is defined in cells. 699 * \param m is the material type. 700 * \return 701 * - TRUE if the area.materials[m] is not NULL; 702 * - FALSE otherwise. 703 */ 704 #define cell_material_defined(m) (area.materials[m] != NULL) 705 706 /*! \brief Material at cell. 707 * 708 * Get the amount of a specific material in cexll(x,y). 709 * \see aref. 710 * \param x is the x location. 711 * \param y is the y location. 712 * \param m is the Material type. 713 * \return the amount of the material at cell(x,y). 714 */ 715 #define material_at(x,y,m) aref(area.materials[m], x, y) 716 717 /*! \brief Set Material at cell. 718 * 719 * Set the amount of a specific material in cexll(x,y). 720 * \see aref. 721 * \param x is the x location. 722 * \param y is the y location. 723 * \param m is the Material type. 724 * \param v is the new value of the amount of Material at cell(x.y) 725 * \return the amount of the material at cell(x,y). 726 */ 727 #define set_material_at(x,y,m,v) aset(area.materials[m], x, y, v) 728 729 /* Temperature layer. */ 730 731 /*! \brief Is temperature defined? 732 * 733 * Check to see if temperature is defined. 734 * \return 735 * - TRUE if area.temperature is not NULL; 736 * - FALSE otherwise. 737 */ 738 #define temperatures_defined() (area.temperature != NULL) 739 740 /*! \brief Temperature at cell. 741 * 742 * Get temperature at cell(x,y). 743 * \see aref. 744 * \param x is the x location. 745 * \param y is the y location. 746 * \return the temperature at cell(x,y). 747 */ 748 #define temperature_at(x,y) aref(area.temperature, x, y) 749 750 /*! \brief Set temperature at cell. 751 * 752 * Set temperature at cell(x,y). 753 * \see aset. 754 * \param x is the x location. 755 * \param y is the y location. 756 * \param v is the new temperature. 757 * \return the temperature at cell(x,y). 758 */ 759 #define set_temperature_at(x,y,v) aset(area.temperature, x, y, v) 760 761 /* Clouds layer. */ 762 763 /*! \brief Are clouds defined? 764 * 765 * Check to see if clouds are used in game. 766 * \return 767 * - TRUE if area.clouds is not NULL; 768 * - FALSE otherwise. 769 */ 770 #define clouds_defined() (area.clouds != NULL) 771 772 /*! \brief Clouds at cell. 773 * 774 * Get clouds at cell(x,y). 775 * \see aref. 776 * \param x is the x location. 777 * \param y is the y location. 778 * \return the clouds at cell(x,y). 779 */ 780 #define raw_cloud_at(x,y) aref(area.clouds, x, y) 781 782 /*! \brief Set clouds at cell. 783 * 784 * set clouds at cell(x,y). 785 * \see aset. 786 * \param x is the x location. 787 * \param y is the y location. 788 * \param v is the new value of clouds. 789 * \return the clouds at cell(x,y). 790 */ 791 #define set_raw_cloud_at(x,y,v) aset(area.clouds, x, y, v) 792 793 /*! \brief Are cloud bottoms defined? 794 * 795 * Check to see if cloud bottoms are used in game. 796 * \return 797 * - TRUE if area.cloud bottoms is not NULL; 798 * - FALSE otherwise. 799 */ 800 #define cloud_bottoms_defined() (area.cloudbottoms != NULL) 801 802 /*! \brief Cloud bottom at cell. 803 * 804 * Get cloud bottom at cell(x,y). 805 * \see aref. 806 * \param x is the x location. 807 * \param y is the y location. 808 * \return the cloud bottom at cell(x,y). 809 */ 810 #define raw_cloud_bottom_at(x,y) aref(area.cloudbottoms, x, y) 811 812 /*! \brief Set cloud bottoms at cell. 813 * 814 * set cloud bottom at cell(x,y). 815 * \see aset. 816 * \param x is the x location. 817 * \param y is the y location. 818 * \param v is the new value of the cloud bottom. 819 * \return the cloud bottom at cell(x,y). 820 */ 821 #define set_raw_cloud_bottom_at(x,y,v) aset(area.cloudbottoms, x, y, v) 822 823 /*! \brief Are cloud tops defined? 824 * 825 * Check to see if cloud tops are used in game. 826 * \return 827 * - TRUE if area.cloud tops is not NULL; 828 * - FALSE otherwise. 829 */ 830 #define cloud_heights_defined() (area.cloudheights != NULL) 831 832 /*! \brief Cloud top at cell. 833 * 834 * Get cloud top at cell(x,y). 835 * \see aref. 836 * \param x is the x location. 837 * \param y is the y location. 838 * \return the cloud top at cell(x,y). 839 */ 840 #define raw_cloud_height_at(x,y) aref(area.cloudheights, x, y) 841 842 /*! \brief Set cloud top at cell. 843 * 844 * set cloud top at cell(x,y). 845 * \see aset. 846 * \param x is the x location. 847 * \param y is the y location. 848 * \param v is the new value of the cloud top. 849 * \return the cloud top at cell(x,y). 850 */ 851 #define set_raw_cloud_height_at(x,y,v) aset(area.cloudheights, x, y, v) 852 853 /* Winds layer. */ 854 855 /*! \brief Are winds defined? 856 * 857 * Check to see if winds are used in game. 858 * \return 859 * - TRUE if area.winds is not NULL; 860 * - FALSE otherwise. 861 */ 862 #define winds_defined() (area.winds != NULL) 863 864 /*! \brief Raw wind at cell. 865 * 866 * Get raw wind value at cell(x,y). The raw wind value is 867 * a combination of direction and force. The direction is 868 * in the bottom 3 bits of the cell value. 869 * \see aref. 870 * \param x is the x location. 871 * \param y is the y location. 872 * \return the raw wind at cell(x,y). 873 */ 874 #define raw_wind_at(x,y) aref(area.winds, x, y) 875 876 /*! \brief Set raw wind at cell. 877 * 878 * Set raw wind value at cell(x,y). The raw wind value is 879 * a combination of direction and force. The direction is 880 * in the bottom 3 bits of the cell value. 881 * \see aset. 882 * \param x is the x location. 883 * \param y is the y location. 884 * \param v is the new raw wind value. 885 * \return the raw wind at cell(x,y). 886 */ 887 #define set_raw_wind_at(x,y,v) aset(area.winds, x, y, v) 888 889 /*! \brief Wind direction. 890 * 891 * Extract the wind direction from the raw wind value. 892 * \param w is the raw wind value. 893 * \return the wind direction. 894 */ 895 #define wind_dir(w) ((w) & 0x07) 896 897 /*! \brief Wind froce. 898 * 899 * Extract the wind force from the raw wind value. 900 * \param w is the raw wind value. 901 * \return the wind force. 902 */ 903 #define wind_force(w) ((w) >> 3) 904 905 /*! \brief Wind direction at. 906 * 907 * Get the wind direction at cell(x,y). 908 * \see wind_dir, raw_wind_at. 909 * \param x is the x location. 910 * \param y is the y location. 911 * \return the wind direction at cell(x,y). 912 */ 913 #define wind_dir_at(x,y) (wind_dir(raw_wind_at(x, y))) 914 915 /*! \brief Wind force at. 916 * 917 * Get the wind force at cell(x,y). 918 * \see wind_force, raw_wind_at. 919 * \param x is the x location. 920 * \param y is the y location. 921 * \return the wind force at cell(x,y). 922 */ 923 #define wind_force_at(x,y) (wind_force(raw_wind_at(x, y))) 924 925 /*! \brief Set wind at cell. 926 * 927 * Set wind value at cell(x,y). 928 * \see set_raw_wind_at. 929 * \param x is the x location. 930 * \param y is the y location. 931 * \param d is the new wind direction value. 932 * \param f is the new wind force value. 933 * \return the raw wind at cell(x,y). 934 */ 935 #define set_wind_at(x,y,d,f) (set_raw_wind_at(x, y, ((f) << 3) | (d))) 936 937 /*! \brief Calm wind force. */ 938 #define CALM (0) 939 940 /* Handlers for scratch layers. */ 941 942 /*! \brief Get scratch layer 1. 943 * 944 * Get the value of scratch layer 1 at cell(x,y). 945 * \param x is the x location. 946 * \param y is the y location. 947 * \return the value of scratch layer 1 at cell(x,y). 948 */ 949 #define tmp1_at(x,y) aref(area.tmp1, x, y) 950 951 /*! \brief Set scratch layer 1. 952 * 953 * Set the value of scratch layer 1 at cell(x,y). 954 * \param x is the x location. 955 * \param y is the y location. 956 * \param v is the new value. 957 * \return the value of scratch layer 1 at cell(x,y). 958 */ 959 #define set_tmp1_at(x,y,v) aset(area.tmp1, x, y, v) 960 961 /*! \brief Get scratch layer 2. 962 * 963 * Get the value of scratch layer 2 at cell(x,y). 964 * \param x is the x location. 965 * \param y is the y location. 966 * \return the value of scratch layer 2 at cell(x,y). 967 */ 968 #define tmp2_at(x,y) aref(area.tmp2, x, y) 969 970 /*! \brief Set scratch layer 2. 971 * 972 * Set the value of scratch layer 2 at cell(x,y). 973 * \param x is the x location. 974 * \param y is the y location. 975 * \param v is the new value. 976 * \return the value of scratch layer 2 at cell(x,y). 977 */ 978 #define set_tmp2_at(x,y,v) aset(area.tmp2, x, y, v) 979 980 /*! \brief Get scratch layer 3. 981 * 982 * Get the value of scratch layer 3 at cell(x,y). 983 * \param x is the x location. 984 * \param y is the y location. 985 * \return the value of scratch layer 3 at cell(x,y). 986 */ 987 #define tmp3_at(x,y) aref(area.tmp3, x, y) 988 989 /*! \brief Set scratch layer 3. 990 * 991 * Set the value of scratch layer 3 at cell(x,y). 992 * \param x is the x location. 993 * \param y is the y location. 994 * \param v is the new value. 995 * \return the value of scratch layer 3 at cell(x,y). 996 */ 997 #define set_tmp3_at(x,y,v) aset(area.tmp3, x, y, v) 998 999 /*! \brief Wrap x. 1000 * 1001 * This little macro implements wraparound in the x direction. 1002 * \note The stupid add of shifted width is for the benefit of brain-damaged 1003 * mod operators that don't handle negative numbers properly. 1004 * \param x is the unwrapped x value. 1005 * \return the value within the world bounds. 1006 */ 1007 #define wrapx(x) (area.xwrap ? (((x) + (area.width << 8)) % area.width) : (x)) 1008 1009 /*! \brief Constrain y co-ordinate. 1010 * 1011 * Constrain y to northern and southern edges. 1012 * \see max, min. 1013 * \param y is raw y co-ordiante. 1014 * \return y co-ordinate withing world boundary. 1015 */ 1016 #define limity(y) (max(0, min((y), (area.height-1)))) 1017 1018 /*! \brief Constrain y to inerior of world. 1019 * 1020 * Constrain y co-ordinate to be within world. 1021 * \see max, min. 1022 * \param y is raw y co-ordiante. 1023 * \return y co-ordinate in interior of world. 1024 */ 1025 #define interior(y) (max(1, min((y), (area.height-2)))) 1026 1027 /*! \brief Coordinate in direction. 1028 * 1029 * Calculate the co-ordinates of moving a distance of one in a 1030 * direction, contraining the x co-ordiante to be wrapped. 1031 * \note The y co-odinate is not limited or constrained. 1032 * \see wrapx.. 1033 * \param x is the current x co-ordinate. 1034 * \param y is the current y co-ordinate. 1035 * \param d is the direction to move. 1036 * \param nx is the new x co-ordinate. 1037 * \param ny is the new y co-ordiante. 1038 * \return the new y co-ordiante. 1039 */ 1040 #define xy_in_dir(x,y,dir,nx,ny) \ 1041 (nx) = wrapx((x) + dirx[dir]); (ny) = (y) + diry[dir]; 1042 1043 /*! \brief Is in area? 1044 * 1045 * Test whether x,y is a valid position anywhere in the current area. 1046 * \note in_area and inside_area are very heavily used; any 1047 * optimization will likely speed up Xconq overall. 1048 * \see between, x_in_area. 1049 * \param x is the x co-ordinate. 1050 * \param y is the y co-ordiante. 1051 * \return 1052 * - TRUE if cell(x,y) is in area; 1053 * - FALSE otherwise. 1054 */ 1055 #define in_area(x, y) \ 1056 (between(0, (y), area.height-1) && x_in_area(x, y)) 1057 1058 /*! \brief Is x in area? 1059 * 1060 * Test whether x is a inside the current area. 1061 * \note in_area and inside_area are very heavily used; any 1062 * optimization will likely speed up Xconq overall. 1063 * \see between. 1064 * \param x is the x co-ordinate. 1065 * \param y is the y co-ordiante. 1066 * \return 1067 * - TRUE if cell(x,y) is in area; 1068 * - FALSE otherwise. 1069 */ 1070 #define x_in_area(x, y) \ 1071 (area.xwrap ? TRUE : (between(0, (x), area.width-1) && \ 1072 between(area.halfheight, \ 1073 (x)+(y), \ 1074 area.width+area.halfheight-1))) 1075 1076 /*! \brief Is valid unit position? 1077 * 1078 * Test whether x,y is a valid position anywhere in the current area. 1079 * \note in_area and inside_area are very heavily used; any 1080 * optimization will likely speed up Xconq overall. 1081 * \bug Does x testing work right for even/odd heights? 1082 * \see between, x_inside_area. 1083 * \param x is the x co-ordinate. 1084 * \param y is the y co-ordiante. 1085 * \return 1086 * - TRUE if cell(x,y) is inside area; 1087 * - FALSE otherwise. 1088 */ 1089 #define inside_area(x, y) \ 1090 (between(1, (y), area.height-2) && x_inside_area(x, y)) 1091 1092 /*! \brief Is x a valid unit postion? 1093 * 1094 * Test whether x is a inside the current area. 1095 * \note in_area and inside_area are very heavily used; any 1096 * optimization will likely speed up Xconq overall. 1097 * \bug Does x testing work right for even/odd heights? 1098 * \see between. 1099 * \param x is the x co-ordinate. 1100 * \param y is the y co-ordiante. 1101 * \return 1102 * - TRUE if cell(x,y) is in area; 1103 * - FALSE otherwise. 1104 */ 1105 #define x_inside_area(x, y) \ 1106 (area.xwrap ? TRUE : (between(1, (x), area.width-2) && \ 1107 between(area.halfheight+1, \ 1108 (x)+(y), \ 1109 area.width+area.halfheight-2))) 1110 1111 /*! \brief Iterate over all cells. 1112 * 1113 * Iteration over all valid cell positions in a area. These should be 1114 * used carefully, since they don't (can't) have any grouping braces 1115 * embedded. 1116 * \see x_in_area. 1117 * \param x is the x co-ordinate. 1118 * \param y is the y co-ordiante. 1119 */ 1120 #define for_all_cells(x,y) \ 1121 for (x = 0; x < area.width; ++x) \ 1122 for (y = 0; y < area.height; ++y) \ 1123 if (x_in_area(x, y)) 1124 1125 /* This doesn't generate positions along area edges. Typically more 1126 useful within game. */ 1127 /*! \brief Iterate over all interior cells. 1128 * 1129 * This doesn't generate positions along area edges. Typically more 1130 * useful within game than for_all_cells(). 1131 * Iteration over all valid interior cell positions in a area. These should be 1132 * used carefully, since they don't (can't) have any grouping braces 1133 * embedded. 1134 * \see x_inside_area. 1135 * \param x is the x co-ordinate. 1136 * \param y is the y co-ordiante. 1137 */ 1138 #define for_all_interior_cells(x,y) \ 1139 for (x = 0; x < area.width; ++x) \ 1140 for (y = 1; y < area.height - 1; ++y) \ 1141 if (x_inside_area(x, y)) 1142 1143 /*! \brief Iterate through features. 1144 * 1145 * Walk thrhoug all defined features. 1146 * \param feat is the feature iteration variable. 1147 */ 1148 #define for_all_features(feat) \ 1149 for ((feat) = featurelist; (feat) != NULL; (feat) = (feat)->next) 1150 1151 /*! \brief Lighting at cell. 1152 * 1153 * Returns the lighting state of a given position. 1154 * \todo (should opencode distance call here) 1155 * \param x is the cell's x co-ordinate. 1156 * \param y is the cell's y co-ordinate. 1157 * \param snx is the sun's x co-ordinate. 1158 * \param sny is the sun's y co-ordiante. 1159 * \return 1160 * - two if in sunlight; 1161 * - one if in twilight; or 1162 * - zero if in darkness. 1163 */ 1164 #define lighting(x,y,snx,sny) \ 1165 ((world_distance(x, y, snx, sny) < world.daylight_width) ? 2 : \ 1166 ((world_distance(x, y, snx, sny) < world.twilight_width) ? 1 : 0)) 1167 1168 /*! \brief Night at cell? 1169 * 1170 * Is it night at cell(x,y) 1171 * \see lighting, sunx, suny. 1172 * \param x is the cell's x co-ordinate. 1173 * \param y is the cell's y co-ordinate. 1174 * \return 1175 * - TRUE if lighting is 0 at cell; 1176 * - FALSE otherwise. 1177 */ 1178 #define night_at(x,y) \ 1179 (daynight && lighting((x), (y), (int) sunx, (int) suny) == 0) 1180 1181 /* World-related variables. */ 1182 1183 /*! World global. */ 1184 extern World world; 1185 1186 /*! Area global. */ 1187 extern Area area; 1188 1189 /*! Mid turn restore flag. ???*/ 1190 extern int midturnrestore; 1191 1192 /*! Number of features. */ 1193 extern int numfeatures; 1194 1195 /*! Minimum elevation. */ 1196 extern int minelev; 1197 /*! Maximum elevation. */ 1198 extern int maxelev; 1199 /*! Minimum termperature. */ 1200 extern int mintemp; 1201 /*! Maximum termperature. */ 1202 extern int maxtemp; 1203 /*! Minimum wind forces. */ 1204 extern int minwindforce; 1205 /*! Maximum windforce. */ 1206 extern int maxwindforce; 1207 1208 /*! Any Materials in terrain? ??? */ 1209 extern int any_materials_in_terrain; 1210 /*! Any elevation variation? ??? */ 1211 extern int any_elev_variation; 1212 /*! Any temperture variation? ??? */ 1213 extern int any_temp_variation; 1214 /*! Any temperature variation in layer? ??? */ 1215 extern int any_temp_variation_in_layer; 1216 /*! Any wind variation? ??? */ 1217 extern int any_wind_variation; 1218 /*! Any wind variation in layer? ??? */ 1219 extern int any_wind_variation_in_layer; 1220 /*! Any clouds? ??? */ 1221 extern int any_clouds; 1222 1223 /* World-related functions. */ 1224 1225 extern void init_world(void); 1226 extern int set_world_circumference(int circum, int warn); 1227 extern int set_area_shape(int width, int height, int warn); 1228 extern int valid_area_shape(int width, int height, int warn); 1229 extern void check_area_shape(void); 1230 extern void calculate_world_globals(void); 1231 extern void final_init_world(void); 1232 extern void compute_elevation_bounds(void); 1233 1234 extern void allocate_area_terrain(void); 1235 extern void allocate_area_aux_terrain(int t); 1236 extern void allocate_area_scratch(int n); 1237 extern void allocate_area_elevations(void); 1238 extern void allocate_area_temperatures(void); 1239 extern void allocate_area_people_sides(void); 1240 extern void allocate_area_control_sides(void); 1241 extern void allocate_area_material(int m); 1242 extern void allocate_area_clouds(void); 1243 extern void allocate_area_cloud_altitudes(void); 1244 extern void allocate_area_cloud_bottoms(void); 1245 extern void allocate_area_cloud_heights(void); 1246 extern void allocate_area_winds(void); 1247 1248 extern int fn_terrain_at(int x, int y); 1249 extern int fn_aux_terrain_at(int x, int y); 1250 extern int fn_feature_at(int x, int y); 1251 extern int fn_elevation_at(int x, int y); 1252 extern int fn_people_side_at(int x, int y); 1253 extern int fn_control_side_at(int x, int y); 1254 extern int fn_material_at(int x, int y); 1255 extern int fn_temperature_at(int x, int y); 1256 extern int fn_raw_cloud_at(int x, int y); 1257 extern int fn_raw_cloud_bottom_at(int x, int y); 1258 extern int fn_raw_cloud_height_at(int x, int y); 1259 extern int fn_raw_wind_at(int x, int y); 1260 extern void allocate_area_users(void); 1261 extern int fn_user_at(int x, int y); 1262 extern void fn_set_user_at(int x, int y, int val); 1263 extern void fn_set_terrain_at(int x, int y, int val); 1264 extern void fn_set_aux_terrain_at(int x, int y, int val); 1265 extern void fn_set_people_side_at(int x, int y, int val); 1266 extern void fn_set_control_side_at(int x, int y, int val); 1267 extern void fn_set_raw_feature_at(int x, int y, int val); 1268 extern void fn_set_elevation_at(int x, int y, int val); 1269 extern void fn_set_material_at(int x, int y, int val); 1270 extern void fn_set_temperature_at(int x, int y, int val); 1271 extern void fn_set_raw_wind_at(int x, int y, int val); 1272 extern void fn_set_raw_cloud_at(int x, int y, int val); 1273 extern void fn_set_raw_cloud_bottom_at(int x, int y, int val); 1274 extern void fn_set_raw_cloud_height_at(int x, int y, int val); 1275 1276 extern void change_terrain_type(int x, int y, int t2); 1277 1278 extern int limited_search_around(int x0, int y0, int range, 1279 int (*pred)(int, int, int *, ParamBox *), 1280 int incr, int *counter, 1281 int rsltlimit, ParamBox *parambox); 1282 extern int search_around(int x0, int y0, int range, 1283 int (*pred)(int, int, int *, ParamBox *), 1284 int incr, ParamBox *parambox); 1285 extern int search_around(int x0, int y0, int maxdist, int (*pred)(int, int), 1286 int *rxp, int *ryp, int incr); 1287 extern int limited_search_around(int x0, int y0, int maxdist, 1288 int (*pred)(int, int, int *), int *rxp, 1289 int *ryp, int incr, int rsltlimit); 1290 extern int search_and_apply(int x0, int y0, int maxdist, int (*pred)(int, int), 1291 int *rxp, int *ryp, int incr, 1292 void (*fn)(int, int), int num); 1293 extern void apply_to_area(int x0, int y0, int dist, void (*fn)(int, int)); 1294 extern void apply_to_area_plus_edge(int x0, int y0, int dist, 1295 void (*fn)(int, int)); 1296 extern void apply_to_ring(int x0, int y0, int distmin, int distmax, 1297 void (*fn)(int, int)); 1298 extern void apply_to_hexagon(int x0, int y0, int w2, int h2, 1299 void (*fn)(int, int)); 1300 extern int limited_search_under_arc(int x, int y, int dir, int range, 1301 int dirbias, 1302 int (*pred)(int x, int y, int *counter, 1303 ParamBox *parambox), 1304 int *counter, int rsltlimit, 1305 ParamBox *parambox); 1306 extern int search_under_arc(int x, int y, int dir, int range, int dirbias, 1307 int (*pred)(int x, int y, int *counter, 1308 ParamBox *parambox), 1309 ParamBox *parambox); 1310 extern void apply_to_path(int fx, int fy, int tx, int ty, 1311 int (*dirtest)(int x, int y, int dir), 1312 int (*dirsort)(int x, int y, int *dirchoices, 1313 int numchoices), 1314 int (*fn)(int x, int y, int dir, int j, 1315 int numchoices), 1316 int shortest); 1317 #if 0 1318 int find_path(int fx, int fy, int tx, int ty, 1319 int (*chooser)(int, int, int, int, int *), 1320 int maxwps, Waypoint *waypoints, int *numwpsp); 1321 #endif 1322 extern int search_straight_line(int x0, int y0, int x1, int y1, 1323 int (*pred)(int, int), int *rxp, int *ryp); 1324 1325 extern void set_border_at(int x, int y, int dir, int t, int onoff); 1326 extern void set_connection_at(int x, int y, int dir, int t, int onoff); 1327 extern void patch_linear_terrain(int t); 1328 1329 extern void init_features(void); 1330 extern Feature *find_feature(int fid); 1331 extern Feature *feature_at(int x, int y); 1332 extern void compute_all_feature_centroids(void); 1333 extern void compute_feature_centroid(Feature *feature); 1334 1335 extern int point_in_dir(int x, int y, int dir, int *xp, int *yp); 1336 extern int interior_point_in_dir(int x, int y, int dir, int *xp, int *yp); 1337 extern int point_in_dir_n(int x, int y, int dir, int n, int *xp, int *yp); 1338 extern int interior_point_in_dir_n(int x, int y, int dir, int n, 1339 int *xp, int *yp); 1340 extern int random_point(int *xp, int *yp); 1341 extern int random_edge_point(int *xp, int *yp); 1342 extern int random_point_near(int cx, int cy, int radius, int *xp, int *yp); 1343 extern int random_point_in_area(int cx, int cy, int rx, int ry, 1344 int *xp, int *yp); 1345 extern void terrain_subtype_warning(char *context, int t); 1346 extern int approx_dir(int dx, int dy); 1347 extern int hextant(int dx, int dy); 1348 extern int distance(int x1, int y1, int x2, int y2); 1349 extern int world_distance(int x1, int y1, int x2, int y2); 1350 extern int closest_dir(int x, int y); 1351 1352 extern void xy_to_latlong(int x, int y, int xf, int yf, int *latp, int *lonp); 1353 extern int latlong_to_xy(int lat, int lon, int *xp, int *yp, 1354 int *xfp, int *yfp); 1355 extern int num_people_at(int x, int y); 1356