00001
00002
00003
00004
00005
00006
00007
00008
00017 typedef struct a_world {
00018 int circumference;
00019 int daylength;
00020 int yearlength;
00021 int axial_tilt;
00022 int daylight_fraction;
00023 int twilight_fraction;
00024 int daylight_width;
00025 int twilight_width;
00026 } World;
00027
00033 #define MINWIDTH 3
00034
00040 #define MINHEIGHT 3
00041
00052 typedef struct a_area {
00053 short width;
00054 short height;
00055 short halfwidth;
00056 short halfheight;
00057 short maxdim;
00058 short xwrap;
00059 int numcells;
00060 int latitude;
00061 int longitude;
00062 short projection;
00063 int cellwidth;
00064 short fullwidth;
00065 short fullheight;
00066 short fullx;
00067 short fully;
00068 short sunx;
00069 short suny;
00070 Obj *temp_year;
00071 char *image_name;
00073 struct a_unit **units;
00074 char *terrain;
00075 char **auxterrain;
00076 char *peopleside;
00077 char *controlside;
00078 short *features;
00079 short *elevations;
00080 short avgelev;
00081 short minelev;
00082 short maxelev;
00083 long **materials;
00084 short *temperature;
00085 short *clouds;
00086 short *cloudbottoms;
00087 short *cloudheights;
00088 short *winds;
00089
00090 short *tmp1;
00091 short *tmp2;
00092 short *tmp3;
00093 struct a_region **terrain_regions;
00094 struct a_region **landsea_regions;
00095 short *user;
00096 } Area;
00097
00101 typedef struct a_feature {
00102 int type;
00103 short id;
00104 char *name;
00105 char *feattype;
00107 struct a_feature *next;
00108
00109 int size;
00110 int x;
00111 int y;
00112 short xmin;
00113 short ymin;
00114 short xmax;
00115 short ymax;
00116 int mindiam;
00117 int maxdiam;
00118 int relabel;
00119 } Feature;
00120
00121
00122
00126 typedef struct a_waypoint {
00127 int x;
00128 int y;
00129 int note;
00130 } Waypoint;
00131
00136 typedef struct a_path {
00137 int numwps;
00138 Waypoint wps[100];
00139 } Path;
00140
00141
00142
00144 typedef struct a_region {
00145 int ttype;
00146 int size;
00147 short xmin;
00148 short ymin;
00149 short xmax;
00150 short ymax;
00151 struct a_region *merge;
00152 struct a_region_link *neighbors;
00153 struct a_region *next;
00154 } TRegion;
00155
00157 typedef struct a_region_link {
00158 struct a_region *neighbor;
00159 struct a_region_link *next;
00160 } TRegionLink;
00161
00170 #define malloc_area_layer(TYPE) \
00171 ((TYPE *) xmalloc(area.width * area.height * sizeof(TYPE)))
00172
00182 #define zero_area_layer(ADDR, TYPE) \
00183 (memset(ADDR, 0, area.width * area.height * sizeof(TYPE)))
00184
00185
00186
00196 #define aref(m,x,y) \
00197 (in_area((x),(y)) ? (m)[area.width * (y) + wrapx((x))] : 0)
00198
00209 #define aset(m,x,y,v) \
00210 (in_area((x),(y)) ? (m)[area.width * (y) + wrapx((x))] = (v) : 0)
00211
00222 #define aadd(m,x,y,v) \
00223 (in_area((x),(y)) ? (m)[area.width * (y) + wrapx((x))] += (v) : 0)
00224
00225
00226
00230 #define NOUSER (0)
00231
00238 #define user_defined() (area.user != NULL)
00239
00247 #define user_at(x, y) aref(area.user, x, y)
00248
00249 #define set_user_at(x, y, u) aset(area.user, x, y, u)
00250
00258 #define radius_covers_n_cells(dist) (1 + (((dist) + 1) * (dist) * 3))
00259
00270 #define cell_is_within_range(x, y, n, x1, y1) \
00271 (( (x) - (x1) > (n) || (x1) - (x) > (n) || (y) - (y1) > (n) \
00272 || (y1) - (y) > (n) || (x) + (y) - (x1) - (y1) > (n) \
00273 || (x1) + (y1) - (x) - (y) > (n) ) ? FALSE : TRUE)
00274
00283 #define cell_is_within_reach(u, x1, y1) \
00284 cell_is_within_range((u)->x, (u)->y, (u)->reach, (x1), (y1))
00285
00295 #define for_all_cells_within_range(x, y, n, x1, y1) \
00296 for((x1) = (x) - (n); (x1) <= (x) + (n); (x1)++) \
00297 for((y1) = max((y) - (n), (y) - (n) + (x) - (x1)); \
00298 (y1) <= min((y) + (n), (y) + (n) + (x) - (x1)); (y1)++)
00299
00308 #define for_all_cells_within_reach(u, x1, y1) \
00309 for_all_cells_within_range((u)->x, (u)->y, (u)->reach, (x1), (y1))
00310
00322 #define unit_at(x,y) aref(area.units, x, y)
00323
00333 #define set_unit_at(x,y,u) aset(area.units, x, y, u)
00334
00342 #define for_all_stack(x,y,var) \
00343 for ((var) = unit_at((x), (y)); (var) != NULL; (var) = (var)->nexthere)
00344
00356 #define for_all_stack_with_occs(x,y,var) \
00357 for ((var) = unit_at((x), (y)); \
00358 (var) != NULL; \
00359 (var) = ((var)->occupant != NULL ? \
00360 (var)->occupant : \
00361 ((var)->nexthere != NULL ? \
00362 (var)->nexthere : \
00363 ((var)->transport != NULL && \
00364 (var)->transport->nexthere != NULL ? \
00365 (var)->transport->nexthere : \
00366 ((var)->transport != NULL && \
00367 (var)->transport->transport != NULL && \
00368 (var)->transport->transport->nexthere != NULL ? \
00369 (var)->transport->transport->nexthere : \
00370 ((var)->transport != NULL && \
00371 (var)->transport->transport != NULL && \
00372 (var)->transport->transport->transport != NULL && \
00373 (var)->transport->transport->transport->nexthere != NULL ? \
00374 (var)->transport->transport->transport->nexthere : NULL))))))
00375
00383 #define terrain_defined() (area.terrain != NULL)
00384
00393 #define terrain_at(x,y) aref(area.terrain, x, y)
00394
00404 #define set_terrain_at(x,y,t) aset(area.terrain, x, y, t)
00405
00406
00407
00415 #define any_aux_terrain_defined() (area.auxterrain != NULL)
00416
00428 #define aux_terrain_defined(at) \
00429 (any_aux_terrain_defined() && area.auxterrain[at] != NULL)
00430
00440 #define aux_terrain_at(x,y,at) aref(area.auxterrain[at], x, y)
00441
00452 #define set_aux_terrain_at(x,y,at,v) aset(area.auxterrain[at], x, y, v)
00453
00466 #define any_borders_at(x,y,b) (aux_terrain_at(x, y, b) != 0)
00467
00481 #define border_at(x,y,dir,b) \
00482 (aux_terrain_defined(b) ? (aux_terrain_at(x, y, b) & (1 << (dir))) : FALSE)
00483
00495 #define any_connections_at(x,y,c) (aux_terrain_at(x, y, c) != 0)
00496
00510 #define connection_at(x,y,dir,c) \
00511 (aux_terrain_defined(c) ? (aux_terrain_at(x, y, c) & (1 << (dir))) : FALSE)
00512
00513
00514
00522 #define elevations_defined() (area.elevations != NULL)
00523
00533 #define elev_at(x,y) aref(area.elevations, x, y)
00534
00545 #define set_elev_at(x,y,v) aset(area.elevations, x, y, v)
00546
00547
00548
00556 #define features_defined() (area.features != NULL)
00557
00566 #define raw_feature_at(x,y) aref(area.features, x, y)
00567
00577 #define set_raw_feature_at(x,y,f) aset(area.features, x, y, f)
00578
00579
00580
00588 #define people_sides_defined() (area.peopleside != NULL)
00589
00597 #define people_side_at(x,y) aref(area.peopleside, x, y)
00598
00607 #define set_people_side_at(x,y,s) aset(area.peopleside, x, y, s)
00608
00617 #define NOBODY (60)
00618
00628 #define populated(x,y) (people_side_at(x,y) != NOBODY)
00629
00630
00631
00639 #define control_sides_defined() (area.controlside != NULL)
00640
00650 #define control_side_at(x,y) aref(area.controlside, x, y)
00651
00662 #define set_control_side_at(x,y,s) aset(area.controlside, x, y, s)
00663
00671 #define NOCONTROL (60)
00672
00683 #define controlled(x,y) (control_side_at(x,y) != NOCONTROL)
00684
00685
00686
00694 #define any_cell_materials_defined() (area.materials != NULL)
00695
00704 #define cell_material_defined(m) (area.materials[m] != NULL)
00705
00715 #define material_at(x,y,m) aref(area.materials[m], x, y)
00716
00727 #define set_material_at(x,y,m,v) aset(area.materials[m], x, y, v)
00728
00729
00730
00738 #define temperatures_defined() (area.temperature != NULL)
00739
00748 #define temperature_at(x,y) aref(area.temperature, x, y)
00749
00759 #define set_temperature_at(x,y,v) aset(area.temperature, x, y, v)
00760
00761
00762
00770 #define clouds_defined() (area.clouds != NULL)
00771
00780 #define raw_cloud_at(x,y) aref(area.clouds, x, y)
00781
00791 #define set_raw_cloud_at(x,y,v) aset(area.clouds, x, y, v)
00792
00800 #define cloud_bottoms_defined() (area.cloudbottoms != NULL)
00801
00810 #define raw_cloud_bottom_at(x,y) aref(area.cloudbottoms, x, y)
00811
00821 #define set_raw_cloud_bottom_at(x,y,v) aset(area.cloudbottoms, x, y, v)
00822
00830 #define cloud_heights_defined() (area.cloudheights != NULL)
00831
00840 #define raw_cloud_height_at(x,y) aref(area.cloudheights, x, y)
00841
00851 #define set_raw_cloud_height_at(x,y,v) aset(area.cloudheights, x, y, v)
00852
00853
00854
00862 #define winds_defined() (area.winds != NULL)
00863
00874 #define raw_wind_at(x,y) aref(area.winds, x, y)
00875
00887 #define set_raw_wind_at(x,y,v) aset(area.winds, x, y, v)
00888
00895 #define wind_dir(w) ((w) & 0x07)
00896
00903 #define wind_force(w) ((w) >> 3)
00904
00913 #define wind_dir_at(x,y) (wind_dir(raw_wind_at(x, y)))
00914
00923 #define wind_force_at(x,y) (wind_force(raw_wind_at(x, y)))
00924
00935 #define set_wind_at(x,y,d,f) (set_raw_wind_at(x, y, ((f) << 3) | (d)))
00936
00938 #define CALM (0)
00939
00940
00941
00949 #define tmp1_at(x,y) aref(area.tmp1, x, y)
00950
00959 #define set_tmp1_at(x,y,v) aset(area.tmp1, x, y, v)
00960
00968 #define tmp2_at(x,y) aref(area.tmp2, x, y)
00969
00978 #define set_tmp2_at(x,y,v) aset(area.tmp2, x, y, v)
00979
00987 #define tmp3_at(x,y) aref(area.tmp3, x, y)
00988
00997 #define set_tmp3_at(x,y,v) aset(area.tmp3, x, y, v)
00998
01007 #define wrapx(x) (area.xwrap ? (((x) + (area.width << 8)) % area.width) : (x))
01008
01016 #define limity(y) (max(0, min((y), (area.height-1))))
01017
01025 #define interior(y) (max(1, min((y), (area.height-2))))
01026
01040 #define xy_in_dir(x,y,dir,nx,ny) \
01041 (nx) = wrapx((x) + dirx[dir]); (ny) = (y) + diry[dir];
01042
01055 #define in_area(x, y) \
01056 (between(0, (y), area.height-1) && x_in_area(x, y))
01057
01070 #define x_in_area(x, y) \
01071 (area.xwrap ? TRUE : (between(0, (x), area.width-1) && \
01072 between(area.halfheight, \
01073 (x)+(y), \
01074 area.width+area.halfheight-1)))
01075
01089 #define inside_area(x, y) \
01090 (between(1, (y), area.height-2) && x_inside_area(x, y))
01091
01105 #define x_inside_area(x, y) \
01106 (area.xwrap ? TRUE : (between(1, (x), area.width-2) && \
01107 between(area.halfheight+1, \
01108 (x)+(y), \
01109 area.width+area.halfheight-2)))
01110
01120 #define for_all_cells(x,y) \
01121 for (x = 0; x < area.width; ++x) \
01122 for (y = 0; y < area.height; ++y) \
01123 if (x_in_area(x, y))
01124
01125
01126
01138 #define for_all_interior_cells(x,y) \
01139 for (x = 0; x < area.width; ++x) \
01140 for (y = 1; y < area.height - 1; ++y) \
01141 if (x_inside_area(x, y))
01142
01148 #define for_all_features(feat) \
01149 for ((feat) = featurelist; (feat) != NULL; (feat) = (feat)->next)
01150
01164 #define lighting(x,y,snx,sny) \
01165 ((world_distance(x, y, snx, sny) < world.daylight_width) ? 2 : \
01166 ((world_distance(x, y, snx, sny) < world.twilight_width) ? 1 : 0))
01167
01178 #define night_at(x,y) \
01179 (daynight && lighting((x), (y), (int) sunx, (int) suny) == 0)
01180
01181
01182
01184 extern World world;
01185
01187 extern Area area;
01188
01190 extern int midturnrestore;
01191
01193 extern int numfeatures;
01194
01196 extern int minelev;
01198 extern int maxelev;
01200 extern int mintemp;
01202 extern int maxtemp;
01204 extern int minwindforce;
01206 extern int maxwindforce;
01207
01209 extern int any_materials_in_terrain;
01211 extern int any_elev_variation;
01213 extern int any_temp_variation;
01215 extern int any_temp_variation_in_layer;
01217 extern int any_wind_variation;
01219 extern int any_wind_variation_in_layer;
01221 extern int any_clouds;
01222
01223
01224
01225 extern void init_world(void);
01226 extern int set_world_circumference(int circum, int warn);
01227 extern int set_area_shape(int width, int height, int warn);
01228 extern int valid_area_shape(int width, int height, int warn);
01229 extern void check_area_shape(void);
01230 extern void calculate_world_globals(void);
01231 extern void final_init_world(void);
01232 extern void compute_elevation_bounds(void);
01233
01234 extern void allocate_area_terrain(void);
01235 extern void allocate_area_aux_terrain(int t);
01236 extern void allocate_area_scratch(int n);
01237 extern void allocate_area_elevations(void);
01238 extern void allocate_area_temperatures(void);
01239 extern void allocate_area_people_sides(void);
01240 extern void allocate_area_control_sides(void);
01241 extern void allocate_area_material(int m);
01242 extern void allocate_area_clouds(void);
01243 extern void allocate_area_cloud_altitudes(void);
01244 extern void allocate_area_cloud_bottoms(void);
01245 extern void allocate_area_cloud_heights(void);
01246 extern void allocate_area_winds(void);
01247
01248 extern int fn_terrain_at(int x, int y);
01249 extern int fn_aux_terrain_at(int x, int y);
01250 extern int fn_feature_at(int x, int y);
01251 extern int fn_elevation_at(int x, int y);
01252 extern int fn_people_side_at(int x, int y);
01253 extern int fn_control_side_at(int x, int y);
01254 extern int fn_material_at(int x, int y);
01255 extern int fn_temperature_at(int x, int y);
01256 extern int fn_raw_cloud_at(int x, int y);
01257 extern int fn_raw_cloud_bottom_at(int x, int y);
01258 extern int fn_raw_cloud_height_at(int x, int y);
01259 extern int fn_raw_wind_at(int x, int y);
01260 extern void allocate_area_users(void);
01261 extern int fn_user_at(int x, int y);
01262 extern void fn_set_user_at(int x, int y, int val);
01263 extern void fn_set_terrain_at(int x, int y, int val);
01264 extern void fn_set_aux_terrain_at(int x, int y, int val);
01265 extern void fn_set_people_side_at(int x, int y, int val);
01266 extern void fn_set_control_side_at(int x, int y, int val);
01267 extern void fn_set_raw_feature_at(int x, int y, int val);
01268 extern void fn_set_elevation_at(int x, int y, int val);
01269 extern void fn_set_material_at(int x, int y, int val);
01270 extern void fn_set_temperature_at(int x, int y, int val);
01271 extern void fn_set_raw_wind_at(int x, int y, int val);
01272 extern void fn_set_raw_cloud_at(int x, int y, int val);
01273 extern void fn_set_raw_cloud_bottom_at(int x, int y, int val);
01274 extern void fn_set_raw_cloud_height_at(int x, int y, int val);
01275
01276 extern void change_terrain_type(int x, int y, int t2);
01277
01278 extern int limited_search_around(int x0, int y0, int range,
01279 int (*pred)(int, int, int *, ParamBox *),
01280 int incr, int *counter,
01281 int rsltlimit, ParamBox *parambox);
01282 extern int search_around(int x0, int y0, int range,
01283 int (*pred)(int, int, int *, ParamBox *),
01284 int incr, ParamBox *parambox);
01285 extern int search_around(int x0, int y0, int maxdist, int (*pred)(int, int),
01286 int *rxp, int *ryp, int incr);
01287 extern int limited_search_around(int x0, int y0, int maxdist,
01288 int (*pred)(int, int, int *), int *rxp,
01289 int *ryp, int incr, int rsltlimit);
01290 extern int search_and_apply(int x0, int y0, int maxdist, int (*pred)(int, int),
01291 int *rxp, int *ryp, int incr,
01292 void (*fn)(int, int), int num);
01293 extern void apply_to_area(int x0, int y0, int dist, void (*fn)(int, int));
01294 extern void apply_to_area_plus_edge(int x0, int y0, int dist,
01295 void (*fn)(int, int));
01296 extern void apply_to_ring(int x0, int y0, int distmin, int distmax,
01297 void (*fn)(int, int));
01298 extern void apply_to_hexagon(int x0, int y0, int w2, int h2,
01299 void (*fn)(int, int));
01300 extern int limited_search_under_arc(int x, int y, int dir, int range,
01301 int dirbias,
01302 int (*pred)(int x, int y, int *counter,
01303 ParamBox *parambox),
01304 int *counter, int rsltlimit,
01305 ParamBox *parambox);
01306 extern int search_under_arc(int x, int y, int dir, int range, int dirbias,
01307 int (*pred)(int x, int y, int *counter,
01308 ParamBox *parambox),
01309 ParamBox *parambox);
01310 extern void apply_to_path(int fx, int fy, int tx, int ty,
01311 int (*dirtest)(int x, int y, int dir),
01312 int (*dirsort)(int x, int y, int *dirchoices,
01313 int numchoices),
01314 int (*fn)(int x, int y, int dir, int j,
01315 int numchoices),
01316 int shortest);
01317 #if 0
01318 int find_path(int fx, int fy, int tx, int ty,
01319 int (*chooser)(int, int, int, int, int *),
01320 int maxwps, Waypoint *waypoints, int *numwpsp);
01321 #endif
01322 extern int search_straight_line(int x0, int y0, int x1, int y1,
01323 int (*pred)(int, int), int *rxp, int *ryp);
01324
01325 extern void set_border_at(int x, int y, int dir, int t, int onoff);
01326 extern void set_connection_at(int x, int y, int dir, int t, int onoff);
01327 extern void patch_linear_terrain(int t);
01328
01329 extern void init_features(void);
01330 extern Feature *find_feature(int fid);
01331 extern Feature *feature_at(int x, int y);
01332 extern void compute_all_feature_centroids(void);
01333 extern void compute_feature_centroid(Feature *feature);
01334
01335 extern int point_in_dir(int x, int y, int dir, int *xp, int *yp);
01336 extern int interior_point_in_dir(int x, int y, int dir, int *xp, int *yp);
01337 extern int point_in_dir_n(int x, int y, int dir, int n, int *xp, int *yp);
01338 extern int interior_point_in_dir_n(int x, int y, int dir, int n,
01339 int *xp, int *yp);
01340 extern int random_point(int *xp, int *yp);
01341 extern int random_edge_point(int *xp, int *yp);
01342 extern int random_point_near(int cx, int cy, int radius, int *xp, int *yp);
01343 extern int random_point_in_area(int cx, int cy, int rx, int ry,
01344 int *xp, int *yp);
01345 extern void terrain_subtype_warning(char *context, int t);
01346 extern int approx_dir(int dx, int dy);
01347 extern int hextant(int dx, int dy);
01348 extern int distance(int x1, int y1, int x2, int y2);
01349 extern int world_distance(int x1, int y1, int x2, int y2);
01350 extern int closest_dir(int x, int y);
01351
01352 extern void xy_to_latlong(int x, int y, int xf, int yf, int *latp, int *lonp);
01353 extern int latlong_to_xy(int lat, int lon, int *xp, int *yp,
01354 int *xfp, int *yfp);
01355 extern int num_people_at(int x, int y);