glob2-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [glob2-devel] I'm confused by the code in NewNicowar::control_attack


From: Bradley Arsenault
Subject: Re: [glob2-devel] I'm confused by the code in NewNicowar::control_attacks
Date: Fri, 10 Aug 2007 15:14:24 -0400

On 8/10/07, Joe Wells <address@hidden> wrote:
Okay, I'm lucky this time I happened to be running under the debugger
when I got a segmentation fault.  (It should *not* be necessary to run
under the debugger.  Programs that crash should leave core dump
files.)

This time, the guilty code is in NewNicowar::control_attacks.  (I have
no idea if this is related to the segmentation violation I reported
earlier.)  For reference, I've appended the code of this function
below.

This code is doing several things that I don't understand.

The part most directly at fault is that it is assuming the command b =
echo.get_building_register().get_building(i) stores a valid building
in b.  This time, it does not, and dereferencing the building with
b->locked[true] causes a crash.  So it should definitely check that b
is valid before using it.

get_building(i) should *always* be valid, this is an echo semantic, as long as I is up to date. Nicowar uses iterating to find buildings. I will investigate this further.
 

But anyway, how could this call possibly work?  The number i is an
index of an attack flag.  (Right?)  How could this possibly be
connected to swimming pools?  And why is code for controlling attack
flags concerned with swimming pools at all?

Maybe this is code that was copied from elsewhere and insufficiently
adapted afterward?

I'm confused.

--
Joe

======================================================================
void NewNicowar::control_attacks(Echo& echo)
{
        choose_enemy_target(echo);

        if(target!=-1)
        {
                int number_attacks=0;
                if(war)
                {
                        number_attacks=2;
                }


                if(attack_flags.size() < number_attacks)
                {
                        attack_building(echo);
                }
        }

        BuildingSearch bs_pool(echo);
        bs_pool.add_condition(new SpecificBuildingType(IntBuildingType::SWIMSPEED_BUILDING));
        int num_pool=bs_pool.count_buildings();

        for(int i=0; i<attack_flags.size(); ++i)
        {
                Building* b = echo.get_building_register().get_building(i);
                if((num_pool && b->locked[true]) || (num_pool==0 && b->locked[false]))
                {
                        ManagementOrder* mo_destroy=new DestroyBuilding(i);
                        echo.add_management_order(mo_destroy);
                }
        }
}


_______________________________________________
glob2-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/glob2-devel

Having a swimming pool means the units are trained to swim, its used to check whether the building is accessible or not. If units can swim, more area is accessible. This code should be using can_swim i'll look into that. Also, seems like attack_flags is storing an integer to a flag that has been destroyed. All flags should cause an event to be triggered that causes the removal of it from this list. Somehow, that event isn't firing. I'll look into that to.

Currently my computer is offline except for my windows one, so I have to wait to do the remaining bug fixes on beta 1. They include this nicowar fix, a fix to YOG, and a couple others that i'll dig through my emails for.


--
Extra cheese comes at a cost. Bradley Arsenault.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]