File: OTOWNRES.h

package info (click to toggle)
7kaa 2.15.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 131,312 kB
  • sloc: cpp: 134,790; asm: 3,523; ansic: 1,949; perl: 1,665; makefile: 1,181; sh: 126; pascal: 27
file content (172 lines) | stat: -rw-r--r-- 4,360 bytes parent folder | download | duplicates (6)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Seven Kingdoms: Ancient Adversaries
 *
 * Copyright 1997,1998 Enlight Software Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

//Filename    : OTOWNRES.H
//Description : Town town resource

#ifndef __OTOWNRES_H
#define __OTOWNRES_H

#ifndef __ALL_H
#include <ALL.h>
#endif

#ifndef __ORESDB_H
#include <ORESDB.h>
#endif

#ifndef __OTOWNREC_H
#include <OTOWNREC.h>
#endif

//--------- define game constants --------//

#define MAX_TOWN_LAYOUT_SLOT           25
#define POPULATION_PER_HOUSE            6     // no. of people per building

#define EFFECTIVE_TOWN_TOWN_DISTANCE   8     // The minimum distance between 2 towns
#define EFFECTIVE_FIRM_TOWN_DISTANCE   8     // maximum distance between the town and the base until it's no longer considered as command base of the town
#define EFFECTIVE_FIRM_FIRM_DISTANCE   8     // maximum distance between the town and the base until it's no longer considered as command base of the town
#define EFFECTIVE_POWER_DISTANCE       3

// population range of each building levels:
// level 1 building: 1-3, level 2 building: 4-6, level 3 building: 7-9

//------- values of TownSlot::build_type -------//

enum { TOWN_OBJECT_HOUSE=1,
		 TOWN_OBJECT_PLANT,
		 TOWN_OBJECT_FARM,
		 TOWN_OBJECT_FLAG,
	  };

//------ define struct TownLayout --------//

struct TownLayout
{
	char  build_count;      // no. of building in this layout

	short first_slot_recno;
	char  slot_count;

	char* ground_bitmap_ptr;
};

//------ define struct TownSlot --------//

struct TownSlot
{
	short base_x, base_y;
	char  build_type;       // id. of the building type
	char  build_code;       // building direction
};

//------ define struct TownBuildType --------//

struct TownBuildType
{
	short first_build_recno;
	int   build_count;
};

//------ define struct TownName --------//

struct TownName
{
	enum { NAME_LEN=15 };
	char name[NAME_LEN+1];
};

//------ define struct TownBuild --------//

struct TownBuild
{
public:
   char  build_type;          // building type. e.g. house, wind mill, church

	char  race_id;
	char  build_code;

	char* bitmap_ptr;
	short bitmap_width;
	short bitmap_height;

public:
	void draw(int townRecno, int absBaseX, int absBaseY);
};

//--------- Define class TownRes ----------//

class TownRes
{
public:
	char  init_flag;
	int   town_layout_count, town_slot_count;
	int   town_build_type_count, town_build_count, town_name_count;

	TownLayout*    town_layout_array;
	TownSlot*      town_slot_array;
	TownBuildType* town_build_type_array;
	TownBuild*     town_build_array;
	TownName*      town_name_array;
	unsigned char* town_name_used_array;	// store the used_count separately from town_name_array to faciliate file saving

	ResourceDb     res_bitmap;

public:
   TownRes();

   void init();
   void deinit();

	int   scan_build(int slotId, int raceId);

	char*	get_name(int recNo);
	int	get_new_name_id(int raceId);
	void	free_name_id(int townNameId);

	int   write_file(File*);
	int   read_file(File*);

	#ifdef DEBUG
		TownLayout*    get_layout(int recNo);
		TownSlot*      get_slot(int recNo);
		TownBuildType* get_build_type(int recNo);
		TownBuild*     get_build(int recNo);
	#else
		TownLayout*    get_layout(int recNo)      { return town_layout_array    +recNo-1; };
		TownSlot*      get_slot(int recNo)        { return town_slot_array      +recNo-1; };
      TownBuildType* get_build_type(int recNo)  { return town_build_type_array+recNo-1; };
      TownBuild*     get_build(int recNo)       { return town_build_array     +recNo-1; };
   #endif

private:
   void load_town_layout();
   void load_town_slot();
   void load_town_build_type();
   void load_town_build();
   void load_town_name();
};

extern TownRes town_res;

//------------------------------------------//

#endif