Exemple #1
0
void LuaUtils::PushCommandDesc(lua_State* L, const CommandDescription& cd)
{
	const int numParams = cd.params.size();
	const int numTblKeys = 12;

	lua_checkstack(L, 1 + 1 + 1 + 1);
	lua_createtable(L, 0, numTblKeys);

	HSTR_PUSH_NUMBER(L, "id",          cd.id);
	HSTR_PUSH_NUMBER(L, "type",        cd.type);
	HSTR_PUSH_STRING(L, "name",        cd.name);
	HSTR_PUSH_STRING(L, "action",      cd.action);
	HSTR_PUSH_STRING(L, "tooltip",     cd.tooltip);
	HSTR_PUSH_STRING(L, "texture",     cd.iconname);
	HSTR_PUSH_STRING(L, "cursor",      cd.mouseicon);
	HSTR_PUSH_BOOL(L,   "hidden",      cd.hidden);
	HSTR_PUSH_BOOL(L,   "disabled",    cd.disabled);
	HSTR_PUSH_BOOL(L,   "showUnique",  cd.showUnique);
	HSTR_PUSH_BOOL(L,   "onlyTexture", cd.onlyTexture);

	HSTR_PUSH(L, "params");

	lua_createtable(L, 0, numParams);

	for (int p = 0; p < numParams; p++) {
		lua_pushsstring(L, cd.params[p]);
		lua_rawseti(L, -2, p + 1);
	}

	// CmdDesc["params"] = {[1] = "string1", [2] = "string2", ...}
	lua_settable(L, -3);
}
Exemple #2
0
int LuaUICommand::GetUICommands(lua_State* L) 
{
	SyncedGameCommands::actionExecutorsMap_t syncedExecutors = syncedGameCommands->GetActionExecutors();
	UnsyncedGameCommands::actionExecutorsMap_t unsyncedExecutors = unsyncedGameCommands->GetActionExecutors();
	
	int count = 0;
	lua_createtable(L, syncedExecutors.size() + unsyncedExecutors.size(), 0);
	for (SyncedGameCommands::actionExecutorsMap_t::iterator iter = syncedExecutors.begin(); iter != syncedExecutors.end(); ++iter) {
		lua_createtable(L, 0, 4);
		ISyncedActionExecutor* exec = iter->second;
		HSTR_PUSH_STRING(L, "command",     exec->GetCommand());
		HSTR_PUSH_STRING(L, "description", exec->GetDescription());
		HSTR_PUSH_BOOL(L,   "synced",      exec->IsSynced());
		HSTR_PUSH_BOOL(L,   "cheat",       exec->IsCheatRequired());
		lua_rawseti(L, -2, count++);
	}
	for (UnsyncedGameCommands::actionExecutorsMap_t::iterator iter = unsyncedExecutors.begin(); iter != unsyncedExecutors.end(); ++iter) {
		lua_createtable(L, 0, 4);
		IUnsyncedActionExecutor* exec = iter->second;
		HSTR_PUSH_STRING(L, "command",     exec->GetCommand());
		HSTR_PUSH_STRING(L, "description", exec->GetDescription());
		HSTR_PUSH_BOOL(L,   "synced",      exec->IsSynced());
		HSTR_PUSH_BOOL(L,   "cheat",       exec->IsCheatRequired());
		lua_rawseti(L, -2, count++);
	}
	return 1;
}
Exemple #3
0
int LuaArchive::GetAvailableAIs(lua_State* L)
{
	const std::string gameArchivePath = GetFileName(luaL_optsstring(L, 1, ""));
	const std::string mapArchivePath = GetFileName(luaL_optsstring(L, 2, ""));

	// load selected archives to get lua ais
	if (!gameArchivePath.empty()) {
		vfsHandler->AddArchive(gameArchivePath, false);
	}
	if (!mapArchivePath.empty()) {
		vfsHandler->AddArchive(mapArchivePath, false);
	}

	const IAILibraryManager::T_skirmishAIKeys& skirmishAIKeys = aiLibManager->GetSkirmishAIKeys();
	std::vector< std::vector<InfoItem> > luaAIInfos = luaAIImplHandler.LoadInfos();	

	lua_createtable(L, skirmishAIKeys.size() + luaAIInfos.size(), 0);
	unsigned int count = 0;

	for(int i=0; i<luaAIInfos.size(); i++) {
		lua_newtable(L); {
			for (int j=0; j<luaAIInfos[i].size(); j++) {
				if (luaAIInfos[i][j].key==SKIRMISH_AI_PROPERTY_SHORT_NAME) {
					HSTR_PUSH_STRING(L, "shortName", luaAIInfos[i][j].GetValueAsString());
				} else if (luaAIInfos[i][j].key==SKIRMISH_AI_PROPERTY_VERSION) {
					HSTR_PUSH_STRING(L, "version", luaAIInfos[i][j].GetValueAsString());
				}
			}
		}
		lua_rawseti(L, -2, ++count);
	}
	
	// close archives
	if (!mapArchivePath.empty()) {
		vfsHandler->RemoveArchive(mapArchivePath);
	}
	if (!gameArchivePath.empty()) {
		vfsHandler->RemoveArchive(gameArchivePath);
	}
	
	IAILibraryManager::T_skirmishAIKeys::const_iterator i = skirmishAIKeys.begin();
	IAILibraryManager::T_skirmishAIKeys::const_iterator e = skirmishAIKeys.end();

	for (; i != e; ++i) {
		lua_newtable(L); {
			HSTR_PUSH_STRING(L, "shortName", i->GetShortName());
			HSTR_PUSH_STRING(L, "version", i->GetVersion());
		}
		lua_rawseti(L, -2, ++count);
	}
	
	return 1;
}
Exemple #4
0
static int ModelTable(lua_State* L, const void* data) {
	const UnitDef* ud = static_cast<const UnitDef*>(data);
	const std::string modelFile = modelParser->FindModelPath(ud->modelName);

	lua_newtable(L);
	HSTR_PUSH_STRING(L, "type", StringToLower(FileSystem::GetExtension(modelFile)));
	HSTR_PUSH_STRING(L, "path", modelFile);
	HSTR_PUSH_STRING(L, "name", ud->modelName);
	HSTR_PUSH(L, "textures");

	lua_newtable(L);
	if (ud->model != NULL) {
		LuaPushNamedString(L, "tex1", ud->model->tex1);
		LuaPushNamedString(L, "tex2", ud->model->tex2);
	}
	lua_rawset(L, -3);
	return 1;
}
Exemple #5
0
static int MoveDefTable(lua_State* L, const void* data)
{
	const unsigned int mdType = *static_cast<const unsigned int*>(data);
	const MoveDef* md = NULL;

	lua_newtable(L);
	if (mdType == -1U) {
		return 1;
	}
	if ((md = moveDefHandler->GetMoveDefByPathType(mdType)) == NULL) {
		return 1;
	}

	HSTR_PUSH_NUMBER(L, "id", md->pathType);

	switch (md->speedModClass) {
		case MoveDef::Tank:  { HSTR_PUSH_STRING(L, "family", "tank");  HSTR_PUSH_STRING(L, "type", "ground"); break; }
		case MoveDef::KBot:  { HSTR_PUSH_STRING(L, "family", "kbot");  HSTR_PUSH_STRING(L, "type", "ground"); break; }
		case MoveDef::Hover: { HSTR_PUSH_STRING(L, "family", "hover"); HSTR_PUSH_STRING(L, "type",  "hover"); break; }
		case MoveDef::Ship:  { HSTR_PUSH_STRING(L, "family", "ship");  HSTR_PUSH_STRING(L, "type",   "ship"); break; }
	}

	HSTR_PUSH_NUMBER(L, "xsize",         md->xsize);
	HSTR_PUSH_NUMBER(L, "zsize",         md->zsize);
	HSTR_PUSH_NUMBER(L, "depth",         md->depth);
	HSTR_PUSH_NUMBER(L, "maxSlope",      md->maxSlope);
	HSTR_PUSH_NUMBER(L, "slopeMod",      md->slopeMod);
	HSTR_PUSH_NUMBER(L, "depthMod",      md->depthModParams[MoveDef::DEPTHMOD_LIN_COEFF]);
	HSTR_PUSH_NUMBER(L, "crushStrength", md->crushStrength);

	HSTR_PUSH_BOOL(L, "heatMapping",     md->heatMapping);
	HSTR_PUSH_NUMBER(L, "heatMod",       md->heatMod);
	HSTR_PUSH_NUMBER(L, "heatProduced",  md->heatProduced);

	HSTR_PUSH_STRING(L, "name", md->name);

	return 1;
}
static int GuiSoundSetTable(lua_State* L, const void* data)
{
	const GuiSoundSet& soundSet = *((const GuiSoundSet*) data);
	const int soundCount = (int)soundSet.sounds.size();
	lua_newtable(L);
	for (int i = 0; i < soundCount; i++) {
		lua_pushnumber(L, i + 1);
		lua_newtable(L);
		const GuiSoundSet::Data& sound = soundSet.sounds[i];
		HSTR_PUSH_STRING(L, "name",   sound.name);
		HSTR_PUSH_NUMBER(L, "volume", sound.volume);
		if (!CLuaHandle::GetSynced(L)) {
			HSTR_PUSH_NUMBER(L, "id", sound.id);
		}
		lua_rawset(L, -3);
	}
	return 1;
}
Exemple #7
0
static void PushGuiSoundSet(lua_State* L, const string& name,
                            const GuiSoundSet& soundSet)
{
	const int soundCount = (int)soundSet.sounds.size();
	lua_pushsstring(L, name);
	lua_newtable(L);
	for (int i = 0; i < soundCount; i++) {
		lua_pushnumber(L, i + 1);
		lua_newtable(L);
		const GuiSoundSet::Data& sound = soundSet.sounds[i];
		HSTR_PUSH_STRING(L, "name",   sound.name);
		HSTR_PUSH_NUMBER(L, "volume", sound.volume);
		if (!CLuaHandle::GetHandleSynced(L)) {
			HSTR_PUSH_NUMBER(L, "id", sound.id);
		}
		lua_rawset(L, -3);
	}
	lua_rawset(L, -3);
}
static int VisualsTable(lua_State* L, const void* data)
{
	const struct WeaponDef::Visuals& v =
		*((const struct WeaponDef::Visuals*)data);
	lua_newtable(L);
	HSTR_PUSH_STRING(L, "modelName",      v.modelName);
	HSTR_PUSH_NUMBER(L, "colorR",         v.color.x);
	HSTR_PUSH_NUMBER(L, "colorG",         v.color.y);
	HSTR_PUSH_NUMBER(L, "colorB",         v.color.z);
	HSTR_PUSH_NUMBER(L, "color2R",        v.color2.x);
	HSTR_PUSH_NUMBER(L, "color2G",        v.color2.y);
	HSTR_PUSH_NUMBER(L, "color2B",        v.color2.z);
	HSTR_PUSH_BOOL  (L, "smokeTrail",     v.smokeTrail);
	HSTR_PUSH_BOOL  (L, "beamWeapon",     v.beamweapon);
	HSTR_PUSH_NUMBER(L, "tileLength",     v.tilelength);
	HSTR_PUSH_NUMBER(L, "scrollSpeed",    v.scrollspeed);
	HSTR_PUSH_NUMBER(L, "pulseSpeed",     v.pulseSpeed);
	HSTR_PUSH_NUMBER(L, "laserFlareSize", v.laserflaresize);
	HSTR_PUSH_NUMBER(L, "thickness",      v.thickness);
	HSTR_PUSH_NUMBER(L, "coreThickness",  v.corethickness);
	HSTR_PUSH_NUMBER(L, "beamDecay",      v.beamdecay);
	HSTR_PUSH_NUMBER(L, "stages",         v.stages);
	HSTR_PUSH_NUMBER(L, "sizeDecay",      v.sizeDecay);
	HSTR_PUSH_NUMBER(L, "alphaDecay",     v.alphaDecay);
	HSTR_PUSH_NUMBER(L, "separation",     v.separation);
	HSTR_PUSH_BOOL  (L, "noGap",          v.noGap);

	HSTR_PUSH_BOOL  (L, "alwaysVisible", v.alwaysVisible);

	return 1;
//	CColorMap *colorMap;
//	AtlasedTexture *texture1;
//	AtlasedTexture *texture2;
//	AtlasedTexture *texture3;
//	AtlasedTexture *texture4;
}