void World::plant_death(int scanDensity, int scanRadius) { int yBase = misc.random(scanDensity); int xBase = misc.random(scanDensity); for( int y = yBase; y < max_y_loc; y += scanDensity) { for( int x = xBase; x < max_x_loc; x += scanDensity) // for( int y = 0; y < max_y_loc; y ++) // { // for( int x = 0; x < max_x_loc; x ++) { Location *locPtr = get_loc(x,y); // when a plant is found if( locPtr->is_plant() ) { char neighbour =0; char totalSpace =0; // scan the area arounding for( int scanY = y - scanRadius; scanY <= y + scanRadius; scanY ++) { for( int scanX = x - scanRadius; scanX <= x + scanRadius; scanX ++) { if ((scanX >= 0) && (scanY >= 0) && (scanX < max_x_loc) && (scanY < max_y_loc)) { totalSpace++; Location *scanLocPtr = get_loc(scanX,scanY); if( (scanLocPtr)->is_plant() ) neighbour++; } } } // must remove plant if more than one forth of the space is occupied // if( (totalSpace>>2) <= neighbour ) if( neighbour > 2 ) { locPtr = get_loc(x,y); get_loc(x,y)->remove_plant(); if( locPtr->fire_src() > 50) locPtr->set_fire_src(50); plant_count--; } } } } }
//--------- Begin of function Bullet::process_die --------// // // return : <int> 1 - dying animation completes. // 0 - still dying // int Bullet::process_die() { // ------- sound effect --------// se_res.sound(cur_x_loc(), cur_y_loc(), cur_frame, 'S',sprite_id,"DIE"); //--------- next frame ---------// if( ++cur_frame > sprite_info->die.frame_count ) // ####### begin Gilbert 28/6 ########// if( ++cur_frame > sprite_info->die.frame_count ) { // ------- set fire on the target area --------// if( fire_radius > 0) { Location *locPtr; if( fire_radius == 1) { locPtr = world.get_loc(target_x_loc, target_y_loc); if( locPtr->can_set_fire() && locPtr->fire_str() < 30 ) locPtr->set_fire_str(30); if( locPtr->fire_src() > 0 ) locPtr->set_fire_src(1); // such that the fire will be put out quickly } else { short x, y, x1, y1, x2, y2; // ##### begin Gilbert 2/10 ######// x1 = target_x_loc - fire_radius + 1; if( x1 < 0 ) x1 = 0; y1 = target_y_loc - fire_radius + 1; if( y1 < 0 ) y1 = 0; x2 = target_x_loc + fire_radius - 1; if( x2 >= world.max_x_loc ) x2 = world.max_x_loc-1; y2 = target_y_loc + fire_radius - 1; if( y2 >= world.max_y_loc ) y2 = world.max_y_loc-1; // ##### end Gilbert 2/10 ######// for( y = y1; y <= y2; ++y) { locPtr = world.get_loc(x1, y); for( x = x1; x <= x2; ++x, ++locPtr) { // ##### begin Gilbert 30/10 ######// int dist = abs(x-target_x_loc) + abs(y-target_y_loc); if( dist > fire_radius) continue; int fl = 30 - dist * 7; if( fl < 10 ) fl = 10; if( locPtr->can_set_fire() && locPtr->fire_str() < fl ) locPtr->set_fire_str(fl); if( locPtr->fire_src() > 0 ) locPtr->set_fire_src(1); // such that the fire will be put out quickly // ##### begin Gilbert 30/10 ######// } } } } return 1; } // ####### end Gilbert 28/6 ########// return 0; }
//------------ begin of function World::plant_death ---------// // // a plant may death, if it is surrounded by many trees // void World::plant_death(int scanDensity) { int yBase = m.random(scanDensity); int xBase = m.random(scanDensity); for( int y = yBase; y < max_y_loc; y += scanDensity) { for( int x = xBase; x < max_x_loc; x += scanDensity) { Location *locPtr = get_loc(x,y); if( locPtr->is_plant() ) { char neighbour =0; char totalSpace =0; // west if( x > 0) { totalSpace++; if( (locPtr-1)->is_plant() ) neighbour++; } // east if( x < max_x_loc-1) { totalSpace++; if( (locPtr+1)->is_plant() ) neighbour++; } if( y > 0) { locPtr = get_loc(x,y-1); // north square totalSpace++; if( locPtr->is_plant() ) neighbour++; // north west if( x > 0) { totalSpace++; if( (locPtr-1)->is_plant() ) neighbour++; } // north east if( x < max_x_loc-1) { totalSpace++; if( (locPtr+1)->is_plant() ) neighbour++; } } if( y < max_x_loc-1) { locPtr = get_loc(x,y+1); // south square totalSpace++; if( locPtr->is_plant() ) neighbour++; // south west if( x > 0) { totalSpace++; if( (locPtr-1)->is_plant() ) neighbour++; } // south east if( x < max_x_loc-1) { totalSpace++; if( (locPtr+1)->is_plant() ) neighbour++; } } // may remove plant if more than two third of the space is occupied if( m.random(totalSpace) + 2*totalSpace/3 <= neighbour ) { locPtr = get_loc(x,y); get_loc(x,y)->remove_plant(); if( locPtr->fire_src() > 50) locPtr->set_fire_src(50); plant_count--; //### begin alex 24/6 ###// //newl->set_power_off(); //newl->power_nation_recno = 0; //set_surr_power_off(x, y); //#### end alex 24/6 ####// } } } } }