00001
00002
00003
00004
00005 #include <OSYS.H>
00006 #include <OVGA.H>
00007 #include <OGAMESET.H>
00008 #include <OWORLD.H>
00009 #include <OTERRAIN.H>
00010 #include <OINFO.H>
00011 #include <OPLANT.H>
00012 #include <OCONFIG.H>
00013 #include <OWORLDMT.H>
00014 #include <OCOLTBL.H>
00015 #include <OBITMAP.H>
00016
00017
00018
00019
00020
00021
00022
00023
00024 PlantRes::PlantRes() {
00025 init_flag=0;
00026 }
00027
00028
00029
00030
00034
00035 deinit();
00036
00037
00038
00039 String str;
00040
00041 str = DIR_RES;
00042
00043 str += "I_PLANT";
00044 str += config.terrain_set;
00045 str += ".RES";
00046
00047 res_bitmap.init_imported(str,1);
00048
00049
00050
00051 load_plant_info();
00052 load_plant_bitmap();
00053
00054
00055 plant_map_color = (char) V_DARK_GREEN;
00056
00057
00058 init_flag=1;
00059 }
00060
00061
00062
00063
00064
00065 void PlantRes::deinit() {
00066 if( init_flag ) {
00067 mem_del(plant_info_array);
00068 mem_del(plant_bitmap_array);
00069 mem_del(scan_id_array);
00070 init_flag=0;
00071 }
00072 }
00073
00074
00075
00076
00078
00079 PlantRec *plantRec;
00080 PlantInfo *plantInfo;
00081 int i;
00082
00083
00084
00085 String plantDbName;
00086 plantDbName = DIR_RES;
00087 plantDbName += "PLANT";
00088 plantDbName += config.terrain_set;
00089 plantDbName += ".RES";
00090 Database plantDbObj(plantDbName, 1);
00091
00092 Database *dbPlant = &plantDbObj;
00093
00094 plant_count = (short) dbPlant->rec_count();
00095 plant_info_array = (PlantInfo*) mem_add( sizeof(PlantInfo)*plant_count );
00096
00097 memset( plant_info_array, 0, sizeof(PlantInfo) * plant_count );
00098
00099
00100
00101 for( i=0 ; i<plant_count ; i++ ) {
00102 plantRec = (PlantRec*) dbPlant->read(i+1);
00103 plantInfo = plant_info_array+i;
00104
00105 m.rtrim_fld( plantInfo->code, plantRec->code, plantRec->CODE_LEN );
00106 plantInfo->climate_zone = m.atoi( plantRec->climate_zone, plantRec->ZONE_LEN );
00107
00108 if( plantRec->tera_type1[0] == 'T' ) {
00109 plantInfo->tera_type[0] = 'T';
00110 }
00111 else {
00112 if(plantRec->tera_type1[0] != ' ')
00113 plantInfo->tera_type[0] = terrain_res.get_tera_type_id( plantRec->tera_type1 );
00114 else
00115 plantInfo->tera_type[0] = 0;
00116 }
00117
00118 if( plantRec->tera_type2[0] == 'T' ) {
00119 plantInfo->tera_type[1] = 'T';
00120 }
00121 else {
00122 if(plantRec->tera_type2[0] != ' ')
00123 plantInfo->tera_type[1] = terrain_res.get_tera_type_id( plantRec->tera_type2 );
00124 else
00125 plantInfo->tera_type[1] = 0;
00126 }
00127
00128 if( plantRec->tera_type3[0] == 'T' ) {
00129 plantInfo->tera_type[2] = 'T';
00130 }
00131 else {
00132 if(plantRec->tera_type3[0] != ' ')
00133 plantInfo->tera_type[2] = terrain_res.get_tera_type_id( plantRec->tera_type3 );
00134 else
00135 plantInfo->tera_type[2] = 0;
00136 }
00137
00138 plantInfo->first_bitmap = m.atoi( plantRec->first_bitmap, plantRec->FIRST_BITMAP_LEN );
00139 plantInfo->bitmap_count = m.atoi( plantRec->bitmap_count, plantRec->BITMAP_COUNT_LEN );
00140 }
00141 }
00142
00143
00144
00145
00147
00148 PlantBitmapRec *plantBitmapRec;
00149 PlantBitmap *plantBitmap;
00150 int i;
00151 long bitmapOffset;
00152
00153 String plantDbName;
00154 plantDbName = DIR_RES;
00155 plantDbName += "PLANTBM";
00156 plantDbName += config.terrain_set;
00157 plantDbName += ".RES";
00158 Database plantDbObj(plantDbName, 1);
00159
00160 Database *dbPlantBitmap = &plantDbObj;
00161
00162 plant_bitmap_count = (short) dbPlantBitmap->rec_count();
00163 plant_bitmap_array = (PlantBitmap*) mem_add( sizeof(PlantBitmap)*plant_bitmap_count );
00164
00165 scan_id_array = (short*) mem_add( sizeof(short)*plant_bitmap_count );
00166
00167
00168
00169 memset( plant_bitmap_array, 0, sizeof(PlantBitmap) * plant_bitmap_count );
00170
00171 for( i=0 ; i<plant_bitmap_count ; i++ ) {
00172 plantBitmapRec = (PlantBitmapRec*) dbPlantBitmap->read(i+1);
00173 plantBitmap = plant_bitmap_array+i;
00174
00175 plantBitmap->size = m.atoi( plantBitmapRec->size, plantBitmapRec->SIZE_LEN );
00176
00177 memcpy( &bitmapOffset, plantBitmapRec->bitmap_ptr, sizeof(long) );
00178
00179 plantBitmap->bitmap_ptr = res_bitmap.read_imported(bitmapOffset);
00180 plantBitmap->bitmap_width = *((short*)plantBitmap->bitmap_ptr);
00181 plantBitmap->bitmap_height = *(((short*)plantBitmap->bitmap_ptr)+1);
00182
00183 plantBitmap->offset_x = m.atoi( plantBitmapRec->offset_x, plantBitmapRec->OFFSET_LEN );
00184 plantBitmap->offset_y = m.atoi( plantBitmapRec->offset_y, plantBitmapRec->OFFSET_LEN );
00185
00186
00187 plantBitmap->offset_x += -LOCATE_WIDTH/2 - (-ZOOM_LOC_X_WIDTH/2 + -ZOOM_LOC_Y_WIDTH/2);
00188 plantBitmap->offset_y += -LOCATE_HEIGHT/2 - (-ZOOM_LOC_X_HEIGHT/2 + -ZOOM_LOC_Y_HEIGHT/2);
00189
00190 if( plantBitmapRec->town_age >= '1' && plantBitmapRec->town_age <= '9' )
00191 plantBitmap->town_age = plantBitmapRec->town_age-'0';
00192 }
00193 }
00194
00195
00196
00197
00212
00213 int i, j;
00214 int matchCount=0;
00215 PlantInfo* plantInfo = plant_info_array;
00216 PlantBitmap* plantBitmap = plant_bitmap_array + plantInfo->first_bitmap - 1;
00217
00218
00219
00220 for( i=0 ; i<plant_count ; i++, plantInfo++ ) {
00221 if( !climateZone || (plantInfo->climate_zone & climateZone) ) {
00222 if( !teraType ||
00223 plantInfo->tera_type[0] == teraType ||
00224 plantInfo->tera_type[1] == teraType ||
00225 plantInfo->tera_type[2] == teraType ) {
00226
00227 plantBitmap = plant_bitmap_array + plantInfo->first_bitmap - 1;
00228 for( j=0 ; j<plantInfo->bitmap_count ; j++, plantBitmap++ ) {
00229
00230 if( !townAge || plantBitmap->town_age == townAge || plantBitmap->town_age=='*' ) {
00231 scan_id_array[matchCount++] = plantInfo->first_bitmap + j;
00232
00233 err_when( matchCount > plant_bitmap_count );
00234 }
00235 }
00236 }
00237 }
00238 }
00239
00240
00241
00242 if( matchCount > 0 ) {
00243 int plantBitmapId = scan_id_array[m.random(matchCount)];
00244
00245 err_when( plantBitmapId < 1 || plantBitmapId > plant_bitmap_count );
00246
00247 return plantBitmapId;
00248 }
00249 else
00250 return 0;
00251 }
00252
00253
00254
00255
00256
00257 short PlantRes::plant_recno(short bitmapId) {
00258 int i;
00259 PlantInfo *plantInfo = plant_info_array;
00260 for( i = 0; i<plant_count; ++i, plantInfo++ )
00261 if( plantInfo->first_bitmap <= bitmapId &&
00262 bitmapId < plantInfo->first_bitmap+ plantInfo->bitmap_count)
00263 return i+1;
00264 return 0;
00265 }
00266
00267
00268
00269 #ifdef DEBUG
00270
00271
00272
00273 PlantInfo* PlantRes::operator[](int plantId) {
00274 err_if( plantId<1 || plantId>plant_count )
00275 err_now( "PlantRes::operator[]" );
00276
00277 return plant_info_array+plantId-1;
00278 }
00279
00280
00281
00282
00283
00284 PlantBitmap* PlantRes::get_bitmap(int bitmapId) {
00285 err_if( bitmapId<1 || bitmapId>plant_bitmap_count )
00286 err_now( "PlantRes::get_bitmap" );
00287
00288 return plant_bitmap_array+bitmapId-1;
00289 }
00290
00291
00292 #endif
00293
00294
00298
00299
00300
00301 Location* locPtr = world.get_loc(xLoc, yLoc);
00302
00303 int innerX = locPtr->plant_inner_x();
00304 int innerY = locPtr->plant_inner_y();
00305
00306 world.zoom_matrix->put_bitmap_offset(xLoc*LOCATE_WIDTH+innerX, yLoc*LOCATE_HEIGHT+innerX,
00307 world.interpolate_z(xLoc*LOCATE_WIDTH+innerX, yLoc*LOCATE_HEIGHT+innerY), bitmap_ptr,
00308 offset_x, offset_y,
00309 NULL, 0, 1);
00310 }
00311
00312
00313
00314
00323
00324 short *remapTable;
00325
00326 remapTable = (short *)vga.vga_color_table->get_table( constructionCompletionPercent * 20 / 100 - 20 );
00327
00328 short bitmapWidth = ((Bitmap *)bitmap_ptr)->get_width();
00329 short bitmapHeight = ((Bitmap *)bitmap_ptr)->get_height();
00330
00331 world.zoom_matrix->put_bitmap_offset(curX, curY, curZ, bitmap_ptr,
00332 -bitmapWidth/2, -bitmapHeight+15,
00333 remapTable, 0, 1);
00334 }
00335
00336