Skip to content

Commit

Permalink
Add {Set,Get}FeatureRulesParam(s)
Browse files Browse the repository at this point in the history
Fix #5059
  • Loading branch information
ashdnazg committed Mar 19, 2016
1 parent 36c554f commit 77f0ddf
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 21 deletions.
1 change: 1 addition & 0 deletions doc/changelog.txt
Expand Up @@ -12,6 +12,7 @@ Sim:
- COB: deprecate unit/team/allyteam/global vars. Use lua functions instead.

Lua:
- Add {Set,Get}FeatureRulesParam(s)
- Add new Spring.ClearUnitGoal(unitID) callout.
- add GamePaused and GameProgress callins to base gadget-handler
- extend builtin uniform binding for custom Lua materials
Expand Down
22 changes: 16 additions & 6 deletions rts/Lua/LuaSyncedCtrl.cpp
Expand Up @@ -155,9 +155,10 @@ bool LuaSyncedCtrl::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(SetTeamShareLevel);
REGISTER_LUA_CFUNC(ShareTeamResource);

REGISTER_LUA_CFUNC(SetUnitRulesParam);
REGISTER_LUA_CFUNC(SetTeamRulesParam);
REGISTER_LUA_CFUNC(SetGameRulesParam);
REGISTER_LUA_CFUNC(SetTeamRulesParam);
REGISTER_LUA_CFUNC(SetUnitRulesParam);
REGISTER_LUA_CFUNC(SetFeatureRulesParam);

REGISTER_LUA_CFUNC(CreateUnit);
REGISTER_LUA_CFUNC(DestroyUnit);
Expand Down Expand Up @@ -1055,9 +1056,9 @@ int LuaSyncedCtrl::SetGameRulesParam(lua_State* L)
int LuaSyncedCtrl::SetTeamRulesParam(lua_State* L)
{
CTeam* team = ParseTeam(L, __FUNCTION__, 1);
if (team == NULL) {
if (team == nullptr)
return 0;
}

SetRulesParam(L, __FUNCTION__, 1, team->modParams, team->modParamsMap);
return 0;
}
Expand All @@ -1066,14 +1067,23 @@ int LuaSyncedCtrl::SetTeamRulesParam(lua_State* L)
int LuaSyncedCtrl::SetUnitRulesParam(lua_State* L)
{
CUnit* unit = ParseUnit(L, __FUNCTION__, 1);
if (unit == NULL) {
if (unit == nullptr)
return 0;
}

SetRulesParam(L, __FUNCTION__, 1, unit->modParams, unit->modParamsMap);
return 0;
}


int LuaSyncedCtrl::SetFeatureRulesParam(lua_State* L)
{
CFeature* feature = ParseFeature(L, __FUNCTION__, 1);
if (feature == nullptr)
return 0;

SetRulesParam(L, __FUNCTION__, 1, feature->modParams, feature->modParamsMap);
return 0;
}

/******************************************************************************/
/******************************************************************************/
Expand Down
5 changes: 3 additions & 2 deletions rts/Lua/LuaSyncedCtrl.h
Expand Up @@ -38,9 +38,10 @@ class LuaSyncedCtrl
static int CallCOBScript(lua_State* L);
static int GetCOBScriptID(lua_State* L);

static int SetUnitRulesParam(lua_State* L);
static int SetTeamRulesParam(lua_State* L);
static int SetGameRulesParam(lua_State* L);
static int SetTeamRulesParam(lua_State* L);
static int SetUnitRulesParam(lua_State* L);
static int SetFeatureRulesParam(lua_State* L);

static int GiveOrderToUnit(lua_State* L);
static int GiveOrderToUnitMap(lua_State* L);
Expand Down
62 changes: 61 additions & 1 deletion rts/Lua/LuaSyncedRead.cpp
Expand Up @@ -285,6 +285,9 @@ bool LuaSyncedRead::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(GetFeaturePieceCollisionVolumeData);
REGISTER_LUA_CFUNC(GetFeatureSeparation);

REGISTER_LUA_CFUNC(GetFeatureRulesParam);
REGISTER_LUA_CFUNC(GetFeatureRulesParams);

REGISTER_LUA_CFUNC(GetProjectilePosition);
REGISTER_LUA_CFUNC(GetProjectileDirection);
REGISTER_LUA_CFUNC(GetProjectileVelocity);
Expand Down Expand Up @@ -4619,7 +4622,7 @@ int LuaSyncedRead::GetFeatureCollisionVolumeData(lua_State* L)
{
CFeature* feature = ParseFeature(L, __FUNCTION__, 1);

if (feature == NULL)
if (feature == nullptr)
return 0;

return (PushCollisionVolumeData(L, &feature->collisionVolume));
Expand All @@ -4631,6 +4634,63 @@ int LuaSyncedRead::GetFeaturePieceCollisionVolumeData(lua_State* L)
}


