2025-07-21 16:59 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000519Spring engineUnit Scriptingpublic2007-04-10 23:20
Reporterimbaczek 
Assigned Totrepan 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000519: [patch] added Lua call-in CommandFallback which recieves unhandled commands
Descriptiontitle says it all. no rocket science here.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • diff file icon add_lua_command_fallback.diff (3,253 bytes) 2007-04-10 21:58 -
    Index: Lua/LuaRules.cpp
    ===================================================================
    --- Lua/LuaRules.cpp	(revision 3598)
    +++ Lua/LuaRules.cpp	(working copy)
    @@ -92,6 +92,7 @@
     	haveAllowUnitCreation    = HasCallIn("AllowUnitCreation");
     	haveAllowUnitTransfer    = HasCallIn("AllowUnitTransfer");
     	haveAllowFeatureCreation = HasCallIn("AllowFeatureCreation");
    +	haveCommandFallback      = HasCallIn("CommandFallback");
     }
     
     
    @@ -322,6 +323,63 @@
     }
     
     
    +bool CLuaRules::CommandFallback(const CUnit* unit, const Command& cmd)
    +{
    +	if (!haveCommandFallback) {
    +		return true; // the call is not defined
    +	}
    +
    +	lua_settop(L, 0);
    +
    +	static const LuaHashString cmdStr("CommandFallback");
    +	if (!cmdStr.GetGlobalFunc(L)) {
    +		lua_settop(L, 0);
    +		return true; // the call is not defined
    +	}
    +
    +	// push the unit info
    +	lua_pushnumber(L, unit->id);
    +	lua_pushnumber(L, unit->unitDef->id);
    +	lua_pushnumber(L, unit->team);
    +
    +	// push the command id
    +	lua_pushnumber(L, cmd.id);
    +
    +	// push the params list
    +	lua_newtable(L);
    +	for (int p = 0; p < (int)cmd.params.size(); p++) {
    +		lua_pushnumber(L, p + 1);
    +		lua_pushnumber(L, cmd.params[p]);
    +		lua_rawset(L, -3);
    +	}
    +	HSTR_PUSH_NUMBER(L, "n", cmd.params.size());
    +
    +	// push the options table
    +	lua_newtable(L);
    +	HSTR_PUSH_NUMBER(L, "coded", cmd.options);
    +	HSTR_PUSH_BOOL(L, "alt",   (cmd.options & ALT_KEY));
    +	HSTR_PUSH_BOOL(L, "ctrl",  (cmd.options & CONTROL_KEY));
    +	HSTR_PUSH_BOOL(L, "shift", (cmd.options & SHIFT_KEY));
    +	HSTR_PUSH_BOOL(L, "right", (cmd.options & RIGHT_MOUSE_KEY));
    +
    +	// call the function
    +	if (!RunCallIn(cmdStr, 6, 0)) {
    +		return true;
    +	}
    +
    +	// get the results
    +	const int args = lua_gettop(L);
    +	if (args != 0) {
    +		logOutput.Print("%s() bad return value (%i)\n",
    +		                cmdStr.GetString().c_str(), args);
    +		lua_settop(L, 0);
    +		return true;
    +	}
    +
    +	return true;
    +}
    +
    +
     /******************************************************************************/
     /******************************************************************************/
     //
    Index: Lua/LuaRules.h
    ===================================================================
    --- Lua/LuaRules.h	(revision 3598)
    +++ Lua/LuaRules.h	(working copy)
    @@ -43,7 +43,9 @@
     		                       const CUnit* builder, const float3* pos);
     		bool AllowFeatureCreation(const FeatureDef* featureDef, int allyTeamID,
     		                          const float3& pos);
    -		bool AllowUnitTransfer(const CUnit* unit, int newTeam, bool capture);
    +		bool AllowUnitTransfer(const CUnit* unit, int newTeam, bool capture);
    +
    +		bool CommandFallback(const CUnit* unit, const Command& cmd);
     
     	private:
     		CLuaRules();
    @@ -79,7 +81,9 @@
     		bool haveAllowCommand;
     		bool haveAllowUnitCreation;
     		bool haveAllowUnitTransfer;
    -		bool haveAllowFeatureCreation;
    +		bool haveAllowFeatureCreation;
    +
    +		bool haveCommandFallback;
     
     		map<string, string> infoMap;
     
    Index: Sim/Units/CommandAI/CommandAI.cpp
    ===================================================================
    --- Sim/Units/CommandAI/CommandAI.cpp	(revision 3598)
    +++ Sim/Units/CommandAI/CommandAI.cpp	(working copy)
    @@ -1055,6 +1055,7 @@
         }
     	}
     	ExecuteStateCommand(c);
    +	luaRules->CommandFallback(owner, c);
     	FinishCommand();
     }
     
    
    diff file icon add_lua_command_fallback.diff (3,253 bytes) 2007-04-10 21:58 +

-Relationships
+Relationships

-Notes
There are no notes attached to this issue.
+Notes

-Issue History
Date Modified Username Field Change
2007-04-10 21:58 imbaczek New Issue
2007-04-10 21:58 imbaczek Status new => assigned
2007-04-10 21:58 imbaczek Assigned To => fnordia
2007-04-10 21:58 imbaczek File Added: add_lua_command_fallback.diff
2007-04-10 23:20 trepan Assigned To fnordia => trepan
2007-04-10 23:20 trepan Status assigned => resolved
+Issue History