Try to document TGear a bit, so people know what is commonly overridden, and what stuff is used for. Remove gtIceGun-specific values from TGear and abuse a couple of commonly abused members instead.
--- a/hedgewars/GSHandlers.inc Fri Mar 22 14:54:20 2013 +0100
+++ b/hedgewars/GSHandlers.inc Tue Mar 26 17:47:06 2013 -0400
@@ -5088,8 +5088,7 @@
procedure updateTarget(Gear:PGear; newX, newY:HWFloat);
- var
- iter:PGear;
+ //var iter:PGear;
begin
with Gear^ do
begin
@@ -5118,10 +5117,10 @@
procedure doStepIceGun(Gear: PGear);
const iceWaitCollision:Longint = 0;
const iceCollideWithGround:Longint = 1;
-const iceWaitNextTarget:Longint = 2;
-const iceCollideWithHog:Longint = 4;
+//const iceWaitNextTarget:Longint = 2;
+//const iceCollideWithHog:Longint = 4;
const iceCollideWithWater:Longint = 5;
-const waterFreezingTime:Longint = 500;
+//const waterFreezingTime:Longint = 500;
const groundFreezingTime:Longint = 1000;
const iceRadius = 32;
const iceHeight = 40;
@@ -5132,7 +5131,7 @@
hogs: PGearArrayS;
begin
HHGear := Gear^.Hedgehog^.Gear;
- if (Gear^.Message and gmAttack <> 0) or (Gear^.Health = 0) or (HHGear = nil) or (HHGear^.Damage <> 0) then
+ if (Gear^.Message and gmAttack <> 0) or (HHGear = nil) or (HHGear^.Damage <> 0) then
begin
DeleteGear(Gear);
AfterAttack;
@@ -5150,7 +5149,7 @@
(Target.Y and LAND_HEIGHT_MASK = 0) and ((Land[Target.Y, Target.X] = 0))) then
begin
updateTarget(Gear, ndX, ndY);
- IceState := iceWaitCollision;
+ Health := iceWaitCollision;
end
else
begin
@@ -5168,18 +5167,18 @@
CheckCollisionWithLand(Gear);
if (State and gstCollision) <> 0 then
begin
- if IceState = iceWaitCollision then
+ if Health = iceWaitCollision then
begin
- IceState := iceCollideWithGround;
- IceTime := GameTicks;
+ Health := iceCollideWithGround;
+ Power := GameTicks;
end
end
else if (target.y >= cWaterLine) then
begin
- if IceState = iceWaitCollision then
+ if Health = iceWaitCollision then
begin
- IceState := iceCollideWithWater;
- IceTime := GameTicks;
+ Health := iceCollideWithWater;
+ Power := GameTicks;
end;
end;
@@ -5189,18 +5188,18 @@
Y:= HHGear^.Y
end;
- if (IceState = iceCollideWithGround) and ((GameTicks - IceTime) > groundFreezingTime) then
+ if (Health = iceCollideWithGround) and ((GameTicks - Power) > groundFreezingTime) then
begin
FillRoundInLandWithIce(Target.X, Target.Y, iceRadius);
SetAllHHToActive;
- IceState := iceWaitCollision;
+ Health := iceWaitCollision;
end;
- if (IceState = iceCollideWithWater) and ((GameTicks - IceTime) > groundFreezingTime) then
+ if (Health = iceCollideWithWater) and ((GameTicks - Power) > groundFreezingTime) then
begin
DrawIceBreak(Target.X, cWaterLine - iceHeight, iceRadius, iceHeight);
SetAllHHToActive;
- IceState := iceWaitCollision;
+ Health := iceWaitCollision;
end;
// freeze nearby hogs
--- a/hedgewars/uGearsHedgehog.pas Fri Mar 22 14:54:20 2013 +0100
+++ b/hedgewars/uGearsHedgehog.pas Tue Mar 26 17:47:06 2013 -0400
@@ -383,10 +383,7 @@
end;
//amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
- amIceGun: begin
- newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
- newGear^.radius := 8;
- end;
+ amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
end;
if altUse and (newGear <> nil) then
begin
--- a/hedgewars/uGearsList.pas Fri Mar 22 14:54:20 2013 +0100
+++ b/hedgewars/uGearsList.pas Tue Mar 26 17:47:06 2013 -0400
@@ -548,7 +548,10 @@
gear^.Pos:= 1;
end;
}
- gtIceGun: gear^.Health:= 1000;
+ gtIceGun: begin
+ gear^.Health:= 1000;
+ gear^.Radius:= 8;
+ end;
gtGenericFaller:begin
gear^.AdvBounce:= 1;
gear^.Radius:= 1;
--- a/hedgewars/uLandGraphics.pas Fri Mar 22 14:54:20 2013 +0100
+++ b/hedgewars/uLandGraphics.pas Tue Mar 26 17:47:06 2013 -0400
@@ -278,9 +278,9 @@
var
iceSurface: PSDL_Surface;
icePixels: PLongwordArray;
- pictureX, pictureY: LongInt;
- w, c: LongWord;
- weight: Longint;
+ //pictureX, pictureY: LongInt;
+ w: LongWord;
+ //weight: Longint;
begin
// So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
iceSurface:= SpritesData[sprIceTexture].Surface;
--- a/hedgewars/uTypes.pas Fri Mar 22 14:54:20 2013 +0100
+++ b/hedgewars/uTypes.pas Tue Mar 26 17:47:06 2013 -0400
@@ -220,48 +220,56 @@
PClan = ^TClan;
TGearStepProcedure = procedure (Gear: PGear);
+// So, you're here looking for variables you can (ab)use to store some gear state?
+// Not all members of this structure are created equal. Comments below are my take on what can be used for what in the gear structure.
TGear = record
- NextGear, PrevGear: PGear;
- Active: Boolean;
- AdvBounce: Longword;
- Invulnerable: Boolean;
- RenderTimer: Boolean;
- AmmoType : TAmmoType;
- State : Longword;
- X : hwFloat;
+// Don't ever override these.
+ NextGear, PrevGear: PGear; // Linked list
+ Z: Longword; // Z index. For rendering. Sets order in list
+ Active: Boolean; // Is gear Active (running step code)
+ Kind: TGearType;
+ doStep: TGearStepProcedure; // Code the gear is running
+ AmmoType : TAmmoType; // Ammo type associated with this kind of gear
+ RenderTimer: Boolean; // Will visually display Timer if true
+ Target : TPoint; // Gear target. Will render in uGearsRender unless a special case is added
+ AIHints: LongWord; // hints for ai.
+ LastDamage: PHedgehog; // Used to track damage source for stats
+ CollisionIndex: LongInt; // Position in collision array
+ Message: LongWord; // Game messages are stored here. See gm bitmasks in uConsts
+ uid: Longword; // Lua use this to reference gears
+// Strongly recommended not to override these. Will mess up generic operations like portaling
+ X : hwFloat; // X/Y/dX/dY are position/velocity. People count on these having semi-normal values
Y : hwFloat;
dX: hwFloat;
dY: hwFloat;
- Target : TPoint;
- Kind: TGearType;
- Pos: Longword;
- doStep: TGearStepProcedure;
- Radius: LongInt;
- Angle, Power : Longword;
- DirAngle: real;
- Timer : LongWord;
+ State : Longword; // See gst bitmask values in uConsts
+ PortalCounter: LongWord; // Necessary to interrupt portal loops. Not possible to avoid infinite loops without it.
+// Don't use these if you're using generic movement like doStepFallingGear and explosion shoves. Generally recommended not to use.
+ Radius: LongInt; // Radius. If not using uCollisions, is usually used to indicate area of effect
+ CollisionMask: Word; // Masking off Land impact FF7F for example ignores current hog and crates
+ AdvBounce: Longword; // Triggers 45° bounces. Is a counter to avoid edge cases
Elasticity: hwFloat;
Friction : hwFloat;
- Density : hwFloat;
- Message, MsgParam : Longword;
- Hedgehog: PHedgehog;
+ Density : hwFloat; // Density is kind of a mix of size and density. Impacts distance thrown, wind.
+ ImpactSound: TSound; // first sound, others have to be after it in the sounds def.
+ nImpactSounds: Word; // count of ImpactSounds.
+// Don't use these if you want to take damage normally, otherwise health/damage are commonly used for other purposes
+ Invulnerable: Boolean;
Health, Damage, Karma: LongInt;
- CollisionIndex: LongInt;
- Tag: LongInt;
- Tex: PTexture;
- Z: Longword;
- CollisionMask: Word;
- LinkedGear: PGear;
- FlightTime: Longword;
- uid: Longword;
- ImpactSound: TSound; // first sound, others have to be after it in the sounds def.
- nImpactSounds: Word; // count of ImpactSounds
- SoundChannel: LongInt;
- PortalCounter: LongWord; // Hopefully temporary, but avoids infinite portal loops in a guaranteed fashion.
- AIHints: LongWord; // hints for ai. haha ^^^^^^ temporary, sure
- IceTime: Longint; //time of ice beam with object some interaction temporary
- IceState: Longint; //state of ice gun temporary
- LastDamage: PHedgehog;
+// DirAngle is a "real" - if you don't need it for rotation of sprite in uGearsRender, you can use it for any visual-only value
+ DirAngle: real;
+// These are frequently overridden to serve some other purpose
+ Pos: Longword; // Commonly overridden. Example use is posCase values in uConsts.
+ Angle, Power : Longword; // Used for hog aiming/firing. Angle is rarely used as an Angle otherwise.
+ Timer : LongWord; // Typically used for some sort of gear timer. Time to explosion, remaining fuel...
+ Tag: LongInt; // Quite generic. Variety of uses.
+ FlightTime: Longword; // Initially added for batting of hogs to determine homerun. Used for some firing delays
+ MsgParam: LongWord; // Initially stored a set of messages. So usually gm values like Message. Frequently overriden
+// These are not used generically, but should probably be used for purpose intended. Definitely shouldn't override pointer type
+ Tex: PTexture; // A texture created by the gear. Shouldn't use for anything but textures
+ LinkedGear: PGear; // Used to track a related gear. Portal pairs for example.
+ Hedgehog: PHedgehog; // set to CurrentHedgehog on gear creation
+ SoundChannel: LongInt; // Used to track a sound the gear started
end;
TPGearArray = array of PGear;
PGearArrayS = record