Construction tool
authorunc0rr
Wed, 07 Feb 2007 21:36:55 +0000
changeset 409 4f1841929ccc
parent 408 6c3da4907d00
child 410 586add9f7f3d
Construction tool
hedgewars/CCHandlers.inc
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uAIAmmoTests.pas
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uLandGraphics.pas
hedgewars/uLocale.pas
share/hedgewars/Data/Graphics/amGirder.png
share/hedgewars/Data/Locale/en.txt
share/hedgewars/Data/Locale/ru.txt
--- a/hedgewars/CCHandlers.inc	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Wed Feb 07 21:36:55 2007 +0000
@@ -53,7 +53,7 @@
 if isDeveloperMode then
    begin
    inc(TeamsCount);
-   ParseCommand('ammstore 93919294221912103', true);
+   ParseCommand('ammstore 939192942219121033', true);
    TryDo(TeamsCount <= 5, 'Too many teams', true);
    AddTeam
    end;
--- a/hedgewars/GSHandlers.inc	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Wed Feb 07 21:36:55 2007 +0000
@@ -1059,3 +1059,25 @@
 if (GameTicks and $3F) = 0 then
    AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtSmokeTrace, 0, 0, 0, 0)
 end;
+
+////////////////////////////////////////////////////////////////////////////////
+
+procedure doStepGirder(Gear: PGear);
+begin
+AllInactive:= false;
+writelntoconsole(inttostr(TargetPoint.X));
+if not TryPlaceOnLand(TargetPoint.X - SpritesData[sprAmGirder].Width div 2,
+                      TargetPoint.Y - SpritesData[sprAmGirder].Height div 2,
+                      sprAmGirder, Gear^.State) then
+   with PHedgehog(Gear^.Hedgehog)^.Gear^ do
+        begin
+        State:= State and not gstAttacking;
+        Message:= Message and not gm_Attack;
+        isCursorVisible:= true;
+        with PHedgehog(Gear^.Hedgehog)^ do
+             State:= State or gstHHChooseTarget
+        end
+   else AfterAttack;
+TargetPoint.X:= NoPointX;
+DeleteGear(Gear)
+end;
--- a/hedgewars/HHHandlers.inc	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/HHHandlers.inc	Wed Feb 07 21:36:55 2007 +0000
@@ -72,6 +72,7 @@
                     amAirAttack: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 0, 0, 0, 0);
                    amMineStrike: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 1, 0, 0, 0);
                     amBlowTorch: CurAmmoGear:= AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtBlowTorch, 0, hwSign(Gear^.dX) * _0_5, 0, 0);
+                       amGirder: CurAmmoGear:= AddGear(0, 0, gtGirder, Ammo^[CurSlot, CurAmmo].Pos, 0, 0, 0);
                   end;
         Power:= 0;
         if CurAmmoGear <> nil then
--- a/hedgewars/uAIAmmoTests.pas	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Wed Feb 07 21:36:55 2007 +0000
@@ -46,7 +46,8 @@
 {amParachute}     nil,
 {amAirAttack}     nil,
 {amMineStrike}    nil,
-{amBlowTorch}     nil
+{amBlowTorch}     nil,
+{amGirder}        nil
                   );
 
 const BadTurn = Low(LongInt);
--- a/hedgewars/uConsts.pas	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/uConsts.pas	Wed Feb 07 21:36:55 2007 +0000
@@ -39,14 +39,14 @@
                    sprClusterBomb, sprClusterParticle, sprFlame, sprHorizont,
                    sprSky, sprAMBorders, sprAMSlot, sprAMSlotName, sprAMAmmos,
                    sprAMSlotKeys, sprAMSelection, sprFinger, sprAirBomb,
-                   sprAirplane, sprAmAirplane);
+                   sprAirplane, sprAmAirplane, sprAmGirder);
 
      TGearType  = (gtCloud, gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
                    gtGrave, gtUFO, gtShotgunShot, gtPickHammer, gtRope,
                    gtSmokeTrace, gtExplosion, gtMine, gtCase, gtDEagleShot, gtDynamite,
                    gtTeamHealthSorter, gtClusterBomb, gtCluster, gtShover, gtFlame,
                    gtFirePunch, gtATStartGame, gtATSmoothWindCh, gtATFinishGame,
-                   gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch);
+                   gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch, gtGirder);
 
      TGearsType = set of TGearType;
 
@@ -56,7 +56,8 @@
 
      TAmmoType  = (amGrenade, amClusterBomb, amBazooka, amUFO, amShotgun, amPickHammer,
                    amSkip, amRope, amMine, amDEagle, amDynamite, amFirePunch,
-                   amBaseballBat, amParachute, amAirAttack, amMineStrike, amBlowTorch);
+                   amBaseballBat, amParachute, amAirAttack, amMineStrike, amBlowTorch,
+                   amGirder);
 
      THWFont    = (fnt16, fntBig);
 
