1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef LUA_RULES_H
#define LUA_RULES_H
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <map>
using std::map;
#include "LuaHandleSynced.h"
#define MAX_LUA_COB_ARGS 10
class CUnit;
class CFeature;
class CProjectile;
class CWeapon;
struct UnitDef;
struct FeatureDef;
struct Command;
struct BuildInfo;
struct lua_State;
class CLuaRules : public CLuaHandleSynced
{
public:
static void LoadHandler();
static void FreeHandler();
public: // call-ins
bool SyncedUpdateCallIn(lua_State *L, const string& name);
bool UnsyncedUpdateCallIn(lua_State *L, const string& name);
bool CommandFallback(const CUnit* unit, const Command& cmd);
bool AllowCommand(const CUnit* unit, const Command& cmd, bool fromSynced);
bool AllowUnitCreation(const UnitDef* unitDef,
const CUnit* builder, const BuildInfo* buildInfo);
bool AllowUnitTransfer(const CUnit* unit, int newTeam, bool capture);
bool AllowUnitBuildStep(const CUnit* builder, const CUnit* unit, float part);
bool AllowFeatureCreation(const FeatureDef* featureDef, int allyTeamID,
const float3& pos);
bool AllowFeatureBuildStep(const CUnit* builder, const CFeature* feature,
float part);
bool AllowResourceLevel(int teamID, const string& type, float level);
bool AllowResourceTransfer(int oldTeam, int newTeam,
const string& type, float amount);
bool AllowDirectUnitControl(int playerID, const CUnit* unit);
bool AllowStartPosition(int playerID, const float3& pos);
bool TerraformComplete(const CUnit* unit, const CUnit* build);
bool MoveCtrlNotify(const CUnit* unit, int data);
void Cob2Lua(const LuaHashString& funcName, const CUnit* unit,
int& argsCount, int args[MAX_LUA_COB_ARGS]);
int AllowWeaponTargetCheck(
unsigned int attackerID,
unsigned int attackerWeaponNum,
unsigned int attackerWeaponDefID);
int AllowWeaponTarget(
unsigned int attackerID,
unsigned int targetID,
unsigned int attackerWeaponNum,
unsigned int attackerWeaponDefID,
float* targetPriority);
bool UnitPreDamaged(const CUnit* unit, const CUnit* attacker,
float damage, int weaponID, bool paralyzer,
float* newDamage, float* impulseMult);
bool ShieldPreDamaged(const CProjectile*, const CWeapon*, const CUnit*, bool);
// unsynced
bool DrawUnit(int unitID);
bool DrawFeature(int featureID);
bool DrawShield(int unitID, int weaponID);
private:
CLuaRules();
~CLuaRules();
protected:
bool AddSyncedCode(lua_State *L);
bool AddUnsyncedCode(lua_State *L);
int UnpackCobArg(lua_State* L);
protected: // call-outs
static int PermitHelperAIs(lua_State* L);
private:
bool haveCommandFallback;
bool haveAllowCommand;
bool haveAllowUnitCreation;
bool haveAllowUnitTransfer;
bool haveAllowUnitBuildStep;
bool haveAllowFeatureCreation;
bool haveAllowFeatureBuildStep;
bool haveAllowResourceLevel;
bool haveAllowResourceTransfer;
bool haveAllowDirectUnitControl;
bool haveAllowStartPosition;
bool haveMoveCtrlNotify;
bool haveTerraformComplete;
bool haveUnitPreDamaged;
bool haveShieldPreDamaged;
bool haveAllowWeaponTargetCheck;
bool haveAllowWeaponTarget;
bool haveDrawUnit;
bool haveDrawFeature;
bool haveDrawShield;
private:
static const int* currentCobArgs;
};
extern CLuaRules* luaRules;
#endif /* LUA_RULES_H */
|