Freeciv-3.4
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 < MAP_NATIVE_WIDTH; i++) {
46 idx = ycoor * MAP_NATIVE_WIDTH + i;
47
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 != nullptr;
80}
81
82/**********************************************************************/
85bool tmap_is(const struct tile *ptile, temperature_type tt)
86{
87 return BOOL_VAL(tmap(ptile) & (tt));
88}
89
90/**********************************************************************/
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{
109 fc_assert_ret(temperature_map != nullptr);
110
112 temperature_map = nullptr;
113}
114
115/**********************************************************************/
121{
122 int i;
123
124 /* If map is defined this is not changed. */
125 /* TODO: Load if from scenario game with tmap */
126 /* to debug, never load at this time */
127 fc_assert_ret(temperature_map == nullptr);
128
130 whole_map_iterate(&(wld.map), ptile) {
131 /* The base temperature is equal to base map_colatitude */
132 int t = map_colatitude(ptile);
133
134 if (!real) {
135 tmap(ptile) = t;
136 } else {
137 /* High land can be 30% cooler */
138 float height = - 0.3 * MAX(0, hmap(ptile) - hmap_shore_level)
141 /* Near ocean temperature can be 15% more "temperate" */
142 float temperate = (0.15 * (wld.map.server.temperature / 100 - t
144 * 2 * MIN(50, tcn)
145 / 100);
146
147 tmap(ptile) = t * (1.0 + temperate) * (1.0 + height);
148 }
150
151 /* Adjust to get evenly distributed frequencies.
152 * Only call adjust when the colatitude range is large enough for this to
153 * make sense - if most variation comes from height and coast, don't try
154 * to squish that back into its original narrow range */
158 }
159
160 /* Now simplify to 4 base values */
161 for (i = 0; i < MAP_INDEX_SIZE; i++) {
162 int t = temperature_map[i];
163
164 if (t >= TROPICAL_LEVEL) {
166 } else if (t >= COLD_LEVEL) {
168 } else if (t >= 2 * ICE_BASE_LEVEL) {
170 } else {
172 }
173 }
174
175 log_debug("%stemperature map ({f}rozen, {c}old, {m}edium, {t}ropical):",
176 real ? "real " : "");
177 for (i = 0; i < MAP_NATIVE_HEIGHT; i++) {
178 log_debug("%5d: %s", i, tmap_y2str(i));
179 }
180}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
char * incite_cost
Definition comments.c:77
int hmap_shore_level
Definition height_map.c:30
struct world wld
Definition game.c:63
#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:192
#define log_debug(message,...)
Definition log.h:116
#define MAP_MAX_LINEAR_SIZE
Definition map.h:677
#define adjc_iterate_end
Definition map.h:439
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:434
#define whole_map_iterate(_map, _tile)
Definition map.h:582
#define whole_map_iterate_end
Definition map.h:591
int map_colatitude(const struct tile *ptile)
#define REAL_COLATITUDE_RANGE(_nmap)
#define MIN_REAL_COLATITUDE(_nmap)
#define COLD_LEVEL
#define MAX_REAL_COLATITUDE(_nmap)
#define ICE_BASE_LEVEL
#define TROPICAL_LEVEL
#define MAX_COLATITUDE
#define adjust_int_map(int_map, int_map_min, 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
struct civ_map::@44::@46 server
int temperature
Definition map_types.h:116
Definition tile.h:50
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:636
#define MAP_NATIVE_WIDTH
#define MAP_INDEX_SIZE
#define MAP_NATIVE_HEIGHT