Add PIF_NoScenarioSave option to script players

alut-include-path
Sven Eberhardt 2017-02-20 13:39:11 -05:00
parent 99a65008cd
commit cc0371bdf5
3 changed files with 41 additions and 21 deletions

View File

@ -192,6 +192,7 @@ void C4PlayerInfo::CompileFunc(StdCompiler *pComp)
{ "Won", PIF_Won },
{ "AttributesFixed", PIF_AttributesFixed },
{ "NoScenarioInit", PIF_NoScenarioInit },
{ "NoScenarioSave", PIF_NoScenarioSave },
{ "NoEliminationCheck", PIF_NoEliminationCheck },
{ "Invisible", PIF_Invisible},
{ nullptr, 0 },
@ -1687,7 +1688,9 @@ bool C4PlayerInfoList::SetAsRestoreInfos(C4PlayerInfoList &rFromPlayers, bool fS
}
else if (pInfo->GetType() == C4PT_Script)
{
fKeepInfo = fSaveScriptPlrs;
// Save only if either all players should be saved (fSaveScriptPlrs && fSaveUserPlrs)
// or if script players are saved and general scenario saving for this script player is desired
fKeepInfo = fSaveScriptPlrs && (fSaveUserPlrs || pInfo->IsScenarioSaveDesired());
if (fSetScriptPlrRefToLocalGroup)
{
// just compose a unique filename for script player

View File

@ -45,26 +45,27 @@ public:
// player flags
enum Flags
{
PIF_Joined = 1<<0, // player has joined the game
PIF_Removed = 1<<2, // player has been removed
PIF_HasRes = 1<<3, // pRes is set
PIF_JoinIssued = 1<<4, // flag for host to mark a player for which the join is issued
PIF_TempFile = 1<<5, // player file is temporary and to be deleted after join recreation
PIF_InScenarioFile = 1<<6, // player file is present within the scenario; res is not to be used
PIF_JoinedForSavegameOnly = 1<<7, // player file has been specified to take over a savegame player; do not join as normal player if association fails
PIF_Disconnected = 1<<8, // the player was removed because his client disconnected
PIF_Won = 1<<9, // player survived until game end (for game evaluation only)
PIF_VotedOut = 1<<10, // player was removed from the round after a successful voting
PIF_AttributesFixed= 1<<11, // player color and name aren't changed on collision
PIF_NoScenarioInit = 1<<12, // do not call ScenariInit for this player
PIF_NoEliminationCheck = 1<<13, // do not eliminate player if crew is empty
PIF_Invisible = 1<<14, // do not show in lobby and menus
PIF_Joined = 1 << 0, // player has joined the game
PIF_Removed = 1 << 2, // player has been removed
PIF_HasRes = 1 << 3, // pRes is set
PIF_JoinIssued = 1 << 4, // flag for host to mark a player for which the join is issued
PIF_TempFile = 1 << 5, // player file is temporary and to be deleted after join recreation
PIF_InScenarioFile = 1 << 6, // player file is present within the scenario; res is not to be used
PIF_JoinedForSavegameOnly = 1 << 7, // player file has been specified to take over a savegame player; do not join as normal player if association fails
PIF_Disconnected = 1 << 8, // the player was removed because his client disconnected
PIF_Won = 1 << 9, // player survived until game end (for game evaluation only)
PIF_VotedOut = 1 << 10, // player was removed from the round after a successful voting
PIF_AttributesFixed = 1 << 11, // player color and name aren't changed on collision
PIF_NoScenarioInit = 1 << 12, // do not call ScenariInit for this player
PIF_NoEliminationCheck = 1 << 13, // do not eliminate player if crew is empty
PIF_Invisible = 1 << 14, // do not show in lobby and menus
PIF_NoScenarioSave = 1 << 15, // not saved in SavePlayerInfos.txt if "save as scenario" is performed
// flags to be synchronized via network and saved into player info
PIF_SyncFlags = PIF_Joined | PIF_Removed | PIF_HasRes | PIF_InScenarioFile | PIF_JoinedForSavegameOnly | PIF_Disconnected | PIF_Won | PIF_VotedOut | PIF_AttributesFixed | PIF_NoScenarioInit | PIF_NoEliminationCheck | PIF_Invisible,
PIF_SyncFlags = PIF_Joined | PIF_Removed | PIF_HasRes | PIF_InScenarioFile | PIF_JoinedForSavegameOnly | PIF_Disconnected | PIF_Won | PIF_VotedOut | PIF_AttributesFixed | PIF_NoScenarioInit | PIF_NoEliminationCheck | PIF_Invisible | PIF_NoScenarioSave,
// flags to be copied from savegame-player for takeover
PIF_SavegameTakeoverFlags = PIF_Joined | PIF_Removed | PIF_JoinIssued | PIF_AttributesFixed | PIF_NoScenarioInit | PIF_NoEliminationCheck | PIF_Invisible
PIF_SavegameTakeoverFlags = PIF_Joined | PIF_Removed | PIF_JoinIssued | PIF_AttributesFixed | PIF_NoScenarioInit | PIF_NoEliminationCheck | PIF_Invisible | PIF_NoScenarioSave,
};
// player attributes used in attribute conflict resolver
@ -176,6 +177,7 @@ public:
bool IsAttributesFixed() const { return !!(dwFlags & PIF_AttributesFixed); }
bool IsInvisible() const { return !!(dwFlags & PIF_Invisible); }
bool IsScenarioInitDesired() const { return !(dwFlags & PIF_NoScenarioInit); }
bool IsScenarioSaveDesired() const { return !(dwFlags & PIF_NoScenarioSave); }
C4ID GetScriptPlayerExtraID() const { return idExtraData; }
bool IsNoEliminationCheck() const { return !!(dwFlags & PIF_NoEliminationCheck); }
bool HasAutoGeneratedColor() { return dwColor != dwOriginalColor; } // whether the player got a new color assigned due to color conflict

View File

@ -1127,10 +1127,12 @@ static bool FnSetLeaguePerformance(C4PropList * _this, long iScore, long idPlaye
}
static const int32_t CSPF_FixedAttributes = 1<<0,
CSPF_NoScenarioInit = 1<<1,
CSPF_NoEliminationCheck = 1<<2,
CSPF_Invisible = 1<<3;
static const int32_t CSPF_FixedAttributes = 1 << 0,
CSPF_NoScenarioInit = 1 << 1,
CSPF_NoEliminationCheck = 1 << 2,
CSPF_Invisible = 1 << 3,
CSPF_NoScenarioSave = 1 << 4;
static bool FnCreateScriptPlayer(C4PropList * _this, C4String *szName, long dwColor, long idTeam, long dwFlags, C4ID idExtra)
{
@ -1146,6 +1148,7 @@ static bool FnCreateScriptPlayer(C4PropList * _this, C4String *szName, long dwCo
if (dwFlags & CSPF_NoScenarioInit ) dwInfoFlags |= C4PlayerInfo::PIF_NoScenarioInit;
if (dwFlags & CSPF_NoEliminationCheck) dwInfoFlags |= C4PlayerInfo::PIF_NoEliminationCheck;
if (dwFlags & CSPF_Invisible ) dwInfoFlags |= C4PlayerInfo::PIF_Invisible;
if (dwFlags & CSPF_NoScenarioSave) dwInfoFlags |= C4PlayerInfo::PIF_NoScenarioSave;
pScriptPlrInfo->SetAsScriptPlayer(szName->GetCStr(), dwColor, dwInfoFlags, idExtra);
pScriptPlrInfo->SetTeam(idTeam);
C4ClientPlayerInfos JoinPkt(nullptr, true, pScriptPlrInfo);
@ -2287,6 +2290,16 @@ static bool FnSetPlayerTeam(C4PropList * _this, long iPlayer, long idNewTeam, bo
return true;
}
// undocumented!
static C4PropList *FnGetScriptPlayerExtraID(C4PropList * _this, long player_number)
{
C4Player *plr = ::Players.Get(player_number);
if (!plr) return nullptr;
C4PlayerInfo *info = plr->GetInfo();
if (!info) return nullptr;
return C4Id2Def(info->GetScriptPlayerExtraID());
}
// undocumented!
static long FnGetTeamConfig(C4PropList * _this, long iConfigValue)
{
@ -2861,6 +2874,7 @@ void InitGameFunctionMap(C4AulScriptEngine *pEngine)
F(GetPlayerID);
F(GetPlayerTeam);
F(SetPlayerTeam);
F(GetScriptPlayerExtraID);
F(GetTeamConfig);
F(GetTeamName);
F(GetTeamColor);
@ -3015,6 +3029,7 @@ C4ScriptConstDef C4ScriptGameConstMap[]=
{ "CSPF_NoScenarioInit" ,C4V_Int, CSPF_NoScenarioInit },
{ "CSPF_NoEliminationCheck" ,C4V_Int, CSPF_NoEliminationCheck },
{ "CSPF_Invisible" ,C4V_Int, CSPF_Invisible },
{ "CSPF_NoScenarioSave" ,C4V_Int, CSPF_NoScenarioSave },
{ "DMQ_Sky" ,C4V_Int, DMQ_Sky },
{ "DMQ_Sub" ,C4V_Int, DMQ_Sub },