added GetCurAmmoType to lua
authorHenek
Wed, 16 Mar 2011 17:25:05 +0100
changeset 5013 04789ba3f200
parent 5012 8767878e08e2
child 5014 adc340265ccf
added GetCurAmmoType to lua
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uGears.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
--- a/hedgewars/GSHandlers.inc	Mon Mar 14 20:08:53 2011 +0300
+++ b/hedgewars/GSHandlers.inc	Wed Mar 16 17:25:05 2011 +0100
@@ -4624,59 +4624,13 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-procedure doStepPlaceStructure(Gear: PGear);
-var 
-    HHGear: PGear;
-    x, y, tx, ty: hwFloat;
-begin
-    AllInactive := false;
-
-    HHGear := Gear^.Hedgehog^.Gear;
-    tx := int2hwFloat(TargetPoint.X);
-    ty := int2hwFloat(TargetPoint.Y);
-    x := HHGear^.X;
-    y := HHGear^.Y;
-
-    if (Distance(tx - x, ty - y) > _256) or
-       not TryPlaceOnLand(TargetPoint.X - SpritesData[sprAmGirder].Width div 2,
-       TargetPoint.Y - SpritesData[sprAmGirder].Height div 2,
-       sprAmGirder, Gear^.State, true, false) then
-    begin
-        PlaySound(sndDenied);
-        HHGear^.Message := HHGear^.Message and not gmAttack;
-        HHGear^.State := HHGear^.State and not gstAttacking;
-        HHGear^.State := HHGear^.State or gstHHChooseTarget;
-        isCursorVisible := true;
-        DeleteGear(Gear)
-    end
-    else 
-    begin
-        PlaySound(sndPlaced);
-        DeleteGear(Gear);
-        AfterAttack;
-    end;
-
-    HHGear^.State := HHGear^.State and not (gstAttacking or gstAttacked);
-    HHGear^.Message := HHGear^.Message and not gmAttack;
-    TargetPoint.X := NoPointX
-end;
-
 procedure doStepStructure(Gear: PGear);
 var 
     i, x, y: LongInt;
     dX, dY: HWFloat;
     hog: PHedgehog;
 begin
-    if Gear^.Hedgehog <> nil then
-        if Gear^.Tag = 0 then
-        begin
-            hog:= Gear^.Hedgehog;
-            hog^.GearHidden:= hog^.Gear;
-            RemoveGearFromList(hog^.Gear);
-            hog^.Gear:= nil;
-            Gear^.Tag:= TotalRounds + 3;
-        end
-        else if Gear^.Tag = TotalRounds then
+    if (Gear^.Hedgehog <> nil) and (Gear^.Tag = TotalRounds) then
         begin
             hog:= Gear^.Hedgehog;
             hog^.Gear:= hog^.GearHidden;
@@ -4689,29 +4643,6 @@
             Gear^.Hedgehog:= nil;
         end;
 
-    if (Gear^.dY.QWordValue <> 0) or (not TestCollisionYwithGear(Gear, 1)) then
-    begin
-        AllInactive := false;
-        Gear^.dY := Gear^.dY + cGravity;
-        Gear^.Y := Gear^.Y + Gear^.dY;
-        if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then SetAllHHToActive;
-        if (Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, -1) then Gear^.dY := _0;
-        if (not Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, 1) then
-        begin
-            if Gear^.dY > _0_2 then
-                for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do
-                    AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
-            Gear^.dY := - Gear^.dY * Gear^.Elasticity;
-            if Gear^.dY > - _0_001 then Gear^.dY := _0
-            else if Gear^.dY < - _0_03 then
-                    PlaySound(Gear^.ImpactSound);
-        end;
-        CheckGearDrowning(Gear);
-    end;
-
-    if (Gear^.dY.QWordValue = 0) then AddGearCI(Gear)
-    else if (Gear^.dY.QWordValue <> 0) then DeleteCI(Gear);
-
     dec(Gear^.Health, Gear^.Damage);
     Gear^.Damage := 0;
 
@@ -4737,3 +4668,50 @@
     end;
 end;
 
