void Military::timeStep(const unsigned int time )
{
  if( game::Date::isMonthChanged() )
  {
    DateTime curDate = game::Date::current();
    //clear old notificationse
    for( Notifications::iterator it=_d->notifications.begin(); it != _d->notifications.end(); )
    {
      if( it->date.monthsTo( curDate ) > notificationHistoryMonths ) { it = _d->notifications.erase( it ); }
      else { ++it; }
    }
  }

  if( game::Date::isWeekChanged() )
  {
    world::EmpirePtr empire = _city()->empire();

    for( Notifications::iterator it=_d->notifications.begin(); it != _d->notifications.end(); )
    {
      world::ObjectPtr object = empire->findObject( it->objectName );

      if( object.isValid() ) { ++it; }
      else { it = _d->notifications.erase( it ); }
    }
  }

  if( _d->needUpdateMilitaryThreat || game::Date::isMonthChanged() )
  {
    _d->needUpdateMilitaryThreat = false;

    EnemySoldierList enemiesInCity = _city()->walkers().select<EnemySoldier>();

    _d->threatValue = enemiesInCity.size() * enemySoldiertThreat;
  }  
}
Example #2
0
void Mars::_doBlessing(PlayerCityPtr city)
{
  EnemySoldierList enemies;
  enemies << city->walkers( walker::any );

  bool blessingDone = false;
  int step = enemies.size() / 3;
  for( int k=0; k < step; k++ )
  {
    int index = math::random( enemies.size() );
    EnemySoldierList::iterator it = enemies.begin();
    std::advance( it, index );
    (*it)->die();
    blessingDone = true;
  }

  if( blessingDone )
  {
    events::GameEventPtr event = events::ShowInfobox::create( _("##spirit_of_mars_title##"),
                                                              _("##spirit_of_mars_text##"),
                                                              events::ShowInfobox::send2scribe );
    event->dispatch();
  }
}