Engine:
* Removed some commented out lines
* Added "SetHealth" script command
* Added support for global variables (between lua and game)
Training Missions:
* Once again fail if your time runs out
* Training missions show a "You've lost!" message
* Changed Shotgun training back to mushrooms map
--- a/hedgewars/uGame.pas Mon Feb 15 21:44:05 2010 +0000
+++ b/hedgewars/uGame.pas Mon Feb 15 21:54:26 2010 +0000
@@ -46,7 +46,7 @@
i:= 1;
while (GameState <> gsExit) and (i <= Lag) do
begin
- ScriptCall('onGameTick');
+ ScriptCall('onGameTick');
if not CurrentTeam^.ExtDriven then
begin
if CurrentHedgehog^.BotLevel <> 0 then ProcessBot;
--- a/hedgewars/uGears.pas Mon Feb 15 21:44:05 2010 +0000
+++ b/hedgewars/uGears.pas Mon Feb 15 21:54:26 2010 +0000
@@ -820,14 +820,8 @@
begin
if not (((Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and ((Gear^.State and gstAttacked) = 0)) then
exit;
-
- //r.x:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) shr 5) * 32;
- //r.y:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) mod 32) * 32;
- //r.w:= 32;
- //r.h:= 32;
- DrawTexture(sx + 16, sy + 16, ropeIconTex);
- //DrawFromRect(sx + 18, sy + 18, @r, SpritesData[sprAMAmmos].Texture);
- DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.75, sx + 30, sy + 30, ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1, 1, 32, 32);
+ DrawTexture(round(sx + 16), round(sy + 16), ropeIconTex);
+ DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.75, round(sx + 30), round(sy + 30), ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1, 1, 32, 32);
end;
end;
--- a/hedgewars/uScript.pas Mon Feb 15 21:44:05 2010 +0000
+++ b/hedgewars/uScript.pas Mon Feb 15 21:54:26 2010 +0000
@@ -149,6 +149,21 @@
lc_getgeartype:= 1
end;
+function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+ if lua_gettop(L) <> 2 then
+ begin
+ WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!');
+ end
+ else
+ begin
+ gear:= GearByUID(lua_tointeger(L, 1));
+ if (gear <> nil) and (gear^.Kind = gtHedgehog) then gear^.Health:= lua_tointeger(L, 2)
+ end;
+ lc_sethealth:= 0
+end;
+
function lc_endgame(L : Plua_State) : LongInt; Cdecl;
begin
GameState:= gsExit;
@@ -367,16 +382,28 @@
end
end;
+procedure SetGlobals;
+begin
+ ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
+end;
+
+procedure GetGlobals;
+begin
+ TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft');
+end;
+
procedure ScriptCall(fname : string);
begin
if not ScriptLoaded then
exit;
+ SetGlobals;
lua_getglobal(luaState, Str2PChar(fname));
if lua_pcall(luaState, 0, 0, 0) <> 0 then
begin
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
lua_pop(luaState, 1)
end;
+ GetGlobals;
end;
function ScriptCall(fname : string; par1: LongInt) : LongInt;
@@ -398,7 +425,7 @@
begin
if not ScriptLoaded then
exit;
-
+ SetGlobals;
lua_getglobal(luaState, Str2PChar(fname));
lua_pushinteger(luaState, par1);
lua_pushinteger(luaState, par2);
@@ -415,6 +442,7 @@
ScriptCall:= lua_tointeger(luaState, -1);
lua_pop(luaState, 1)
end;
+ GetGlobals;
end;
procedure ScriptPrepareAmmoStore;
@@ -516,6 +544,7 @@
lua_register(luaState, 'PlaySound', @lc_playsound);
lua_register(luaState, 'AddTeam', @lc_addteam);
lua_register(luaState, 'AddHog', @lc_addhog);
+lua_register(luaState, 'SetHealth', @lc_sethealth);
ScriptClearStack; // just to be sure stack is empty
ScriptLoaded:= false;
--- a/share/hedgewars/Data/Missions/Bazooka Training.hwt Mon Feb 15 21:44:05 2010 +0000
+++ b/share/hedgewars/Data/Missions/Bazooka Training.hwt Mon Feb 15 21:54:26 2010 +0000
@@ -10,13 +10,18 @@
---------------------------------------------------------------
-- This variable will hold the number of destroyed targets.
-score = 0
+local score = 0
-- This variable represents the number of targets to destroy.
-score_goal = 5
+local score_goal = 5
-- This variable controls how many milliseconds/ticks we'd
-- like to wait before we end the round once all targets
-- have been destroyed.
-end_timer = 5000 -- 5000 ms = 5 s
+local end_timer = 5000 -- 5000 ms = 5 s
+-- This variable is set to true if the game is lost (i.e.
+-- time runs out).
+local game_lost = false
+-- This variable will point to the hog's gear
+local player = nil
-- This is a custom function to make it easier to
-- spawn more targets with just one line of code
@@ -68,8 +73,8 @@
-- Create the player team
AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
-- And add a hog to it
- hog = AddHog("Hunter", 0, 1, "NoHat")
- SetGearPosition(hog, 1960, 1160);
+ player = AddHog("Hunter", 0, 1, "NoHat")
+ SetGearPosition(player, 1960, 1160);
end
-- This function is called when the round starts
@@ -93,8 +98,18 @@
-- You shouldn't try to calculate too complicated
-- code here as this might slow down your game.
function onGameTick()
- -- If the goal is reached ...
- if score == score_goal then
+ -- If time's up, set the game to be lost.
+ -- We actually check the time to be "1 ms" as it
+ -- will be at "0 ms" right at the start of the game.
+ if TurnTimeLeft == 1 then
+ game_lost = true
+ -- ... and show a short message.
+ ShowMission("Bazooka Training", "Aiming Practice", "Oh no! Time's up! Just try again.", -amSkip, 0);
+ -- How about killing our poor hog due to his poor performance?
+ SetHealth(player, 0);
+ end
+ -- If the goal is reached or we've lost ...
+ if score == score_goal or game_lost then
-- ... check to see if the time we'd like to
-- wait has passed and then ...
if end_timer == 0 then
@@ -132,10 +147,12 @@
-- ... spawn another target.
spawnTarget()
else
+ if not game_lost then
-- Otherwise show that the goal was accomplished
ShowMission("Bazooka Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0);
-- Also let the hogs shout "victory!"
PlaySound(sndVictory)
+ end
end
end
end
\ No newline at end of file
--- a/share/hedgewars/Data/Missions/Shotgun Training.hwt Mon Feb 15 21:44:05 2010 +0000
+++ b/share/hedgewars/Data/Missions/Shotgun Training.hwt Mon Feb 15 21:54:26 2010 +0000
@@ -10,13 +10,18 @@
---------------------------------------------------------------
-- This variable will hold the number of destroyed targets.
-score = 0
+local score = 0
-- This variable represents the number of targets to destroy.
-score_goal = 5
+local score_goal = 5
-- This variable controls how many milliseconds/ticks we'd
-- like to wait before we end the round once all targets
-- have been destroyed.
-end_timer = 5000 -- 5000 ms = 5 s
+local end_timer = 5000 -- 5000 ms = 5 s
+-- This variable is set to true if the game is lost (i.e.
+-- time runs out).
+local game_lost = false
+-- This variable will point to the hog's gear
+local player = nil
-- This is a custom function to make it easier to
-- spawn more targets with just one line of code
@@ -53,7 +58,7 @@
-- Game settings and rules
GameFlags = gfMultiWeapon + gfOneClanMode
-- The time the player has to move each round (in ms)
- TurnTime = 90000
+ TurnTime = 25000
-- The frequency of crate drops
CaseFreq = 0
-- The number of land objects being placed
@@ -61,15 +66,15 @@
-- The delay between each round
Delay = 0
-- The map to be played
- Map = "Bamboo"
+ Map = "mushrooms"
-- The theme to be used
- Theme = "Bamboo"
+ Theme = "nature"
-- Create the player team
AddTeam("Shotgun Team", 14483456, "Simple", "Island", "Default")
-- And add a hog to it
- hog = AddHog("Hunter", 0, 1, "NoHat")
- SetGearPosition(hog, 1960, 1160);
+ player = AddHog("Hunter", 0, 1, "NoHat")
+ SetGearPosition(player, 2334, 1254);
end
-- This function is called when the round starts
@@ -93,8 +98,18 @@
-- You shouldn't try to calculate too complicated
-- code here as this might slow down your game.
function onGameTick()
- -- If the goal is reached ...
- if score == score_goal then
+ -- If time's up, set the game to be lost.
+ -- We actually check the time to be "1 ms" as it
+ -- will be at "0 ms" right at the start of the game.
+ if TurnTimeLeft == 1 then
+ game_lost = true
+ -- ... and show a short message.
+ ShowMission("Shotgun Training", "Aiming Practice", "Oh no! Time's up! Just try again.", -amSkip, 0);
+ -- How about killing our poor hog due to his poor performance?
+ SetHealth(player, 0);
+ end
+ -- If the goal is reached or we've lost ...
+ if score == score_goal or game_lost then
-- ... check to see if the time we'd like to
-- wait has passed and then ...
if end_timer == 0 then
@@ -112,8 +127,6 @@
function onAmmoStoreInit()
-- add an unlimited supply of shotgun ammo
SetAmmo(amShotgun, 9, 0)
- -- add one optional laser sight
- SetAmmo(amLaserSight, 1, 0)
end
-- This function is called when a new gear is added.
@@ -134,10 +147,12 @@
-- ... spawn another target.
spawnTarget()
else
+ if not game_lost then
-- Otherwise show that the goal was accomplished
ShowMission("Shotgun Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0);
-- Also let the hogs shout "victory!"
PlaySound(sndVictory)
+ end
end
end
end
\ No newline at end of file