Payday and Missing Credit

A place to post suggestions for new features, new bugs, and comments about the existing code.
fufi
Posts: 297
Joined: Sat Apr 05, 2008 7:26 pm
Contact:

Post by fufi »

...
Last edited by fufi on Fri Oct 31, 2008 6:31 pm, edited 1 time in total.
pkk
Posts: 5419
Joined: Tue Jul 01, 2003 7:00 am
Location: Germany, Munich

Post by pkk »

IMO it's a rounding error:

Payday = ( [Payday] / [Number of Players] ) * [Number of Players]

Payday is donated to each player, before the credits go the the investor (commander).

EDIT:
It's like I said, a rounding problem.

Example:
500 credits / 3 = 166.67 credits

166.67 will be rounded to 166, because delta is INT.

All three player get 166 credits and the investor/commander (because of auto donating) gets 498 credits.


The code (src/FedSrv/fsmission.cpp):
CODEvoid CFSMission::DoPayday(IsideIGC* pside)
{
SideID sideID = pside->GetObjectID();

int np = GetCountOfPlayers(pside, true);
if (np != 0)
{
int delta = m_rgMoney[sideID] / np;
if (delta > 0)
{
BEGIN_PFM_CREATE(g.fm, pfmPayday, S, PAYDAY)
END_PFM_CREATE
pfmPayday->dMoney = Money(delta);
g.fm.SendMessages(CFSSide::FromIGC(pside)->GetGroup(), FM_GUARANTEED, FM_FLUSH);

m_rgMoney[sideID] -= delta * np;

const ShipListIGC * plistShip = pside->GetShips();
for(ShipLinkIGC * plinkShip = plistShip->first(); plinkShip; plinkShip = plinkShip->next())
{
CFSShip * pfsShip = (CFSShip *) plinkShip->data()->GetPrivateData();
if (pfsShip->IsPlayer())
{
CFSPlayer* pfsDonate = pfsShip->GetPlayer()->GetAutoDonate();
if (pfsDonate)
pfsDonate->SetMoney(pfsDonate->GetMoney() + delta);
else
pfsShip->SetMoney(pfsShip->GetMoney() + delta);
}
}
}
}
}

EDIT2:
Alleg is using the same function for starting money, so starting money is also effected by this rounding error.

CODEvoid CFSMission::GiveSideMoney(IsideIGC * pside, Money money)
{
assert (money >= 0);
if (money != 0)
{
SideID sideID = pside->GetObjectID();
m_rgMoney[sideID] += money;

DoPayday(pside);
}
}
Last edited by pkk on Tue Sep 30, 2008 3:45 pm, edited 1 time in total.
The Escapist (Justin Emerson) @ Dec 21 2010, 02:33 PM:
The history of open-source Allegiance is paved with the bodies of dead code branches, forum flame wars, and personal vendettas. But a community remains because people still love the game.
Dark_Sponge
Posts: 386
Joined: Sun Dec 23, 2007 4:43 am

Post by Dark_Sponge »

pkk wrote:QUOTE (pkk @ Sep 30 2008, 08:17 AM) IMO it's a rounding error:
Oh sure, a rounding error /rolleyes.gif" style="vertical-align:middle" emoid=":roll:" border="0" alt="rolleyes.gif" />
Sounds like Gigacorp's accountants are embezzling again.
ImageImageImage
Andon
Posts: 5453
Joined: Sun Jun 03, 2007 8:29 pm
Location: Maryland, USA
Contact:

Post by Andon »

pkk wrote:QUOTE (pkk @ Sep 30 2008, 11:17 AM) IMO it's a rounding error:

Payday = ( [Payday] / [Number of Players] ) * [Number of Players]

Payday is donated to each player, before the credits go the the investor (commander).

EDIT:
It's like I said, a rounding problem.

Example:
500 credits / 3 = 166.67 credits

166.67 will be rounded to 166, because delta is INT.

All three player get 166 credits and the investor/commander (because of auto donating) gets 498 credits.
The code (src/FedSrv/fsmission.cpp):
(codesnip)
How hard would it be to change delta to a double instead of an int? Seems like a pretty straightforward change to me, but then again, this IS the alleg code
Image
ImageImage
DasSmiter
Posts: 3820
Joined: Mon May 23, 2005 7:00 am
Location: Stillwater, Oklahoma

Post by DasSmiter »

can we switch it to double or something so that we get the full 500?

i've had games where i do need that extra 3 to be able to open, and i hate have 19999 money
ImageImageImage
Get over yourselves, don't try to win arguments on the internet where the option of a punch in the mouth is unavailable
"It is not that I cannot create anything good, but that I will not." And to prove this, he created the peacock.
badpazzword
Posts: 3627
Joined: Thu Jan 12, 2006 8:00 am
Contact:

Post by badpazzword »

Can't you cast delta to float, then use a rounding function on it (ceiling e.g.)?

Nevermind my post.
Last edited by badpazzword on Tue Sep 30, 2008 5:32 pm, edited 1 time in total.
Have gaming questions? Get expert answers! Image Image
CronoDroid
Posts: 4606
Joined: Sun Nov 06, 2005 8:00 am
Contact:

Post by CronoDroid »

Yeah that needs to be changed. I hate it when you're missing those two credits to hand out an extra SR!
Psychosis
Posts: 4218
Joined: Wed Oct 27, 2004 7:00 am
Location: California

Post by Psychosis »

can we make that fudge the other way? I'd rather it was 2 extra credits then 2 credits short
Ramaglor
Posts: 687
Joined: Sun Aug 28, 2005 7:00 am
Location: Seattle

Post by Ramaglor »

The fudging only goes one way...... "int" always rounds down
Spidey's tactical advice on TS during Tourny game
QUOTE We don't need to save our thingy.[/quote]
Andon
Posts: 5453
Joined: Sun Jun 03, 2007 8:29 pm
Location: Maryland, USA
Contact:

Post by Andon »

I don't know how simple it would be, but perhaps do something where it finds the difference between the original payday and the actual payday, and gives that to the investor
Image
ImageImage
Post Reply