int LuaSyncedRead::GetFeatureRulesParams(lua_State* L)
{
CFeature* feature = ParseFeature(L, __FUNCTION__, 1);

if (feature == nullptr)
return 0;

int losMask = LuaRulesParams::RULESPARAMLOS_PUBLIC_MASK;

if (IsAlliedAllyTeam(L, feature->allyteam) || game->IsGameOver()) {
losMask |= LuaRulesParams::RULESPARAMLOS_PRIVATE_MASK;
}
else if (teamHandler->AlliedTeams(feature->team, CLuaHandle::GetHandleReadTeam(L)) || ((CLuaHandle::GetHandleReadAllyTeam(L) < 0) && CLuaHandle::GetHandleFullRead(L))) {
losMask |= LuaRulesParams::RULESPARAMLOS_ALLIED_MASK;
}
else if (CLuaHandle::GetHandleReadAllyTeam(L) < 0) {
//! NoAccessTeam
}
else if (IsFeatureVisible(L, feature)) {
losMask |= LuaRulesParams::RULESPARAMLOS_INLOS_MASK;
}

const LuaRulesParams::Params& params = feature->modParams;
const LuaRulesParams::HashMap& paramsMap = feature->modParamsMap;

return PushRulesParams(L, __FUNCTION__, params, paramsMap, losMask);
}


int LuaSyncedRead::GetFeatureRulesParam(lua_State* L)
{
CFeature* feature = ParseFeature(L, __FUNCTION__, 1);

if (feature == nullptr)
return 0;

int losMask = LuaRulesParams::RULESPARAMLOS_PUBLIC_MASK;

if (IsAlliedAllyTeam(L, feature->allyteam) || game->IsGameOver()) {
losMask |= LuaRulesParams::RULESPARAMLOS_PRIVATE_MASK;
}
else if (teamHandler->AlliedTeams(feature->team, CLuaHandle::GetHandleReadTeam(L)) || ((CLuaHandle::GetHandleReadAllyTeam(L) < 0) && CLuaHandle::GetHandleFullRead(L))) {
losMask |= LuaRulesParams::RULESPARAMLOS_ALLIED_MASK;
}
else if (CLuaHandle::GetHandleReadAllyTeam(L) < 0) {
//! NoAccessTeam
}
else if (IsFeatureVisible(L, feature)) {
losMask |= LuaRulesParams::RULESPARAMLOS_INLOS_MASK;
}

const LuaRulesParams::Params& params = feature->modParams;
const LuaRulesParams::HashMap& paramsMap = feature->modParamsMap;

return GetRulesParam(L, __FUNCTION__, 2, params, paramsMap, losMask);
}

/******************************************************************************/
/******************************************************************************/

Expand Down
3 changes: 3 additions & 0 deletions rts/Lua/LuaSyncedRead.h
Expand Up @@ -192,6 +192,9 @@ class LuaSyncedRead {
static int GetFeatureCollisionVolumeData(lua_State* L);
static int GetFeaturePieceCollisionVolumeData(lua_State* L);

static int GetFeatureRulesParam(lua_State* L);
static int GetFeatureRulesParams(lua_State* L);

static int GetProjectilePosition(lua_State* L);
static int GetProjectileDirection(lua_State* L);
static int GetProjectileVelocity(lua_State* L);
Expand Down
12 changes: 12 additions & 0 deletions rts/Sim/Objects/SolidObject.h
Expand Up @@ -4,6 +4,7 @@
#define SOLID_OBJECT_H

#include "WorldObject.h"
#include "Lua/LuaRulesParams.h"
#include "Rendering/Models/3DModel.h"
#include "Sim/Misc/CollisionVolume.h"
#include "System/bitops.h"
Expand Down Expand Up @@ -343,6 +344,17 @@ class CSolidObject: public CWorldObject {
bool yardOpen;
short int buildFacing; ///< Orientation of footprint, 4 different states

/**
* @brief mod controlled parameters
* This is a set of parameters that is initialized
* in CreateUnitRulesParams() and may change during the game.
* Each parameter is uniquely identified only by its id
* (which is the index in the vector).
* Parameters may or may not have a name.
*/
LuaRulesParams::Params modParams;
LuaRulesParams::HashMap modParamsMap; ///< name map for mod parameters

public:
static const float DEFAULT_MASS;
static const float MINIMUM_MASS;
Expand Down
12 changes: 0 additions & 12 deletions rts/Sim/Units/Unit.h
Expand Up @@ -6,7 +6,6 @@
#include <vector>
#include <string>

#include "Lua/LuaRulesParams.h"
#include "Sim/Objects/SolidObject.h"
#include "Sim/Misc/Resource.h"
#include "Sim/Weapons/WeaponTarget.h"
Expand Down Expand Up @@ -313,17 +312,6 @@ class CUnit : public CSolidObject

int featureDefID; // FeatureDef id of the wreck we spawn on death

/**
* @brief mod controlled parameters
* This is a set of parameters that is initialized
* in CreateUnitRulesParams() and may change during the game.
* Each parameter is uniquely identified only by its id
* (which is the index in the vector).
* Parameters may or may not have a name.
*/
LuaRulesParams::Params modParams;
LuaRulesParams::HashMap modParamsMap; ///< name map for mod parameters

/// indicate the relative power of the unit, used for experience calulations etc
float power;

Expand Down

0 comments on commit 77f0ddf

Please sign in to comment.