Freeciv-3.3
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 != 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/**********************************************************************/
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/**********************************************************************/
113
114/**********************************************************************/
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)
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
150 /* Adjust to get evenly distributed frequencies.
151 * Only call adjust when the colatitude range is large enough for this to
152 * make sense - if most variation comes from height and coast, don't try
153 * to squish that back into its original narrow range */
157 }
158
159 /* Now simplify to 4 base values */
160 for (i = 0; i < MAP_INDEX_SIZE; i++) {
161 int t = temperature_map[i];
162
163 if (t >= TROPICAL_LEVEL) {
165 } else if (t >= COLD_LEVEL) {
167 } else if (t >= 2 * ICE_BASE_LEVEL) {
169 } else {
171 }
172 }
173
174 log_debug("%stemperature map ({f}rozen, {c}old, {m}edium, {t}ropical):",
175 real ? "real " : "");
176 for (i = 0; i < MAP_NATIVE_HEIGHT; i++) {
177 log_debug("%5d: %s", i, tmap_y2str(i));
178 }
179}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
char * incite_cost
Definition comments.c:76
int hmap_shore_level
Definition height_map.c:30
struct world wld
Definition game.c:62
#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:668
#define adjc_iterate_end
Definition map.h:430
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:425
#define whole_map_iterate(_map, _tile)
Definition map.h:573
#define whole_map_iterate_end
Definition map.h:582
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:633
#define MAP_NATIVE_WIDTH
#define MAP_INDEX_SIZE
#define MAP_NATIVE_HEIGHT