Ejemplo n.º 1
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);
    }
}
Ejemplo n.º 2
0
Archivo: ow_plant.cpp Proyecto: 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);
}
Ejemplo n.º 3
0
//------------ begin of function World::plant_spray ------------//
void World::plant_spray(short *plantArray, char strength, short x, short y)
{
    if( strength <= 0)
        return;

    //---------- if the space is empty put a plant on it ----------//
    Location *newl = get_loc(x, y);
    short basePlantId = plantArray[m.random(PLANT_ARRAY_SIZE)];
    short plantSize = m.random(plant_res[basePlantId]->bitmap_count);
    if( plantSize > strength)
        plantSize = strength;

    char teraType;
    if( newl && newl->can_add_plant() &&
            (plant_res[basePlantId]->tera_type[0] ==
             (teraType = terrain_res[newl->terrain_id]->average_type) ||
             plant_res[basePlantId]->tera_type[1] == teraType ||
             plant_res[basePlantId]->tera_type[2] == teraType) )
    {
        newl->set_plant(plant_res[basePlantId]->first_bitmap +plantSize
                        , rand_inner_x(), rand_inner_y() );
        newl->set_fire_src(100);
        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 ####//
    }
    else if( newl && newl->is_plant() &&
             // 1. same type, large override small
             // newl->plant_id() >= plant_res[basePlantId]->first_bitmap &&
             // newl->plant_id() < plant_res[basePlantId]->first_bitmap + plantSize)
             // 2. same type, small override large
             // newl->plant_id() > plant_res[basePlantId]->first_bitmap + plantSize &&
             // newl->plant_id() < plant_res[basePlantId]->first_bitmap + plant_res[basePlantId]->bitmap_count)
             // 3. all types, small override large
             (newl->plant_id() - plant_res[plant_res.plant_recno(newl->plant_id())]->first_bitmap) >
             plantSize )
    {
        // same kind of plant, but smaller, override by a smaller one
        newl->remove_plant();
        newl->set_plant(plant_res[basePlantId]->first_bitmap +plantSize
                        , rand_inner_x(), rand_inner_y() );
        newl->set_fire_src(100);
        //### begin alex 24/6 ###//
        //newl->set_power_off();
        //newl->power_nation_recno = 0;
        //set_surr_power_off(x, y);
        //#### end alex 24/6 ####//
    }
    else
    {
        plantSize = -1;
    }

    if( plantSize >= 0 && strength)
    {
        char trial = 3;
        while( trial--)
        {
            switch(m.random(8))
            {
            case 0:		// north square
                if( y > 0)
                    plant_spray(plantArray, strength-1, x,y-1);
                break;
            case 1:		// east square
                if( x < max_x_loc-1 )
                    plant_spray(plantArray, strength-1, x+1,y);
                break;
            case 2:		// south square
                if( y < max_y_loc-1 )
                    plant_spray(plantArray, strength-1, x,y+1);
                break;
            case 3:		// west square
                if( x > 0)
                    plant_spray(plantArray, strength-1, x-1,y);
                break;
            case 4:		// north west square
                if( y > 0 && x > 0)
                    plant_spray(plantArray, strength-1, x-1,y-1);
                break;
            case 5:		// north east square
                if( y > 0 && x < max_x_loc-1 )
                    plant_spray(plantArray, strength-1, x+1,y-1);
                break;
            case 6:		// south east square
                if( y < max_y_loc-1 && x < max_x_loc-1)
                    plant_spray(plantArray, strength-1, x+1,y+1);
                break;
            case 7:		// south west square
                if( y < max_y_loc-1 && x > 0)
                    plant_spray(plantArray, strength-1, x-1,y+1);
                break;
            }
        }
    }
}