Esempio n. 1
0
File: ow_plant.cpp Progetto: 7k2/7k2
//----------- Begin of function World::plant_ops -----------//
//
void World::plant_ops()
{
    plant_grow(40);
    plant_reprod(10);
    plant_death();
    plant_spread(50);
}
Esempio n. 2
0
//------------ begin of function World::plant_init ------------//
// randomly select a place and call plant_spray to enlarge the
// forest
//
void World::plant_init()
{
    plant_count = 0;
    int trial;
    for(trial = 50; trial > 0; --trial)
    {
        // ------- randomly select a place to seed plant
        int y = 1+m.random(max_y_loc-2);
        int x = 1+m.random(max_x_loc-2);

        Location *l = get_loc(x,y);
        int build_flag = TRUE;
        char teraType = terrain_res[l->terrain_id]->average_type;

        // ------- all square around are the same terrain type and empty
        for( int y1 = y-1; y1 <= y+1; ++y1)
            for( int x1 = x-1; x1 <= x+1; ++x1)
            {
                l = get_loc(x1,y1);
                // #### begin Gilbert 6/3 #######//
                if( !l->can_add_plant() || terrain_res[l->terrain_id]->average_type != teraType)
                    build_flag = FALSE;
                // #### end Gilbert 6/3 #######//
            }

        if( build_flag )
        {
            short plantBitmap = plant_res.scan( 0, teraType, 0);
            short plantArray[PLANT_ARRAY_SIZE];
            for( int i = 0; i < PLANT_ARRAY_SIZE; ++i)
            {
                plantArray[i] = plant_res.plant_recno(plant_res.scan(0, teraType, 0));
            }
            if( plantArray[0] )
            {
                plant_spray(plantArray, 6+m.random(4), x, y);
            }
        }
    }

    plant_limit = plant_count * 3 / 2;

    // ------- kill some plant ----------//
    for(trial = 8; trial > 0; --trial)
    {
        plant_death(2);
    }
}
Esempio n. 3
0
File: ow_plant.cpp Progetto: 7k2/7k2
//------------ begin of function World::plant_init ------------//
// plantTrial = number of places that randomly selected to plant a forest
// scanRadius = radius of the search area for killing a tree for subroutine plant_death()
//					remove a tree if the area has more than 3 trees
//
void World::plant_init(int plantTrial, int scanRadius)
{
    plant_count = 0;
    for( int trial = plantTrial; trial > 0; --trial )
    {
        // ------- randomly select a place to seed plant
        int y = 1+misc.random(max_y_loc-2);
        int x = 1+misc.random(max_x_loc-2);

        Location *l = get_loc(x,y);
        int build_flag = 1;
        char teraType = terrain_res[l->terrain_id]->average_type;

        // ------- all square around are the same terrain type and empty
        for( int y1 = y-1; y1 <= y+1; ++y1)
            for( int x1 = x-1; x1 <= x+1; ++x1)
            {
                l = get_loc(x1,y1);
                // #### begin Gilbert 6/3 #######//
                if( !l->can_add_plant() || terrain_res[l->terrain_id]->average_type != teraType)
                    build_flag = 0;
                // #### end Gilbert 6/3 #######//
            }

        if( build_flag )
        {
            short plantBitmap = plant_res.scan( 0, teraType, 0);
            short plantArray[PLANT_ARRAY_SIZE];
            for( int i = 0; i < PLANT_ARRAY_SIZE; ++i)
            {
                plantArray[i] = plant_res.plant_recno(plant_res.scan(0, teraType, 0));
            }
            if( plantArray[0] )
            {
                plant_spray(plantArray, 1 + misc.random(3), 1 + misc.random(2), x, y);
            }
        }
    }
    int xLoc, yLoc;
    short plantBitmap = plant_res.scan( 0, 0, 0);
    short plantArray[PLANT_ARRAY_SIZE];
    for( int i = 0; i < PLANT_ARRAY_SIZE; ++i)
        plantArray[i] = plant_res.plant_recno(plant_res.scan(0, 0, 0));

    for( yLoc = 0; yLoc < max_y_loc; ++yLoc )
    {
        for( xLoc = 0; xLoc < max_x_loc; ++xLoc )
        {
            Location* locPtr = get_loc( xLoc, yLoc );
            if(locPtr->has_dirt())
            {
                Rock *dirtPtr = dirt_array[locPtr->dirt_recno()];
                RockInfo *dirtInfo = rock_res.get_rock_info(dirtPtr->rock_recno);
                if (dirtInfo->rock_type == 'P')
                {
                    if( plantArray[0] )
                        plant_spray(plantArray, 0, misc.random(3), xLoc, yLoc);
                }
            }
        }
    }
    // ------- kill some plant ----------//
    plant_death(1, scanRadius);
}