-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oterrain.cpp
142 lines (100 loc) · 3.35 KB
/
Oterrain.cpp
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
//Filename : OTERRAIN.CPP
//Description : TerrainRes Class Definition
#include <All.h>
#include <OVGA.H>
#include <OSYS.H>
#include <OSTR.h>
#include <OMISC.h>
#include <OGAMESET.H>
#include <OTERRAIN.h>
//----------- Define constants -------------//
#define TERRAIN_DB "TERRAIN"
//----------- Begin of function TerrainRes Constructor -----//
//!
TerrainRes::TerrainRes() {
init_flag=0;
}
//------------- End of function TerrainRes Constructor -----//
//----------- Begin of function TerrainRes Destructor ------//
//!
TerrainRes::~TerrainRes() {
deinit();
}
//------------- End of function TerrainRes Destructor ------//
//----------- Begin of function TerrainRes::init --------//
//!
void TerrainRes::init() {
if ( init_flag )
return;
//----- read info from TERRAIN.DBF ------//
load_info();
//---- open bitmap resource of different resolutions ----//
load_res( ZOOM_SMALL , "TERRA", "S" );
load_res( ZOOM_MEDIUM, "TERRA", "M" );
load_res( ZOOM_LARGE , "TERRA", "L" );
//----------------------------------------//
init_flag=1;
}
//------------- End of function TerrainRes::init --------//
//----------- Begin of function TerrainRes::deinit --------//
//!
void TerrainRes::deinit() {
if( init_flag ) {
for( int i=0 ; i<MAX_ZOOM_LEVEL ; i++ )
res_bitmap[i].deinit();
mem_del(info_array);
init_flag=0;
}
}
//------------- End of function TerrainRes::deinit --------//
//----------- Begin of function TerrainRes::load_info -------//
//!
//! Read in information of TERRAIN.DBF into memory array
//!
void TerrainRes::load_info() {
TerrainRec *terrainRec;
TerrainInfo *terrainInfo;
int i;
Database *dbTerrain = game_set.open_db(TERRAIN_DB);
terrain_count = (short) dbTerrain->rec_count();
info_array = (TerrainInfo*) mem_add( sizeof(TerrainInfo)*terrain_count );
//------ read in terrain bitmap info array -------//
memset( info_array, 0, sizeof(TerrainInfo) * terrain_count );
for( i=0 ; i<terrain_count ; i++ ) {
terrainRec = (TerrainRec*) dbTerrain->read(i+1);
terrainInfo = info_array+i;
switch( terrainRec->type[0] ) {
case 'G':
terrainInfo->type = TERRAIN_GRASS;
break;
}
m.rtrim_fld( terrainInfo->file_name, terrainRec->file_name, terrainRec->FILE_NAME_LEN );
}
}
//----------- End of function TerrainRes::load_info -------//
//----------- Begin of function TerrainRes::load_res --------//
//!
void TerrainRes::load_res(int zoomLevel, char* namePrefix, char* nameSuffix) {
//------ read bitmaps into memory -----//
String str2;
str2 = DIR_RES;
str2 += namePrefix;
str2 += "_";
str2 += nameSuffix;
str2 += ".RES";
res_bitmap[zoomLevel].init( str2, 1 ); // 1-read all bitmaps into memory
//-------- set TerrainInfo::bitmap_ptr[] --------//
char* bmpPtr;
for( int i=0 ; i<terrain_count ; i++ ) {
bmpPtr = res_bitmap[zoomLevel].read( info_array[i].file_name );
info_array[i].bitmap_ptr[zoomLevel] = bmpPtr;
}
}
//------------- End of function TerrainRes::load_res --------//
//---------- Begin of function TerrainRes::operator[] -----------//
TerrainInfo* TerrainRes::operator[](int terrainId) {
err_if( terrainId<1 || terrainId>terrain_count )
err_now( "TerrainRes::operator[]" );
return info_array+terrainId-1;
}
//------------ End of function TerrainRes::operator[] -----------//