示例#1
0
CLuaRules::CLuaRules()
: CLuaHandleSynced("LuaRules", LUA_HANDLE_ORDER_RULES)
{
	if (!IsValid()) {
		return;
	}

	SetFullCtrl(true, true);
	SetFullRead(true, true);
	SetCtrlTeam(AllAccessTeam, true);
	SetReadTeam(AllAccessTeam, true);
	SetReadAllyTeam(AllAccessTeam, true);
	SetSelectTeam(AllAccessTeam, true);

	Init(LuaRulesSyncedFilename, LuaRulesUnsyncedFilename, SPRING_VFS_MOD);

	if (!IsValid()) {
		return;
	}

	BEGIN_ITERATE_LUA_STATES();

	if (SingleState() || L == L_Sim) {
		haveCommandFallback            = HasCallIn(L, "CommandFallback");
		haveAllowCommand               = HasCallIn(L, "AllowCommand");
		haveAllowUnitCreation          = HasCallIn(L, "AllowUnitCreation");
		haveAllowUnitTransfer          = HasCallIn(L, "AllowUnitTransfer");
		haveAllowUnitBuildStep         = HasCallIn(L, "AllowUnitBuildStep");
		haveAllowFeatureCreation       = HasCallIn(L, "AllowFeatureCreation");
		haveAllowFeatureBuildStep      = HasCallIn(L, "AllowFeatureBuildStep");
		haveAllowResourceLevel         = HasCallIn(L, "AllowResourceLevel");
		haveAllowResourceTransfer      = HasCallIn(L, "AllowResourceTransfer");
		haveAllowDirectUnitControl     = HasCallIn(L, "AllowDirectUnitControl");
		haveAllowStartPosition         = HasCallIn(L, "AllowStartPosition");

		haveMoveCtrlNotify             = HasCallIn(L, "MoveCtrlNotify");
		haveTerraformComplete          = HasCallIn(L, "TerraformComplete");
		haveAllowWeaponTargetCheck     = HasCallIn(L, "AllowWeaponTargetCheck");
		haveAllowWeaponTarget          = HasCallIn(L, "AllowWeaponTarget");
		haveAllowWeaponInterceptTarget = HasCallIn(L, "AllowWeaponInterceptTarget");
		haveUnitPreDamaged             = HasCallIn(L, "UnitPreDamaged");
		haveFeaturePreDamaged          = HasCallIn(L, "FeaturePreDamaged");
		haveShieldPreDamaged           = HasCallIn(L, "ShieldPreDamaged");
	}
	if (SingleState() || L == L_Draw) {
		haveDrawUnit       = HasCallIn(L, "DrawUnit"      );
		haveDrawFeature    = HasCallIn(L, "DrawFeature"   );
		haveDrawShield     = HasCallIn(L, "DrawShield"    );
		haveDrawProjectile = HasCallIn(L, "DrawProjectile");

		SetupUnsyncedFunction(L, "DrawUnit");
		SetupUnsyncedFunction(L, "DrawFeature");
		SetupUnsyncedFunction(L, "DrawShield");
		SetupUnsyncedFunction(L, "DrawProjectile");
		SetupUnsyncedFunction(L, "RecvSkirmishAIMessage");
	}

	END_ITERATE_LUA_STATES();
}
示例#2
0
CLuaRules::CLuaRules()
: CLuaHandleSynced("LuaRules", LUA_HANDLE_ORDER_RULES)
{
	luaRules = this;

	if (L == NULL) {
		return;
	}

	fullCtrl = true;
	fullRead = true;
	ctrlTeam = AllAccessTeam;
	readTeam = AllAccessTeam;
	readAllyTeam = AllAccessTeam;
	selectTeam = AllAccessTeam;

	Init(LuaRulesSyncedFilename, LuaRulesUnsyncedFilename, SPRING_VFS_MOD);

	if (L == NULL) {
		return;
	}

	haveCommandFallback        = HasCallIn("CommandFallback");
	haveAllowCommand           = HasCallIn("AllowCommand");
	haveAllowUnitCreation      = HasCallIn("AllowUnitCreation");
	haveAllowUnitTransfer      = HasCallIn("AllowUnitTransfer");
	haveAllowUnitBuildStep     = HasCallIn("AllowUnitBuildStep");
	haveAllowFeatureCreation   = HasCallIn("AllowFeatureCreation");
	haveAllowFeatureBuildStep  = HasCallIn("AllowFeatureBuildStep");
	haveAllowResourceLevel     = HasCallIn("AllowResourceLevel");
	haveAllowResourceTransfer  = HasCallIn("AllowResourceTransfer");
	haveAllowDirectUnitControl = HasCallIn("AllowDirectUnitControl");
	haveAllowStartPosition     = HasCallIn("AllowStartPosition");

	haveMoveCtrlNotify         = HasCallIn("MoveCtrlNotify");
	haveTerraformComplete      = HasCallIn("TerraformComplete");
	haveAllowWeaponTargetCheck = HasCallIn("AllowWeaponTargetCheck");
	haveAllowWeaponTarget      = HasCallIn("AllowWeaponTarget");
	haveUnitPreDamaged         = HasCallIn("UnitPreDamaged");
	haveShieldPreDamaged       = HasCallIn("ShieldPreDamaged");

	haveDrawUnit    = HasCallIn("DrawUnit");
	haveDrawFeature = HasCallIn("DrawFeature");
	haveAICallIn    = HasCallIn("AICallIn");

	SetupUnsyncedFunction("DrawUnit");
	SetupUnsyncedFunction("DrawFeature");
	SetupUnsyncedFunction("AICallIn");
}
示例#3
0
bool CLuaHandleSynced::UnsyncedUpdateCallIn(const string& name)
{
	if ((name != "RecvFromSynced") &&
	    !eventHandler.IsUnsynced(name)) {
		  return false;
	}
	if (name != "RecvFromSynced") {
		if (HasCallIn(name)) {
			eventHandler.InsertEvent(this, name);
		} else {
			eventHandler.RemoveEvent(this, name);
		}
	}
	SetupUnsyncedFunction(name.c_str());
	return true;
}
示例#4
0
bool CLuaHandleSynced::SetupUnsynced(const string& code, const string& filename)
{
	if ((L == NULL) || code.empty()) {
		return false;
	}

	// make the UNSYNCED table
	unsyncedStr.Push(L);
	lua_newtable(L);
	lua_rawset(L, LUA_REGISTRYINDEX);

	unsyncedStr.GetRegistry(L);

	AddBasicCalls(); // into UNSYNCED

	// remove Script.Kill()
	lua_pushstring(L, "Script");
	lua_rawget(L, -2);
	lua_pushstring(L, "Kill");
	lua_pushnil(L);
	lua_rawset(L, -3);
	LuaPushNamedCFunc(L, "UpdateCallIn", CallOutUnsyncedUpdateCallIn);
	lua_pop(L, 1);

	lua_pushstring(L, "_G");
	unsyncedStr.GetRegistry(L);
	lua_rawset(L, -3);

	LuaPushNamedCFunc(L, "loadstring",   LoadStringData);
	LuaPushNamedCFunc(L, "CallAsTeam",   CallAsTeam);

	// load our libraries
	if (!LuaSyncedTable::PushEntries(L)                                    ||
	    !AddEntriesToTable(L, "VFS",         LuaVFS::PushUnsynced)         ||
	    !AddEntriesToTable(L, "UnitDefs",    LuaUnitDefs::PushEntries)     ||
	    !AddEntriesToTable(L, "WeaponDefs",  LuaWeaponDefs::PushEntries)   ||
	    !AddEntriesToTable(L, "FeatureDefs", LuaFeatureDefs::PushEntries)  ||
	    !AddEntriesToTable(L, "Script",      LuaUnsyncedCall::PushEntries) ||
	    !AddEntriesToTable(L, "Script",      LuaScream::PushEntries)       ||
	    !AddEntriesToTable(L, "Spring",      LuaSyncedRead::PushEntries)   ||
	    !AddEntriesToTable(L, "Spring",      LuaUnsyncedCtrl::PushEntries) ||
	    !AddEntriesToTable(L, "Spring",      LuaUnsyncedRead::PushEntries) ||
	    !AddEntriesToTable(L, "gl",          LuaOpenGL::PushEntries)       ||
	    !AddEntriesToTable(L, "GL",          LuaConstGL::PushEntries)      ||
	    !AddEntriesToTable(L, "Game",        LuaConstGame::PushEntries)    ||
	    !AddEntriesToTable(L, "CMD",         LuaConstCMD::PushEntries)     ||
	    !AddEntriesToTable(L, "CMDTYPE",     LuaConstCMDTYPE::PushEntries)) {
		KillLua();
		return false;
	}

	lua_pushstring(L, "math"); lua_newtable(L);
	lua_getglobal(L, "math"); LightCopyTable(-2, -1); lua_pop(L, 1);
	lua_rawset(L, -3);

	lua_pushstring(L, "table"); lua_newtable(L);
	lua_getglobal(L, "table"); LightCopyTable(-2, -1); lua_pop(L, 1);
	lua_rawset(L, -3);

	lua_pushstring(L, "string"); lua_newtable(L);
	lua_getglobal(L, "string"); LightCopyTable(-2, -1); lua_pop(L, 1);
	lua_rawset(L, -3);

	if (!CopyRealRandomFuncs()) {
		KillLua();
		return false;
	}

	lua_settop(L, 0);

	// note the absence of loadstring() -- global access
	const char* labels[] = {
		"assert",         "error",
		"print",
		"next",           "pairs",        "ipairs",
		"tonumber",       "tostring",     "type",
		"collectgarbage", "gcinfo",
		"unpack",
		"getmetatable",   "setmetatable",
		"rawequal",       "rawget",       "rawset",
		"getfenv",        "setfenv",
		"pcall",          "xpcall",
		"_VERSION",
		NULL
	};
	for (const char** l = labels; *l != NULL; l++) {
		CopyGlobalToUnsynced(*l);
	}

	// add code from the sub-class
	unsyncedStr.GetRegistry(L);
	if (!AddUnsyncedCode()) {
		KillLua();
		return false;
	}
	lua_settop(L, 0);

	if (!LoadUnsyncedCode(code, filename)) {
		KillLua();
		return false;
	}

	if (!SetupUnsyncedFunction("RecvFromSynced")      ||
	    !SetupUnsyncedFunction("Update")              ||
	    !SetupUnsyncedFunction("DrawGenesis")         ||
	    !SetupUnsyncedFunction("DrawWorld")           ||
	    !SetupUnsyncedFunction("DrawWorldPreUnit")    ||
	    !SetupUnsyncedFunction("DrawWorldShadow")     ||
	    !SetupUnsyncedFunction("DrawWorldReflection") ||
	    !SetupUnsyncedFunction("DrawWorldRefraction") ||
	    !SetupUnsyncedFunction("DrawScreenEffects")   ||
	    !SetupUnsyncedFunction("DrawScreen")          ||
	    !SetupUnsyncedFunction("DrawInMiniMap")) {
		return false;
	}

	return true;
}