Freeciv-3.1
Loading...
Searching...
No Matches
temperature_map.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2004 - Marcelo J. Burda
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utilities */
19#include "log.h"
20
21/* common */
22#include "map.h"
23
24/* generator */
25#include "height_map.h"
26#include "mapgen_topology.h"
27#include "mapgen_utils.h"
28
29#include "temperature_map.h"
30
31static int *temperature_map;
32
33#define tmap(_tile) (temperature_map[tile_index(_tile)])
34
35/**********************************************************************/
38#ifdef FREECIV_DEBUG
39static char *tmap_y2str(int ycoor)
40{
41 static char buf[MAP_MAX_LINEAR_SIZE + 1];
42 char *p = buf;
43 int i, idx;
44
45 for (i = 0; i < wld.map.xsize; i++) {
46 idx = ycoor * wld.map.xsize + i;
47
48 if (idx > wld.map.xsize * wld.map.ysize) {
49 break;
50 }
51
52 switch (temperature_map[idx]) {
53 case TT_TROPICAL:
54 *p++ = 't'; /* tropical */
55 break;
56 case TT_TEMPERATE:
57 *p++ = 'm'; /* medium */
58 break;
59 case TT_COLD:
60 *p++ = 'c'; /* cold */
61 break;
62 case TT_FROZEN:
63 *p++ = 'f'; /* frozen */
64 break;
65 }
66 }
67
68 *p = '\0';
69
70 return buf;
71}
72#endif /* FREECIV_DEBUG */
73
74/**********************************************************************/
78{
79 return temperature_map != NULL;
80}
81
82/**********************************************************************/
85bool tmap_is(const struct tile *ptile, temperature_type tt)
86{
87 return BOOL_VAL(tmap(ptile) & (tt));
88}
89
90/**********************************************************************/
93bool is_temperature_type_near(const struct tile *ptile, temperature_type tt)
94{
95 adjc_iterate(&(wld.map), ptile, tile1) {
96 if (BOOL_VAL(tmap(tile1) & (tt))) {
97 return TRUE;
98 };
100
101 return FALSE;
102}
103
104/**********************************************************************/
107void destroy_tmap(void)
108{
110 free(temperature_map);
111 temperature_map = NULL;
112}
113
114/**********************************************************************/
119void create_tmap(bool real)
120{
121 int i;
122
123 /* if map is defined this is not changed */
124 /* TODO: load if from scenario game with tmap */
125 /* to debug, never load at this time */
127
129 whole_map_iterate(&(wld.map), ptile) {
130 /* the base temperature is equal to base map_colatitude */
131 int t = map_colatitude(ptile);
132
133 if (!real) {
134 tmap(ptile) = t;
135 } else {
136 /* high land can be 30% cooler */
137 float height = - 0.3 * MAX(0, hmap(ptile) - hmap_shore_level)
139 int tcn = count_terrain_class_near_tile(&(wld.map), ptile, FALSE, TRUE, TC_OCEAN);
140 /* near ocean temperature can be 15% more "temperate" */
141 float temperate = (0.15 * (wld.map.server.temperature / 100 - t
143 * 2 * MIN(50, tcn)
144 / 100);
145
146 tmap(ptile) = t * (1.0 + temperate) * (1.0 + height);
147 }
149 /* adjust to get well sizes frequencies */
150 /* Notice: if colatitude is loaded from a scenario never call adjust.
151 Scenario may have an odd colatitude distribution and adjust will
152 break it */
153 if (!wld.map.server.alltemperate) {
155 }
156 /* now simplify to 4 base values */
157 for (i = 0; i < MAP_INDEX_SIZE; i++) {
158 int t = temperature_map[i];
159
160 if (t >= TROPICAL_LEVEL) {
162 } else if (t >= COLD_LEVEL) {
164 } else if (t >= 2 * ICE_BASE_LEVEL) {
166 } else {
168 }
169 }
170
171 log_debug("%stemperature map ({f}rozen, {c}old, {m}edium, {t}ropical):",
172 real ? "real " : "");
173 for (i = 0; i < wld.map.ysize; i++) {
174 log_debug("%5d: %s", i, tmap_y2str(i));
175 }
176}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
int hmap_shore_level
Definition height_map.c:30
struct world wld
Definition game.c:58
#define hmap_max_level
Definition height_map.h:33
#define hmap(_tile)
Definition height_map.h:17
#define fc_assert_ret(condition)
Definition log.h:191
#define log_debug(message,...)
Definition log.h:115
#define MAP_MAX_LINEAR_SIZE
Definition map.h:606
#define adjc_iterate_end
Definition map.h:427
#define MAP_INDEX_SIZE
Definition map.h:131
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:422
#define whole_map_iterate(_map, _tile)
Definition map.h:539
#define whole_map_iterate_end
Definition map.h:548
int map_colatitude(const struct tile *ptile)
#define COLD_LEVEL
#define ICE_BASE_LEVEL
#define TROPICAL_LEVEL
#define MAX_COLATITUDE
#define adjust_int_map(int_map, int_map_max)
#define fc_malloc(sz)
Definition mem.h:34
#define MIN(x, y)
Definition shared.h:55
#define BOOL_VAL(x)
Definition shared.h:70
#define MAX(x, y)
Definition shared.h:54
int xsize
Definition map_types.h:77
int ysize
Definition map_types.h:77
bool alltemperate
Definition map_types.h:101
struct civ_map::@41::@43 server
int temperature
Definition map_types.h:102
Definition tile.h:49
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool temperature_is_initialized(void)
void destroy_tmap(void)
#define tmap(_tile)
bool tmap_is(const struct tile *ptile, temperature_type tt)
static int * temperature_map
bool is_temperature_type_near(const struct tile *ptile, temperature_type tt)
void create_tmap(bool real)
int temperature_type
#define TT_COLD
#define TT_FROZEN
#define TT_TROPICAL
#define TT_TEMPERATE
int count_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_class tclass)
Definition terrain.c:621