Make FnSetPlrKnowledge(C4Player*) a C4Player member function

The overload with FnSetPlrKnowledge(C4PropList*) will get problematic.
epoxy
Günther Brammer 2015-12-18 19:26:46 +01:00
parent 6b514893f9
commit ce2b8f45b8
3 changed files with 18 additions and 17 deletions

View File

@ -955,21 +955,6 @@ static bool FnDoBaseProduction(C4PropList * _this, long iPlr, C4ID id, long iCha
return ::Players.Get(iPlr)->BaseProduction.SetIDCount(id,iLastcount+iChange,true);
}
bool FnSetPlrKnowledge(C4Player *player, C4ID id, bool fRemove)
{
if (fRemove)
{
long iIndex = player->Knowledge.GetIndex(id);
if (iIndex<0) return false;
return player->Knowledge.DeleteItem(iIndex);
}
else
{
if (!C4Id2Def(id)) return false;
return player->Knowledge.SetIDCount(id, 1, true);
}
}
static bool FnSetPlrKnowledge(C4PropList * _this, Nillable<long> iPlr, C4ID id, bool fRemove)
{
@ -978,14 +963,14 @@ static bool FnSetPlrKnowledge(C4PropList * _this, Nillable<long> iPlr, C4ID id,
if (iPlr.IsNil())
{
for (C4Player *player = ::Players.First; player; player = player->Next)
if (FnSetPlrKnowledge(player, id, fRemove))
if (player->SetKnowledge(id, fRemove))
success = true;
}
else
{
// Otherwise call for requested player
C4Player *player = ::Players.Get(iPlr);
if (player) success = FnSetPlrKnowledge(player, id, fRemove);
if (player) success = player->SetKnowledge(id, fRemove);
}
return success;
}

View File

@ -720,6 +720,21 @@ bool C4Player::SetWealth(int32_t iVal)
return true;
}
bool C4Player::SetKnowledge(C4ID id, bool fRemove)
{
if (fRemove)
{
long iIndex = Knowledge.GetIndex(id);
if (iIndex<0) return false;
return Knowledge.DeleteItem(iIndex);
}
else
{
if (!C4Id2Def(id)) return false;
return Knowledge.SetIDCount(id, 1, true);
}
}
void C4Player::SetViewMode(int32_t iMode, C4Object *pTarget, bool immediate_position)
{
// safe back

View File

@ -186,6 +186,7 @@ public:
bool ObjectInCrew(C4Object *tobj);
bool DoWealth(int32_t change);
bool SetWealth(int32_t val);
bool SetKnowledge(C4ID id, bool fRemove);
bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false);
bool IsHostileTowards(const C4Player *opponent) const;
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);