forked from Mirrors/openclonk
SetPlrKnowledge(nil, ...) sets/removes knowledge for all players (#1236)
Useful e.g. for ingame scripting when you want to grant extra construction plans. Additionally, this kind of behavior is known from some other functions with per-player parameters like e.g. Sound().issue1247
parent
deadfcf099
commit
b2501ed0e5
|
@ -13,7 +13,7 @@
|
|||
<param>
|
||||
<type>int</type>
|
||||
<name>player</name>
|
||||
<desc>Player which receives the construction plan.</desc>
|
||||
<desc>Player which receives or loses the construction plan. If nil, the function is executed for all players.</desc>
|
||||
</param>
|
||||
<param>
|
||||
<type>id</type>
|
||||
|
@ -31,8 +31,8 @@
|
|||
<desc>Gives a player a construction plan resp. removes the plan if remove is given.</desc>
|
||||
<examples>
|
||||
<example>
|
||||
<code>var i, id; <funclink>while</funclink> (id = <funclink>GetDefinition</funclink>(i++)) SetPlrKnowledge(0, id);</code>
|
||||
<text>The first player is given plans to all loaded objects.</text>
|
||||
<code>var i, id; <funclink>while</funclink> (id = <funclink>GetDefinition</funclink>(i++)) SetPlrKnowledge(nil, id);</code>
|
||||
<text>All players are given plans to all loaded objects.</text>
|
||||
</example>
|
||||
</examples>
|
||||
<related>
|
||||
|
|
|
@ -842,23 +842,41 @@ static bool FnDoBaseProduction(C4PropList * _this, long iPlr, C4ID id, long iCha
|
|||
return ::Players.Get(iPlr)->BaseProduction.SetIDCount(id,iLastcount+iChange,true);
|
||||
}
|
||||
|
||||
static bool FnSetPlrKnowledge(C4PropList * _this, long iPlr, C4ID id, bool fRemove)
|
||||
bool FnSetPlrKnowledge(C4Player *player, C4ID id, bool fRemove)
|
||||
{
|
||||
C4Player *pPlr=::Players.Get(iPlr);
|
||||
if (!pPlr) return false;
|
||||
if (fRemove)
|
||||
{
|
||||
long iIndex=pPlr->Knowledge.GetIndex(id);
|
||||
long iIndex = player->Knowledge.GetIndex(id);
|
||||
if (iIndex<0) return false;
|
||||
return pPlr->Knowledge.DeleteItem(iIndex);
|
||||
return player->Knowledge.DeleteItem(iIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!C4Id2Def(id)) return false;
|
||||
return pPlr->Knowledge.SetIDCount(id,1,true);
|
||||
return player->Knowledge.SetIDCount(id, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
static bool FnSetPlrKnowledge(C4PropList * _this, Nillable<long> iPlr, C4ID id, bool fRemove)
|
||||
{
|
||||
|
||||
bool success = false;
|
||||
// iPlr == nil: Call for all players
|
||||
if (iPlr.IsNil())
|
||||
{
|
||||
for (C4Player *player = ::Players.First; player; player = player->Next)
|
||||
if (FnSetPlrKnowledge(player, id, fRemove))
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise call for requested player
|
||||
C4Player *player = ::Players.Get(iPlr);
|
||||
if (player) success = FnSetPlrKnowledge(player, id, fRemove);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
static C4Value FnGetPlrKnowledge(C4PropList * _this, int iPlr, C4ID id, int iIndex, int dwCategory)
|
||||
{
|
||||
if (!ValidPlr(iPlr)) return C4VBool(false);
|
||||
|
|
Loading…
Reference in New Issue