← Back to team overview

widelands-dev team mailing list archive

ware targets increase function

 

Hi,

I intend to create a function in the AI that would every 40 minutes
increase the ware target  by 1. (details might differ, this is not a topic
of a question)

So far I managed to set following function:

void DefaultAI::set_ware_targets (void) {

     Ware_Index const nr_wares = tribe_->get_nrwares();

    wares.resize(nr_wares);

     for (EconomyObserver* observer : economies) {

       // Don't check if the economy has no warehouse.

        if (observer->economy.warehouses().empty()){

            continue;}

         printf (" owner: %d\n", observer->economy.owner().player_number());


        for (Widelands::Ware_Index id = 0; id < nr_wares; ++id) {

             const Economy::Target_Quantity & tq =

                 observer->economy.ware_target_quantity(id);

             printf ("%d - target: %2d\n",id,tq.permanent);

           }

    }

}


It is called few times, it seems that it will print current target values
properly and then on line starting with printf crashes with:


Program received signal SIGSEGV, Segmentation fault.

0x0879ad38 in Widelands::Player::player_number (this=0x1a) at
/var/widelands/tibor-ai5/src/logic/player.h:112

112 Player_Number     player_number() const {return m_plnum;}

It looks like observer->economy was not a proper object...

Do you have any ideas?

Thanks