void Relation::update(const Gift &gift) { int value = gift.value(); if( value <= 0 ) { Logger::warning( "!!! WARNING: Relation update with 0 value from " + gift.sender() ); value = 1; } int monthFromLastGift = math::clamp<int>( lastGift.date().monthsTo( game::Date::current() ), 0, (int)DateTime::monthsInYear ); float timeKoeff = monthFromLastGift / (float)DateTime::monthsInYear; float affectMoney = (float)lastGift.value() / ( monthFromLastGift + 1 ); float moneyKoeff = math::max<float>( value - affectMoney, 0.f ) / value; float favourUpdate = emperor::maxFavourUpdate * timeKoeff * moneyKoeff; favourUpdate = math::clamp<float>( favourUpdate, 0.f, emperor::maxFavourUpdate); Gift maxValueGift( "", "", math::max<int>( value, lastGift.value() ) ); lastGift = maxValueGift; change( favourUpdate ); }
void Emperor::sendGift(const Gift &gift) { Relation &relation = _dfunc()->relations[gift.sender()]; relation.update(gift); }