@@ -155,7 +156,7 @@
       gm_Destroy= $00000100;
 
       cMaxSlotIndex       = 8;
-      cMaxSlotAmmoIndex   = 1;
+      cMaxSlotAmmoIndex   = 2;
 
       ammoprop_Timerable    = $00000001;
       ammoprop_Power        = $00000002;
@@ -309,7 +310,9 @@
                      (FileName:  'Airplane'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
                      Width: 125; Height: 42; hasAlpha: false),// sprAirplane
                      (FileName:'amAirplane'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
-                     Width:  64; Height: 32; hasAlpha:  true) // sprAmAirplane
+                     Width:  64; Height: 32; hasAlpha:  true),// sprAirplane
+                     (FileName:  'amGirder'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     Width: 128; Height:128; hasAlpha: false) // sprAmGirder
                      );
       Soundz: array[TSound] of record
                                        FileName: String[31];
@@ -597,7 +600,24 @@
                                    TimeAfterTurn: 3000;
                                    minAngle: 768;
                                    maxAngle: 1280;
-                                   PosCount: 1));
+                                   PosCount: 1),
+                                  (NameId: sidGirder;
+                                   Probability: 400;
+                                   NumberInCase: 1;
+                                   Ammo: (Propz: ammoprop_NoCrosshair or
+                                                 ammoprop_NeedTarget or
+                                                 ammoprop_AttackingPut;
+                                          Count: 1;
+                                          NumPerTurn: 0;
+                                          Timer: 0;
+                                          Pos: 0;
+                                          AmmoType: amGirder);
+                                   Slot: 6;
+                                   TimeAfterTurn: 3000;
+                                   minAngle: 0;
+                                   maxAngle: 0;
+                                   PosCount: 4;
+                                   PosSprite: sprAmGirder));
 
 implementation
 
--- a/hedgewars/uGears.pas	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/uGears.pas	Wed Feb 07 21:36:55 2007 +0000
@@ -123,7 +123,8 @@
                                                                @doStepParachute,
                                                                @doStepAirAttack,
                                                                @doStepAirBomb,
-                                                               @doStepBlowTorch
+                                                               @doStepBlowTorch,
+                                                               @doStepGirder
                                                                );
 
 procedure InsertGearToList(Gear: PGear);
--- a/hedgewars/uLandGraphics.pas	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/uLandGraphics.pas	Wed Feb 07 21:36:55 2007 +0000
@@ -18,7 +18,7 @@
 
 unit uLandGraphics;
 interface
-uses uFloat;
+uses uFloat, uConsts;
 {$INCLUDE options.inc}
 
 type PRangeArray = ^TRangeArray;
@@ -31,8 +31,10 @@
 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
 
+function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): boolean;
+
 implementation
-uses SDLh, uMisc, uLand, uConsts;
+uses SDLh, uMisc, uLand;
 
 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);
 var i: LongInt;
@@ -72,7 +74,6 @@
 begin
 p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y];
 case LandSurface^.format^.BytesPerPixel of
-     1: ;// not supported
      2: PWord(@(p^[x * 2]))^:= 0;
      3: begin
         p^[x * 3 + 0]:= 0;
@@ -88,7 +89,6 @@
 begin
 p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y];
 case LandSurface^.format^.BytesPerPixel of
-     1: ;// not supported
      2: PWord(@(p^[x * 2]))^:= cExplosionBorderColor;
      3: begin
         p^[x * 3 + 0]:= cExplosionBorderColor and $FF;
@@ -268,5 +268,110 @@
    SDL_UnlockSurface(LandSurface)
 end;
 
