forked from jamespetts/simutrans-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baum.h
124 lines (90 loc) · 2.97 KB
/
baum.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* This file is part of the Simutrans-Extended project under the Artistic License.
* (see LICENSE.txt)
*/
#ifndef OBJ_BAUM_H
#define OBJ_BAUM_H
#include "simobj.h"
#include "../bauer/tree_builder.h"
#include "../tpl/stringhashtable_tpl.h"
#include "../tpl/vector_tpl.h"
#include "../tpl/weighted_vector_tpl.h"
#include "../descriptor/tree_desc.h"
#include "../simcolor.h"
#include "../dataobj/environment.h"
#include <string>
/**
* Simulated trees for Simutrans.
*/
class baum_t : public obj_t
{
friend class tree_builder_t;
public:
static const uint16 AGE_LIMIT = 704; // in months (58 years 8 months)
static const uint16 SPAWN_PERIOD_START = 512;
static const uint16 SPAWN_PERIOD_LENGTH = 4;
private:
static FLAGGED_PIXVAL outline_color;
/// month of birth
uint16 geburt;
/// type of tree (was 9 but for more compact saves now only 254 different tree types are allowed)
uint8 tree_id;
uint8 season:3;
/// z-offset, max TILE_HEIGHT_STEP ie 4 bits
uint8 zoff:4;
// one bit free ;)
public:
/// Only the load save constructor should be called outside.
/// Otherwise I suggest use the plant tree function (@see tree_builder_t)
baum_t(loadsave_t *file);
baum_t(koord3d pos);
baum_t(koord3d pos, uint8 type, sint32 age, uint8 slope);
baum_t(koord3d pos, const tree_desc_t *desc);
public:
/// @copydoc obj_t::get_name
const char *get_name() const OVERRIDE { return "Baum"; }
#ifndef INLINE_OBJ_TYPE
/// @copydoc obj_t::get_typ
typ get_typ() const OVERRIDE { return baum; }
#endif
/// @copydoc obj_t::rdwr
/// @deprecated Only used for loading old saves that did save tree offsets
void rdwr(loadsave_t *file) OVERRIDE;
/// @copydoc obj_t::finish_rd
void finish_rd() OVERRIDE;
/// @copydoc obj_t::get_image
image_id get_image() const OVERRIDE;
/// @copydoc obj_t::get_outline_image
image_id get_outline_image() const OVERRIDE;
/// @copydoc obj_t::calc_image
/// Calculates tree image dependent on tree age
void calc_image() OVERRIDE;
/// @copydoc obj_t::get_outline_colour
/// hide trees eventually with transparency
FLAGGED_PIXVAL get_outline_colour() const OVERRIDE;
static void recalc_outline_color();
/// @copydoc obj_t::check_season
bool check_season(const bool) OVERRIDE;
/// @copydoc obj_t::rotate90
void rotate90() OVERRIDE;
/// re-calculate z-offset if slope of the tile has changed
void recalc_off();
/// @copydoc obj_t::show_info
void show_info() OVERRIDE;
/// @copydoc obj-t::info
/// @copydoc obj_t::cleanup
void cleanup(player_t *player) OVERRIDE;
public:
const tree_desc_t *get_desc() const { return tree_builder_t::get_desc_by_id(tree_id); }
void set_desc(const tree_desc_t *desc) { tree_id = tree_builder_t::get_id_by_desc(desc); }
uint16 get_desc_id() const { return tree_id; }
/// @returns the age of the tree, in months.
uint32 get_age() const;
public:
void *operator new(size_t s);
void operator delete(void *p);
private:
/// calculate offsets for new trees
void calc_off(uint8 slope, sint8 x=-128, sint8 y=-128);
};
#endif