Engine:
* Fixed reading localized strings longer than 255 bytes
* Fixed weapon tooltip to stay inside visible area in short ammo menus
* Allow maps to use their own map.lua file outside training mode (needs multiplayer testing)
* Added example script to Basketball map showing clan scores
* Fixed Shotgun and Bazooka trainings
* Removed basketball script example
--- a/QTfrontend/gamecfgwidget.cpp Mon Mar 15 02:23:40 2010 +0000
+++ b/QTfrontend/gamecfgwidget.cpp Mon Mar 15 11:53:32 2010 +0000
@@ -158,7 +158,15 @@
QString currentMap = pMapContainer->getCurrentMap();
if (currentMap.size() > 0)
+ {
sl.append("emap " + currentMap);
+ QFile mapLuaFile(
+ QString("%1/Maps/%2/map.lua")
+ .arg(datadir->absolutePath())
+ .arg(currentMap));
+ if(mapLuaFile.exists())
+ sl.append(QString("escript %1").arg(mapLuaFile.fileName()));
+ }
sl.append("etheme " + pMapContainer->getCurrentTheme());
return sl;
}
--- a/hedgewars/uLocale.pas Mon Mar 15 02:23:40 2010 +0000
+++ b/hedgewars/uLocale.pas Mon Mar 15 11:53:32 2010 +0000
@@ -63,7 +63,7 @@
trevt_n: array[TEventId] of integer;
procedure LoadLocale(FileName: shortstring);
-var s: shortstring;
+var s: ansistring;
f: textfile;
a, b, c: LongInt;
first: array[TEventId] of boolean;
--- a/hedgewars/uScript.pas Mon Mar 15 02:23:40 2010 +0000
+++ b/hedgewars/uScript.pas Mon Mar 15 11:53:32 2010 +0000
@@ -32,6 +32,7 @@
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
+function ScriptExists(fname : shortstring) : boolean;
procedure init_uScript;
procedure free_uScript;
@@ -145,10 +146,54 @@
gear:= GearByUID(lua_tointeger(L, 1));
if gear <> nil then
lua_pushinteger(L, ord(gear^.Kind))
+ else
+ lua_pushnil(L);
end;
lc_getgeartype:= 1
end;
+function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+ if lua_gettop(L) <> 1 then
+ begin
+ WriteLnToConsole('LUA: Wrong number of parameters passed to GetHogClan!');
+ lua_pushnil(L); // return value on stack (nil)
+ end
+ else
+ begin
+ gear:= GearByUID(lua_tointeger(L, 1));
+ if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
+ begin
+ lua_pushinteger(L, PHedgehog(gear^.Hedgehog)^.Team^.Clan^.ClanIndex)
+ end
+ else
+ lua_pushnil(L);
+ end;
+ lc_gethogclan:= 1
+end;
+
+function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+ if lua_gettop(L) <> 1 then
+ begin
+ WriteLnToConsole('LUA: Wrong number of parameters passed to GetHogName!');
+ lua_pushnil(L); // return value on stack (nil)
+ end
+ else
+ begin
+ gear:= GearByUID(lua_tointeger(L, 1));
+ if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
+ begin
+ lua_pushstring(L, str2pchar(PHedgehog(gear^.Hedgehog)^.Name))
+ end
+ else
+ lua_pushnil(L);
+ end;
+ lc_gethogname:= 1
+end;
+
function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
var gear : PGear;
begin
@@ -338,7 +383,7 @@
// not required if there's no script to run
if not ScriptLoaded then
exit;
-
+
// push game variables so they may be modified by the script
ScriptSetInteger('GameFlags', GameFlags);
ScriptSetString('Seed', cSeed);
@@ -370,9 +415,14 @@
if ScriptGetString('Theme') <> '' then
ParseCommand('theme ' + ScriptGetString('Theme'), true);
-ScriptPrepareAmmoStore;
-ScriptCall('onAmmoStoreInit');
-ScriptApplyAmmoStore;
+if ScriptExists('onAmmoStoreInit') then
+ begin
+ ScriptPrepareAmmoStore;
+ ScriptCall('onAmmoStoreInit');
+ ScriptApplyAmmoStore
+ end;
+
+ScriptSetInteger('ClansCount', ClansCount)
end;
procedure ScriptLoad(name : shortstring);
@@ -402,7 +452,7 @@
procedure ScriptCall(fname : shortstring);
begin
-if not ScriptLoaded then
+if not ScriptLoaded or not ScriptExists(fname) then
exit;
SetGlobals;
lua_getglobal(luaState, Str2PChar(fname));
@@ -431,7 +481,7 @@
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
begin
-if not ScriptLoaded then
+if not ScriptLoaded or not ScriptExists(fname) then
exit;
SetGlobals;
lua_getglobal(luaState, Str2PChar(fname));
@@ -453,9 +503,24 @@
GetGlobals;
end;
+function ScriptExists(fname : shortstring) : boolean;
+begin
+if not ScriptLoaded then
+ begin
+ ScriptExists:= false;
+ exit
+ end;
+lua_getglobal(luaState, Str2PChar(fname));
+ScriptExists:= not lua_isnoneornil(luaState, -1);
+lua_pop(luaState, -1)
+end;
+
procedure ScriptPrepareAmmoStore;
var i: ShortInt;
begin
+// reset ammostore (quite unclean, but works?)
+free_uAmmos;
+init_uAmmos;
ScriptAmmoStore:= '';
for i:=1 to ord(High(TAmmoType)) do
ScriptAmmoStore:= ScriptAmmoStore + '0000';
@@ -560,6 +625,8 @@
lua_register(luaState, 'AddTeam', @lc_addteam);
lua_register(luaState, 'AddHog', @lc_addhog);
lua_register(luaState, 'SetHealth', @lc_sethealth);
+lua_register(luaState, 'GetHogClan', @lc_gethogclan);
+lua_register(luaState, 'GetHogName', @lc_gethogname);
ScriptClearStack; // just to be sure stack is empty
ScriptLoaded:= false;
@@ -611,6 +678,11 @@
ScriptCall:= 0
end;
+function ScriptExists(fname : shortstring) : boolean;
+begin
+ScriptExists:= false
+end;
+
procedure init_uScript;
begin
end;
--- a/hedgewars/uWorld.pas Mon Mar 15 02:23:40 2010 +0000
+++ b/hedgewars/uWorld.pas Mon Mar 15 11:53:32 2010 +0000
@@ -279,7 +279,7 @@
FreeWeaponTooltip;
if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
- ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, y);
+ ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y, cScreenHeight - WeaponTooltipTex^.h - 40));
bSelected:= false;
if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Maps/Basketball/map.lua Mon Mar 15 11:53:32 2010 +0000
@@ -0,0 +1,79 @@
+-- Hedgewars - Basketball for 2 Players
+
+local caption = {
+ ["en"] = "Hedgewars-Basketball",
+ ["de"] = "Hedgewars-Basketball"
+ }
+
+local subcaption = {
+ ["en"] = "Not So Friendly Match",
+ ["de"] = "Kein-so-Freundschaftsspiel"
+ }
+
+local goal = {
+ ["en"] = "Bat your opponents through the|baskets and out of the map!",
+ ["de"] = "Schlage deine Widersacher durch|die Körbe und aus der Karte hinaus!"
+ }
+
+local scored = {
+ ["en"] = " scored a point!",
+ ["de"] = " erhält einen Punkt!"
+ }
+
+local sscore = {
+ ["en"] = "Score",
+ ["de"] = "Punktestand"
+ }
+
+local team = {
+ ["en"] = "Team"
+ }
+
+local drowning = {
+ ["en"] = "is out and",
+ ["de"] = "ist draußen und"
+ }
+
+local function loc(text)
+ if text == nil then return "**missing**"
+ elseif text[L] == nil then return text["en"]
+ else return text[L]
+ end
+end
+
+---------------------------------------------------------------
+
+local score = {[0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0}
+
+function onGameInit()
+ GameFlags = gfSolidLand + gfBorder + gfInvulnerable + gfRandomOrder + gfLowGravity
+ TurnTime = 20000
+ CaseFreq = 0
+ LandAdds = 0
+ Explosives = 0
+ Delay = 0
+end
+
+function onGameStart()
+ ShowMission(loc(caption), loc(subcaption), loc(goal), -amBaseballBat, 0);
+end
+
+function onGameTick()
+end
+
+function onAmmoStoreInit()
+ SetAmmo(amBaseballBat, 9, 0, 0)
+end
+
+function onGearAdd(gear)
+end
+
+function onGearDelete(gear)
+ if GetGearType(gear) == gtHedgehog then
+ local clan = GetHogClan(gear)
+ score[clan] = score[clan] + 1
+ local s = loc(sscore) .. ": " .. score[0]
+ for i = 1, ClansCount - 1 do s = s .. " - " .. score[i] end
+ ShowMission(loc(caption), loc(subcaption), GetHogName(gear) .. " " .. loc(drowning) .. "|" .. loc(team) .. " " .. (clan + 1) .. " " .. loc(scored) .. "| |" .. s, -amBaseballBat, 0)
+ end
+end
--- a/share/hedgewars/Data/Missions/Basketball - 2 Players.hwt Mon Mar 15 02:23:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
--- Hedgewars - Basketball for 2 Players
-
-local caption = {
- ["en"] = "Hedgewars-Basketball",
- ["de"] = "Hedgewars-Basketball"
- }
-
-local subcaption = {
- ["en"] = "2 Player Match",
- ["de"] = "2-Spieler-Turnier"
- }
-
-local goal = {
- ["en"] = "Bat your opponents through the|baskets and out of the map!",
- ["de"] = "Schlage deine Widersacher durch|die Körbe und aus der Karte hinaus!"
- }
-
-local scored = {
- ["en"] = " scored a point!",
- ["de"] = " haben gepunktet!"
- }
-
-local sscore = {
- ["en"] = "Score",
- ["de"] = "Punktestand"
- }
-
- local teams = {}
-teams[0] = {
- ["en"] = "The Hogville Wizards",
- ["de"] = "Die Igeldorf-Zauberer"
- }
-teams[1] = {
- ["en"] = "The Hogmore Ravens",
- ["de"] = "Die Igelmoor-Raben"
- }
-
-local hognames = {}
-hognames[0] = {"Michael", "Jason", "Mike", "Tom"}
-hognames[1] = {"Diego", "Sam", "Jay", "Hank"}
-
--- To handle missing texts we define a small wrapper function that
--- we'll use to retrieve text.
-local function loc(text)
- if text == nil then return "**missing**"
- elseif text[L] == nil then return text["en"]
- else return text[L]
- end
-end
-
----------------------------------------------------------------
-
-local hogs = {}
-hogs[0] = {nil, nil, nil, nil}
-hogs[1] = {nil, nil, nil, nil}
-
-function onGameInit()
- Seed = 0
- GameFlags = gfSolidLand + gfBorder + gfInvulnerable + gfRandomOrder + gfLowGravity
- TurnTime = 15000
- CaseFreq = 0
- LandAdds = 0
- Explosives = 0
- Delay = 0
- Map = "basketball"
- Theme = "Freeway"
-
- AddTeam(loc(teams[0]), 0xff0000, "Simple", "Island", "Default")
- hogs[0][1] = AddHog(hognames[0][1], 0, 1, "NoHat")
- hogs[0][2] = AddHog(hognames[0][2], 0, 1, "NoHat")
- hogs[0][3] = AddHog(hognames[0][3], 0, 1, "NoHat")
- hogs[0][4] = AddHog(hognames[0][4], 0, 1, "NoHat")
- AddTeam(loc(teams[1]), 0x0000ff, "Simple", "Island", "Default")
- hogs[1][1] = AddHog(hognames[1][1], 0, 1, "NoHat")
- hogs[1][2] = AddHog(hognames[1][2], 0, 1, "NoHat")
- hogs[1][3] = AddHog(hognames[1][3], 0, 1, "NoHat")
- hogs[1][4] = AddHog(hognames[1][4], 0, 1, "NoHat")
-end
-
-function onGameStart()
- ShowMission(loc(caption), loc(subcaption), loc(goal), -amBaseballBat, 0);
-end
-
-function onGameTick()
-end
-
-function onAmmoStoreInit()
- SetAmmo(amBaseballBat, 9, 0, 0)
-end
-
-function onGearAdd(gear)
-end
-
-local score = {0, 0}
-function onGearDelete(gear)
- if gear == hogs[0][1] or gear == hogs[0][2] or gear == hogs[0][3] or gear == hogs[0][4] then
- score[2] = score[2] + 1
- ShowMission(loc(caption), loc(subcaption), loc(teams[1]) .. " " .. loc(scored) .. "|" .. loc(sscore) .. ": " .. score[1] .. " - " .. score[2], -amBaseballBat, 0);
- elseif gear == hogs[1][1] or gear == hogs[1][2] or gear == hogs[1][3] or gear == hogs[1][4] then
- score[1] = score[1] + 1
- ShowMission(loc(caption), loc(subcaption), loc(teams[0]) .. " " .. loc(scored) .. "|" .. loc(sscore) .. ": " .. score[1] .. " - " .. score[2], -amBaseballBat, 0);
- end
-end
\ No newline at end of file
--- a/share/hedgewars/Data/Missions/Bazooka Training.hwt Mon Mar 15 02:23:40 2010 +0000
+++ b/share/hedgewars/Data/Missions/Bazooka Training.hwt Mon Mar 15 11:53:32 2010 +0000
@@ -188,7 +188,7 @@
-- to request the available ammo and probabilities
function onAmmoStoreInit()
-- add an unlimited supply of bazooka ammo
- SetAmmo(amBazooka, 9, 0)
+ SetAmmo(amBazooka, 9, 0, 0)
end
-- This function is called when a new gear is added.
--- a/share/hedgewars/Data/Missions/Shotgun Training.hwt Mon Mar 15 02:23:40 2010 +0000
+++ b/share/hedgewars/Data/Missions/Shotgun Training.hwt Mon Mar 15 11:53:32 2010 +0000
@@ -188,7 +188,7 @@
-- to request the available ammo and probabilities
function onAmmoStoreInit()
-- add an unlimited supply of shotgun ammo
- SetAmmo(amShotgun, 9, 0)
+ SetAmmo(amShotgun, 9, 0, 0)
end
-- This function is called when a new gear is added.