git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@284 67975925-1194-0748-b3d5-c16f83f1a3a1

This commit is contained in:
tankefugl 2005-07-15 14:20:59 +00:00
parent 9ae2165c8f
commit 8fd7e2a1be
7 changed files with 221 additions and 32 deletions

View file

@ -2783,6 +2783,12 @@
<File
RelativePath="..\mod\AvHNexusTunnelToClient.h">
</File>
<File
RelativePath="..\mod\AvHObjective.cpp">
</File>
<File
RelativePath="..\mod\AvHObjective.h">
</File>
<File
RelativePath="..\mod\AvHOrder.cpp">
<FileConfiguration

View file

@ -3885,9 +3885,40 @@ void AvHGamerules::UpdateVictoryStatus(void)
{
bool theCheckVictoryWithCheats = !this->GetCheatsEnabled() || this->GetIsCheatEnabled(kcEndGame1) || this->GetIsCheatEnabled(kcEndGame2);
// SCRIPTENGINE VICTORY
if (this->GetIsScriptedMode())
{
// SCRIPTENGINE: Check for victory status
AvHObjectiveState teamAstate, teamBstate;
teamAstate = this->mTeamA.GetObjectiveManager()->GetObjectivesState();
teamBstate = this->mTeamB.GetObjectiveManager()->GetObjectivesState();
if (teamAstate != OBJECTIVE_INDETERMINED || teamBstate != OBJECTIVE_INDETERMINED)
{
// one team is victorious
this->mVictoryTime = gpGlobals->time;
if (teamAstate == teamBstate)
{
this->mVictoryTeam = TEAM_SPECT;
this->mVictoryDraw = true;
}
else if (teamAstate == OBJECTIVE_COMPLETED || teamBstate == OBJECTIVE_FAILED)
this->mVictoryTeam = this->mTeamA.GetTeamNumber();
else if (teamAstate == OBJECTIVE_FAILED || teamBstate == OBJECTIVE_COMPLETED)
this->mVictoryTeam = this->mTeamB.GetTeamNumber();
}
else
{
// Execute LUA callback OnVictoryCheck
AvHTeamNumber vicTeam = gLUA->OnVictoryCheck();
if (vicTeam != TEAM_IND)
{
this->mVictoryTime = gpGlobals->time;
this->mVictoryTeam = vicTeam;
}
}
// Execute LUA callback OnVictory
if (this->mVictoryTeam != TEAM_IND)
gLUA->OnVictory(this->mVictoryTeam);
}
else
if((this->mVictoryTeam == TEAM_IND) && this->mGameStarted && theCheckVictoryWithCheats && !this->GetIsTrainingMode())

View file

@ -888,6 +888,8 @@ void AvHTeam::ResetGame()
this->mGroupTypes[i] = AVH_USER3_NONE;
}
this->mSelectAllGroup.clear();
this->mObjectiveManager.Clear();
}
void AvHTeam::SpawnResourceTower()
@ -2811,3 +2813,9 @@ void AvHTeam::SetSelectAllGroup(EntityListType& inGroup)
{
this->mSelectAllGroup = inGroup;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AvHObjectiveManager *AvHTeam::GetObjectiveManager()
{
return &this->mObjectiveManager;
}

View file

@ -85,6 +85,7 @@
#include "mod/AvHServerPlayerData.h"
#include "mod/AvHTechSlotManager.h"
#include "mod/AvHAlert.h"
#include "mod/AvHObjective.h"
class AvHPlayer;
@ -220,6 +221,8 @@ public:
EntityListType GetSelectAllGroup();
void SetSelectAllGroup(EntityListType& inGroup);
AvHObjectiveManager *GetObjectiveManager();
private:
void AddTechNode(AvHMessageID inMessageID, AvHTechID inTechID, AvHTechID inPrereq1 = TECH_NULL, AvHTechID inPrereq2 = TECH_NULL, bool inAllowMultiples = true, bool inResearched = false);
void SpawnResourceTower();
@ -332,6 +335,8 @@ private:
EntityListType mSelectAllGroup;
float mTimeReinforcementWaveComplete;
AvHObjectiveManager mObjectiveManager;
};
#endif