+procedure doStepPlaceStructure(Gear: PGear);
+var 
+    hog: PHedgehog;
+    HHGear: PGear;
+    x, y, tx, ty: hwFloat;
+begin
+    AllInactive := false;
+
+    HHGear := Gear^.Hedgehog^.Gear;
+    tx := int2hwFloat(TargetPoint.X);
+    ty := int2hwFloat(TargetPoint.Y);
+    x := HHGear^.X;
+    y := HHGear^.Y;
+
+    HHGear := Gear^.Hedgehog^.Gear;
+    if (Distance(tx - x, ty - y) > _256) or
+       not TryPlaceOnLand(TargetPoint.X - SpritesData[sprHHTelepMask].Width div 2,
+       TargetPoint.Y - SpritesData[sprHHTelepMask].Height div 2,
+       sprHHTelepMask, 0, false, false) then
+    begin
+        HHGear^.Message := HHGear^.Message and not gmAttack;
+        HHGear^.State := HHGear^.State and not gstAttacking;
+        HHGear^.State := HHGear^.State or gstHHChooseTarget;
+        DeleteGear(Gear);
+        isCursorVisible := true;
+        PlaySound(sndDenied)
+    end
+    else
+    begin
+        DeleteCI(HHGear);
+        SetAllHHToActive;
+        PlaySound(sndPlaced);
+        CurAmmoGear:= nil;
+        AfterAttack;
+        Gear^.X := tx;
+        Gear^.Y := ty;
+        Gear^.Tag := TotalRounds + Gear^.Tag;
+        hog:= CurrentHedgehog;
+        hog^.GearHidden:= hog^.Gear;
+        RemoveGearFromList(hog^.Gear);
+        hog^.Gear:= nil;
+        Gear^.Hedgehog := hog;
+        Gear^.doStep := @doStepStructure;
+    end;
+    TargetPoint.X := NoPointX;
+end;
+
--- a/hedgewars/HHHandlers.inc	Mon Mar 14 20:08:53 2011 +0300
+++ b/hedgewars/HHHandlers.inc	Wed Mar 16 17:25:05 2011 +0100
@@ -315,10 +315,7 @@
                     end;
                    amDrillStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 3, _0, _0, CurWeapon^.Timer);
                    //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
-                     amStructure: begin
-                                  FollowGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, 0, SignAs(_0_03, dX), _0, 0);
-                                  FollowGear^.Hedgehog:= Gear^.Hedgehog;
-                                  end;
+                     amStructure: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtStructure, 0, _0, _0, 0);
                   end;
 
         // Clear FollowGear if using on a rope/parachute/saucer etc so focus stays with the hog's movement
--- a/hedgewars/uGears.pas	Mon Mar 14 20:08:53 2011 +0300
+++ b/hedgewars/uGears.pas	Wed Mar 16 17:25:05 2011 +0100
@@ -129,7 +129,7 @@
             @doStepNapalmBomb,
             @doStepSnowball,
             @doStepSnowflake,
-            @doStepStructure
+            @doStepPlaceStructure
             );
 
 procedure InsertGearToList(Gear: PGear);
@@ -519,6 +519,7 @@
                 gear^.Radius:= 13;
                 gear^.Elasticity:= _0_3;
                 gear^.Health:= 50;
+                gear^.Tag:= 3;
                 end;
     end;
 
--- a/hedgewars/uScript.pas	Mon Mar 14 20:08:53 2011 +0300
+++ b/hedgewars/uScript.pas	Wed Mar 16 17:25:05 2011 +0100
@@ -1285,6 +1285,16 @@
             sprAmGirder, lua_tointeger(L, 3), true, false);
     lc_placegirder:= 0
 end;
+
+function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
+var gear : PGear;
+begin
+    if lua_gettop(L) <> 0 then
+        LuaError('Lua: Wrong number of parameters passed to GetCurAmmoType!')
+    else
+        lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
+    lc_getcurammotype := 1;
+end;
 ///////////////////
 
 procedure ScriptPrintStack;
@@ -1705,6 +1715,7 @@
 lua_register(luaState, 'GetHogHat', @lc_gethoghat);
 lua_register(luaState, 'SetHogHat', @lc_sethoghat);
 lua_register(luaState, 'PlaceGirder', @lc_placegirder);
+lua_register(luaState, 'GetCurAmmoType', @lc_getcurammotype);
 
 
 ScriptClearStack; // just to be sure stack is empty
--- a/hedgewars/uVariables.pas	Mon Mar 14 20:08:53 2011 +0300
+++ b/hedgewars/uVariables.pas	Wed Mar 16 17:25:05 2011 +0100
@@ -2058,7 +2058,12 @@
             NameTex: nil;
             Probability: 0;
             NumberInCase: 1;
-            Ammo: (Propz: ammoprop_NoCrosshair or ammoprop_DontHold or ammoprop_Utility;
+            Ammo: (Propz: ammoprop_ForwMsgs or
+                          ammoprop_NoCrosshair or
+                          ammoprop_NeedTarget or
+                          ammoprop_AttackingPut or
+                          ammoprop_Utility or
+                          ammoprop_DontHold;
                 Count: 1;
                 NumPerTurn: 0;
                 Timer: 0;
@@ -2071,8 +2076,8 @@
             maxAngle: 0;
             isDamaging: false;
             SkipTurns: 0;
-            PosCount: 1;
-            PosSprite: sprWater;
+            PosCount: 2;
+            PosSprite: sprAmTeleport;
             ejectX: 0;
             ejectY: 0)
         );