/
Oplant.cpp
136 lines (95 loc) · 3.13 KB
/
Oplant.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
//Filename : OPLANT.CPP
//Description : PlantRes Class Definition
#include <All.h>
#include <OVGA.H>
#include <OSYS.H>
#include <OSTR.h>
#include <OMISC.h>
#include <OGAMESET.H>
#include <OPLANT.h>
//----------- Define constants -------------//
#define PLANT_DB "PLANT"
//----------- Begin of function PlantRes Constructor -----//
//!
PlantRes::PlantRes() {
init_flag=0;
}
//------------- End of function PlantRes Constructor -----//
//----------- Begin of function PlantRes Destructor ------//
//!
PlantRes::~PlantRes() {
deinit();
}
//------------- End of function PlantRes Destructor ------//
//----------- Begin of function PlantRes::init --------//
//!
void PlantRes::init() {
if ( init_flag )
return;
//----- read info from PLANT.DBF ------//
load_info();
//---- open bitmap resource of different resolutions ----//
load_res( ZOOM_SMALL , "PLANT", "S" );
load_res( ZOOM_MEDIUM, "PLANT", "M" );
load_res( ZOOM_LARGE , "PLANT", "L" );
//----------------------------------------//
init_flag=1;
}
//------------- End of function PlantRes::init --------//
//----------- Begin of function PlantRes::deinit --------//
//!
void PlantRes::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 PlantRes::deinit --------//
//----------- Begin of function PlantRes::load_info -------//
//!
//! Read in information of PLANT.DBF into memory array
//!
void PlantRes::load_info() {
PlantRec *plantRec;
PlantInfo *plantInfo;
int i;
Database *dbPlant = game_set.open_db(PLANT_DB);
plant_count = (short) dbPlant->rec_count();
info_array = (PlantInfo*) mem_add( sizeof(PlantInfo)*plant_count );
//------ read in plant bitmap info array -------//
memset( info_array, 0, sizeof(PlantInfo) * plant_count );
for( i=0 ; i<plant_count ; i++ ) {
plantRec = (PlantRec*) dbPlant->read(i+1);
plantInfo = info_array+i;
m.rtrim_fld( plantInfo->file_name, plantRec->file_name, plantRec->FILE_NAME_LEN );
}
}
//----------- End of function PlantRes::load_info -------//
//----------- Begin of function PlantRes::load_res --------//
//!
void PlantRes::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 PlantInfo::bitmap_ptr[] --------//
char* bmpPtr;
for( int i=0 ; i<plant_count ; i++ ) {
bmpPtr = res_bitmap[zoomLevel].read( info_array[i].file_name );
info_array[i].bitmap_ptr[zoomLevel] = bmpPtr;
}
}
//------------- End of function PlantRes::load_res --------//
//---------- Begin of function PlantRes::operator[] -----------//
PlantInfo* PlantRes::operator[](int plantId) {
err_if( plantId<1 || plantId>plant_count )
err_now( "PlantRes::operator[]" );
return info_array+plantId-1;
}
//------------ End of function PlantRes::operator[] -----------//