View file

@ -27,15 +27,8 @@ AvHLUA::~AvHLUA()
void AvHLUA::Init()
{
this->mTimetable.clear();
bool isRestricted = false;
#ifdef AVH_SERVER
this->mNextCallTime = gpGlobals->time + 99999;
isRestricted = GetGameRules()->GetIsCombatMode() || GetGameRules()->GetIsNSMode();
#else
this->mNextCallTime = gClientTimeLastUpdate + 99999;
isRestricted = gHUD.GetIsCombatMode() || gHUD.GetIsNSMode();
#endif
this->mIsRestricted = this->GetIsRestricted();
this->mNextCallTime = this->GetTime() + 99999.0f;
if (this->mGlobalContext != NULL)
{
@ -97,7 +90,7 @@ void AvHLUA::Init()
lua_register(this->mGlobalContext, "client", AvHLUABase_Client);
// SERVER API: non-restricted
if (!isRestricted)
if (!this->mIsRestricted)
{
}
@ -109,12 +102,31 @@ void AvHLUA::Init()
lua_register(this->mGlobalContext, "client", AvHLUABase_Blank);
// CLIENT API: non-restricted
if (!isRestricted)
if (!this->mIsRestricted)
{
}
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool AvHLUA::GetIsRestricted()
{
#ifdef AVH_SERVER
return !GetGameRules()->GetIsScriptedMode();
#else
return !gHUD.GetIsScriptedMode();
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float AvHLUA::GetTime()
{
#ifdef AVH_SERVER
return gpGlobals->time;
#else
return gClientTimeLastUpdate;
#endif
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -126,7 +138,6 @@ bool AvHLUA::LoadLUAForMap(const char *inMapName)
filename += "/maps/";
filename += inMapName;
filename += ".lua";
std::string msg;
bool result = false;
if (luaL_loadfile(this->mGlobalContext, filename.c_str()) || lua_pcall(this->mGlobalContext, 0, 0, 0))
@ -136,6 +147,12 @@ bool AvHLUA::LoadLUAForMap(const char *inMapName)
else
{
// enable or disable events based on restriction
this->definedOnJointeam = this->definedOnLoad = this->definedOnStart = this->definedOnStarted =
this->definedOnVictory = this->definedOnVictoryCheck = this->definedOnStartCheck =
!this->mIsRestricted;
std::string msg;
#ifdef AVH_SERVER
msg = "[LUA] ";
#else
@ -148,12 +165,14 @@ bool AvHLUA::LoadLUAForMap(const char *inMapName)
this->mLoaded = true;
result = true;
}
#ifdef AVH_SERVER
ALERT(at_console, UTIL_VarArgs("%s", msg.c_str()));
ALERT(at_console, UTIL_VarArgs("%s", msg.c_str()));
#else
gEngfuncs.pfnConsolePrint(msg.c_str());
gEngfuncs.pfnConsolePrint(msg.c_str());
#endif
}
return result;
}

View file

@ -79,11 +79,16 @@ public:
void Init();
bool LoadLUAForMap(const char *inMapName);
// Server events
void OnLoad();
bool OnStartCheck();
void OnStart();
void OnStarted();
void OnVictory(AvHTeamNumber inTeamToJoin);
AvHTeamNumber OnVictoryCheck();
void OnJointeam(int inEntindex, AvHTeamNumber inTeamToJoin);
bool mLoaded;
lua_State *mGlobalContext;
@ -92,8 +97,21 @@ public:
int Suspend(lua_State *L, float delay);
int DelayedExecute(lua_State *L, float time);
bool GetIsRestricted();
float GetTime();
private:
// Flags indicating existing server events
bool definedOnLoad;
bool definedOnStartCheck;
bool definedOnStart;
bool definedOnStarted;
bool definedOnVictory;
bool definedOnVictoryCheck;
bool definedOnJointeam;
// Namespace registration
void RegisterNamespace_Time();
#ifdef AVH_SERVER
void RegisterNamespace_Player();
@ -106,6 +124,9 @@ private:
float mNextCallTime;
LUATimetableType mTimetable;
// Restricted = reduced LUA library loads
bool mIsRestricted;
};
extern AvHLUA *gLUA;

View file

@ -11,50 +11,149 @@ extern "C" {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AvHLUA::OnLoad()
{
if (this->mLoaded)
if (this->mLoaded && this->definedOnLoad)
{
lua_getglobal(this->mGlobalContext, "OnLoad");
AvHLUA_Pcall(this->mGlobalContext, 0, 0);
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnLoad");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnLoad = false;
return;
}
if (int errorcode = lua_resume(threadState, 2))
AvHLUA_OnError(lua_tostring(threadState, -1));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool AvHLUA::OnStartCheck()
{
if (this->mLoaded && this->definedOnStartCheck)
{
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnStartCheck");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnStartCheck = false;
return false;
}
if (int errorcode = lua_resume(threadState, 2))
AvHLUA_OnError(lua_tostring(threadState, -1));
// Return the team that won
if (lua_isnumber(threadState, -1))
return (bool)(lua_toboolean(threadState, -1));
}
return false;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AvHLUA::OnStart()
{
if (this->mLoaded)
if (this->mLoaded && this->definedOnStart)
{
lua_getglobal(this->mGlobalContext, "OnStart");
AvHLUA_Pcall(this->mGlobalContext, 0, 0);
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnStart");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnStart = false;
return;
}
if (int errorcode = lua_resume(threadState, 2))
AvHLUA_OnError(lua_tostring(threadState, -1));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AvHLUA::OnStarted()
{
if (this->mLoaded)
if (this->mLoaded && this->definedOnStarted)
{
lua_getglobal(this->mGlobalContext, "OnStarted");
AvHLUA_Pcall(this->mGlobalContext, 0, 0);
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnStarted");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnStarted = false;
return;
}
if (int errorcode = lua_resume(threadState, 2))
AvHLUA_OnError(lua_tostring(threadState, -1));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AvHLUA::OnVictory(AvHTeamNumber inTeamNumber)
{
if (this->mLoaded && this->definedOnVictory)
{
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnVictory");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnVictory = false;
return;
}
lua_pushnumber(threadState, inTeamNumber);
if (int errorcode = lua_resume(threadState, 2))
AvHLUA_OnError(lua_tostring(threadState, -1));
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AvHTeamNumber AvHLUA::OnVictoryCheck()
{
if (this->mLoaded && this->definedOnVictoryCheck)
{
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnVictoryCheck");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnJointeam = false;
return TEAM_IND;
}
if (int errorcode = lua_resume(threadState, 2))
AvHLUA_OnError(lua_tostring(threadState, -1));
// Return the team that won
if (lua_isnumber(threadState, -1))
return (AvHTeamNumber)((int)lua_tonumber(threadState, -1));
}
return TEAM_IND;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void AvHLUA::OnJointeam(int inEntindex, AvHTeamNumber inTeamToJoin)
{
if (this->mLoaded)
if (this->mLoaded && this->definedOnJointeam)
{
lua_State *threadState = lua_newthread(this->mGlobalContext);
lua_getglobal(threadState, "OnJointeam");
if (!lua_isfunction(threadState, -1))
{
// not found, mark and exit
this->definedOnJointeam = false;
return;
}
lua_pushnumber(threadState, inEntindex);
lua_pushnumber(threadState, (int)(inTeamToJoin));
if (int errorcode = lua_resume(threadState, 2))
{
AvHLUA_OnError(lua_tostring(threadState, -1));
}
else
{
// all values returned are on the stack
}
// all values returned are on the stack if no error
}
}
// ---------------------------------------------------------------------