void Army::Transport( Logic& l, float delta_time ) { if( to == final_to ) { int i = l.GetCityIndex( to ); if( to == transporting_to ) { if( i == -1 ) throw std::string("Must transport to a city"); City& c( l.GetCityByIndex(i) ); c.food_contained += food_stored; food_stored = 0; } else if( to == transporting_from ) { if( i != -1 ) { City& c( l.GetCityByIndex(i) ); if( hunger > 0 ) { c.food_contained -= hunger; hunger = 0; } food_stored = storage_capacity; c.food_contained -= food_stored; } else { int j = l.GetFarmIndex( to ); if( j == -1 ) throw std::string("Must transport from a city or farm"); Farm& f( l.GetFarmByIndex( j ) ); if( hunger > 0 ) { f.food -= hunger; hunger = 0; } food_stored = storage_capacity; f.food -= food_stored; } } final_to = from; from = to; to = l.CalculatePathTo( *this, final_to ); } else { from = to; to = l.CalculatePathTo( *this, final_to ); } }
void Army::Move( Logic& l, float delta_time, int& i ) { if( to == final_to ) { for( int j(0); j < l.GetArmies().size(); j++ ) { Army& a( l.GetArmyByIndex(j) ); if( a.used && i != j && x == a.x && y == a.y ) { soldiers += a.soldiers; carts += a.carts; rectangles[ (int)Type::Army ].erase( a.rectangle ); l.GetArmies().erase( j ); break; } } from = to; state = Stationary; } else { from = to; to = l.CalculatePathTo( *this, final_to ); } }