# HG changeset patch # User nemo # Date 1309312108 14400 # Node ID 7f57d0c7816ae05091a7c28e83ec5c4b9c1367a3 # Parent ce527b35d063e27297d96b0697f5fb2e1c7ddec6 Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend diff -r ce527b35d063 -r 7f57d0c7816a QTfrontend/gamecfgwidget.cpp --- a/QTfrontend/gamecfgwidget.cpp Tue Jun 28 19:16:42 2011 -0400 +++ b/QTfrontend/gamecfgwidget.cpp Tue Jun 28 21:48:28 2011 -0400 @@ -229,6 +229,20 @@ QList bcfg; int mapgen = pMapContainer->get_mapgen(); + QString currentMap = pMapContainer->getCurrentMap(); + if (currentMap.size() > 0) + { + bcfg << QString("emap " + currentMap).toUtf8(); + if(pMapContainer->getCurrentIsMission()) + bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8(); + } + bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8(); + + if (Scripts->currentIndex() > 0) + { + bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8(); + } + bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8(); bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8(); bcfg << QString("e$damagepct %1").arg(schemeData(25).toInt()).toUtf8(); @@ -270,20 +284,6 @@ default: ; } - QString currentMap = pMapContainer->getCurrentMap(); - if (currentMap.size() > 0) - { - bcfg << QString("emap " + currentMap).toUtf8(); - if(pMapContainer->getCurrentIsMission()) - bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8(); - } - bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8(); - - if (Scripts->currentIndex() > 0) - { - bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8(); - } - QByteArray result; foreach(QByteArray ba, bcfg) diff -r ce527b35d063 -r 7f57d0c7816a hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Tue Jun 28 19:16:42 2011 -0400 +++ b/hedgewars/uCommandHandlers.pas Tue Jun 28 21:48:28 2011 -0400 @@ -445,7 +445,7 @@ procedure chSetMap(var s: shortstring); begin -if isDeveloperMode then +if isDeveloperMode and (s <> '') then begin UserPathz[ptMapCurrent]:= UserPathz[ptMaps] + '/' + s; Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s; diff -r ce527b35d063 -r 7f57d0c7816a hedgewars/uCommands.pas --- a/hedgewars/uCommands.pas Tue Jun 28 19:16:42 2011 -0400 +++ b/hedgewars/uCommands.pas Tue Jun 28 21:48:28 2011 -0400 @@ -33,7 +33,7 @@ procedure StopMessages(Message: Longword); implementation -uses Types, uConsts, uVariables, uConsole, uUtils, uDebug; +uses Types, uConsts, uVariables, uConsole, uUtils, uDebug, uScript; type PVariable = ^TVariable; TVariable = record @@ -68,7 +68,7 @@ procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); var ii: LongInt; - s: shortstring; + s, i, o: shortstring; t: PVariable; c: char; begin @@ -85,6 +85,8 @@ if t^.Name = CmdStr then begin if TrustedSource or t^.Trusted then + begin + if (c <> '$') or (s[0] <> #0) then s:= ParseCommandOverride(CmdStr, s); case t^.VType of vtCommand: if c='/' then begin @@ -94,8 +96,12 @@ if s[0]=#0 then begin str(PLongInt(t^.Handler)^, s); - WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); - end else val(s, PLongInt(t^.Handler)^); + i:= inttostr(PLongInt(t^.Handler)^); + o:= ParseCommandOverride(CmdStr, i); + if i <> o then val(o, PLongInt(t^.Handler)^) + else WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); + end + else val(s, PLongInt(t^.Handler)^); vthwFloat: if c='$' then if s[0]=#0 then begin @@ -106,13 +112,23 @@ if s[0]=#0 then begin str(ord(boolean(t^.Handler^)), s); - WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); - end else + if boolean(t^.Handler^) then i:= '1' + else i:= '0'; + o:= ParseCommandOverride(CmdStr, i); + if i <> o then + begin + val(o, ii); + boolean(t^.Handler^):= not (ii = 0) + end + else WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); + end + else begin val(s, ii); boolean(t^.Handler^):= not (ii = 0) end; end; + end; exit end else t:= t^.Next end; diff -r ce527b35d063 -r 7f57d0c7816a hedgewars/uScript.pas --- a/hedgewars/uScript.pas Tue Jun 28 19:16:42 2011 -0400 +++ b/hedgewars/uScript.pas Tue Jun 28 21:48:28 2011 -0400 @@ -43,6 +43,7 @@ function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; function ScriptExists(fname : shortstring) : boolean; +function ParseCommandOverride(key, value : shortstring) : shortstring; procedure initModule; procedure freeModule; @@ -1588,6 +1589,25 @@ GetGlobals; end; +function ParseCommandOverride(key, value : shortstring) : shortstring; +begin +ParseCommandOverride:= value; +if not ScriptExists('ParseCommandOverride') then exit; +lua_getglobal(luaState, Str2PChar('ParseCommandOverride')); +lua_pushstring(luaState, Str2PChar(key)); +lua_pushstring(luaState, Str2PChar(value)); +if lua_pcall(luaState, 2, 1, 0) <> 0 then + begin + LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1)); + lua_pop(luaState, 1) + end +else + begin + ParseCommandOverride:= lua_tostring(luaState, -1); + lua_pop(luaState, 1) + end; +end; + function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; begin ScriptCall:= ScriptCall(fname, par1, 0, 0, 0) @@ -1669,14 +1689,23 @@ end; procedure ScriptApplyAmmoStore; -var i : LongInt; +var i, j : LongInt; begin SetAmmoLoadout(ScriptAmmoLoadout); SetAmmoProbability(ScriptAmmoProbability); SetAmmoDelay(ScriptAmmoDelay); SetAmmoReinforcement(ScriptAmmoReinforcement); -for i:= 0 to Pred(TeamsCount) do - AddAmmoStore; + +if (GameFlags and gfSharedAmmo) <> 0 then + for i:= 0 to Pred(ClansCount) do + AddAmmoStore +else if (GameFlags and gfPerHogAmmo) <> 0 then + for i:= 0 to Pred(TeamsCount) do + for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do + AddAmmoStore +else + for i:= 0 to Pred(TeamsCount) do + AddAmmoStore end; procedure initModule; diff -r ce527b35d063 -r 7f57d0c7816a share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua --- a/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Tue Jun 28 19:16:42 2011 -0400 +++ b/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Tue Jun 28 21:48:28 2011 -0400 @@ -46,7 +46,7 @@ function onGameInit() -- Limit flags that can be set, but allow game schemes to be used - GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo)) + GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack)) -- Set a custom game goal that will show together with the scheme ones Goals = loc("Each turn you get one random weapon") end