+function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): boolean;
+var Result: boolean;
+    X, Y, sY, bpp, h, w: LongInt;
+    p: PByteArray;
+    r, rr: TSDL_Rect;
+    Image: PSDL_Surface;
+begin
+Result:= true;
+Image:= SpritesData[Obj].Surface;
+w:= SpritesData[Obj].Width;
+h:= SpritesData[Obj].Height; 
+
+if SDL_MustLock(Image) then
+   SDLTry(SDL_LockSurface(Image) >= 0, true);
+
+bpp:= Image^.format^.BytesPerPixel;
+TryDo(bpp <> 1, 'We don''t work with 8 bit surfaces', true);
+// Check that sprites fits free space
+p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]);
+case bpp of
+     2: for y:= 0 to Pred(h) do
+            begin
+            for x:= 0 to Pred(w) do
+                if PWord(@(p^[x * 2]))^ <> 0 then
+                   if (((cpY + y) and $FFFFFC00) <> 0) or
+                      (((cpX + x) and $FFFFF800) <> 0) or
+                      (Land[cpY + y, cpX + x] <> 0) then
+                      begin
+                      if SDL_MustLock(Image) then
+                         SDL_UnlockSurface(Image);
+                      exit(false)
+                      end;
+            p:= @(p^[Image^.pitch]);
+            end;
+     3: for y:= 0 to Pred(h) do
+            begin
+            for x:= 0 to Pred(w) do
+                if  (p^[x * 3 + 0] <> 0)
+                 or (p^[x * 3 + 1] <> 0)
+                 or (p^[x * 3 + 2] <> 0) then
+                   if (((cpY + y) and $FFFFFC00) <> 0) or
+                      (((cpX + x) and $FFFFF800) <> 0) or
+                      (Land[cpY + y, cpX + x] <> 0) then
+                      begin
+                      if SDL_MustLock(Image) then
+                         SDL_UnlockSurface(Image);
+                      exit(false)
+                      end;
+            p:= @(p^[Image^.pitch]);
+            end;
+     4: for y:= 0 to Pred(h) do
+            begin
+            for x:= 0 to Pred(w) do
+                if PLongword(@(p^[x * 4]))^ <> 0 then
+                   if (((cpY + y) and $FFFFFC00) <> 0) or
+                      (((cpX + x) and $FFFFF800) <> 0) or
+                      (Land[cpY + y, cpX + x] <> 0) then
+                      begin
+                      if SDL_MustLock(Image) then
+                         SDL_UnlockSurface(Image);
+                      exit(false)
+                      end;
+            p:= @(p^[Image^.pitch]);
+            end;
+     end;
+
+// Checked, now place
+p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]);
+case bpp of
+     2: for y:= 0 to Pred(h) do
+            begin
+            for x:= 0 to Pred(w) do
+                if PWord(@(p^[x * 2]))^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND;
+            p:= @(p^[Image^.pitch]);
+            end;
+     3: for y:= 0 to Pred(h) do
+            begin
+            for x:= 0 to Pred(w) do
+                if  (p^[x * 3 + 0] <> 0)
+                 or (p^[x * 3 + 1] <> 0)
+                 or (p^[x * 3 + 2] <> 0) then Land[cpY + y, cpX + x]:= COLOR_LAND;
+            p:= @(p^[Image^.pitch]);
+            end;
+     4: for y:= 0 to Pred(h) do
+            begin
+            for x:= 0 to Pred(w) do
+                if PLongword(@(p^[x * 4]))^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND;
+            p:= @(p^[Image^.pitch]);
+            end;
+     end;
+if SDL_MustLock(Image) then
+   SDL_UnlockSurface(Image);
+
+// Draw sprite on Land surface
+r.x:= 0;
+r.y:= SpritesData[Obj].Height * Frame;
+r.w:= SpritesData[Obj].Width;
+r.h:= SpritesData[Obj].Height;
+rr.x:= cpX;
+rr.y:= cpY;
+SDL_UpperBlit(Image, @r, LandSurface, @rr);
+
+TryPlaceOnLand:= true
+end;
+
 
 end.
--- a/hedgewars/uLocale.pas	Wed Feb 07 17:27:32 2007 +0000
+++ b/hedgewars/uLocale.pas	Wed Feb 07 21:36:55 2007 +0000
@@ -21,7 +21,8 @@
 type TAmmoStrId = (sidGrenade, sidClusterBomb, sidBazooka, sidUFO, sidShotgun,
                    sidPickHammer, sidSkip, sidRope, sidMine, sidDEagle,
                    sidDynamite, sidBaseballBat, sidFirePunch, sidSeconds,
-                   sidParachute, sidAirAttack, sidMineStrike, sidBlowTorch);
+                   sidParachute, sidAirAttack, sidMineStrike, sidBlowTorch,
+                   sidGirder);
 
      TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused);
 
Binary file share/hedgewars/Data/Graphics/amGirder.png has changed
--- a/share/hedgewars/Data/Locale/en.txt	Wed Feb 07 17:27:32 2007 +0000
+++ b/share/hedgewars/Data/Locale/en.txt	Wed Feb 07 21:36:55 2007 +0000
@@ -18,6 +18,7 @@
 00:15=Air Attack
 00:16=Mine Strike
 00:17=Blow Torch
+00:18=Construction
 
 01:00=Let's fight!
 01:01=Round draw
--- a/share/hedgewars/Data/Locale/ru.txt	Wed Feb 07 17:27:32 2007 +0000
+++ b/share/hedgewars/Data/Locale/ru.txt	Wed Feb 07 21:36:55 2007 +0000
@@ -18,6 +18,7 @@
 00:15=Воздушная атака
 00:16=Минный удар
 00:17=Бур
+00:18=Конструктор
 
 01:00=Вперёд к победе!
 01:01=Ничья