25 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
25 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
26 procedure DeleteGear(Gear: PGear); |
26 procedure DeleteGear(Gear: PGear); |
27 procedure InsertGearToList(Gear: PGear); |
27 procedure InsertGearToList(Gear: PGear); |
28 procedure RemoveGearFromList(Gear: PGear); |
28 procedure RemoveGearFromList(Gear: PGear); |
29 |
29 |
|
30 var curHandledGear: PGear; |
|
31 |
30 implementation |
32 implementation |
31 |
33 |
32 uses uRandom, uUtils, uConsts, uVariables, uAmmos, uTeams, uStats, |
34 uses uRandom, uUtils, uConsts, uVariables, uAmmos, uTeams, uStats, |
33 uTextures, uScript, uRenderUtils, uAI, uCollisions, |
35 uTextures, uScript, uRenderUtils, uAI, uCollisions, |
34 uGearsRender, uGearsUtils; |
36 uGearsRender, uGearsUtils, uDebug; |
35 |
37 |
36 var GCounter: LongWord = 0; // this does not get re-initialized, but should be harmless |
38 var GCounter: LongWord = 0; // this does not get re-initialized, but should be harmless |
37 |
39 |
38 procedure InsertGearToList(Gear: PGear); |
40 procedure InsertGearToList(Gear: PGear); |
39 var tmp, ptmp: PGear; |
41 var tmp, ptmp: PGear; |
40 begin |
42 begin |
41 tmp:= GearsList; |
43 tmp:= GearsList; |
42 ptmp:= GearsList; |
44 ptmp:= GearsList; |
43 while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do |
45 while (tmp <> nil) and (tmp^.Z < Gear^.Z) do |
44 begin |
46 begin |
45 ptmp:= tmp; |
47 ptmp:= tmp; |
46 tmp:= tmp^.NextGear |
48 tmp:= tmp^.NextGear |
47 end; |
49 end; |
48 |
50 |
61 Gear^.NextGear^.PrevGear:= Gear; |
63 Gear^.NextGear^.PrevGear:= Gear; |
62 GearsList:= Gear; |
64 GearsList:= Gear; |
63 end; |
65 end; |
64 end; |
66 end; |
65 |
67 |
|
68 |
66 procedure RemoveGearFromList(Gear: PGear); |
69 procedure RemoveGearFromList(Gear: PGear); |
67 begin |
70 begin |
|
71 TryDo((curHandledGear = nil) or (Gear = curHandledGear), 'You''re doing it wrong', true); |
|
72 |
68 if Gear^.NextGear <> nil then |
73 if Gear^.NextGear <> nil then |
69 Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
74 Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
70 if Gear^.PrevGear <> nil then |
75 if Gear^.PrevGear <> nil then |
71 Gear^.PrevGear^.NextGear:= Gear^.NextGear |
76 Gear^.PrevGear^.NextGear:= Gear^.NextGear |
72 else |
77 else |
73 GearsList:= Gear^.NextGear |
78 GearsList:= Gear^.NextGear |
74 end; |
79 end; |
75 |
80 |
|
81 |
76 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
82 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
77 var gear: PGear; |
83 var gear: PGear; |
78 begin |
84 begin |
79 inc(GCounter); |
85 inc(GCounter); |
80 AddFileLog('AddGear: #' + inttostr(GCounter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind)); |
86 AddFileLog('AddGear: #' + inttostr(GCounter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind)); |
90 gear^.dX:= dX; |
96 gear^.dX:= dX; |
91 gear^.dY:= dY; |
97 gear^.dY:= dY; |
92 gear^.doStep:= doStepHandlers[Kind]; |
98 gear^.doStep:= doStepHandlers[Kind]; |
93 gear^.CollisionIndex:= -1; |
99 gear^.CollisionIndex:= -1; |
94 gear^.Timer:= Timer; |
100 gear^.Timer:= Timer; |
95 gear^.FlightTime:= 0; |
|
96 gear^.uid:= GCounter; |
101 gear^.uid:= GCounter; |
97 gear^.SoundChannel:= -1; |
102 gear^.SoundChannel:= -1; |
98 gear^.ImpactSound:= sndNone; |
103 gear^.ImpactSound:= sndNone; |
99 gear^.nImpactSounds:= 0; |
|
100 gear^.Density:= _1; |
104 gear^.Density:= _1; |
101 // Define ammo association, if any. |
105 // Define ammo association, if any. |
102 gear^.AmmoType:= GearKindAmmoTypeMap[Kind]; |
106 gear^.AmmoType:= GearKindAmmoTypeMap[Kind]; |
103 gear^.CollisionMask:= $FFFF; |
107 gear^.CollisionMask:= $FFFF; |
104 |
108 |
105 if CurrentHedgehog <> nil then gear^.Hedgehog:= CurrentHedgehog; |
109 if CurrentHedgehog <> nil then gear^.Hedgehog:= CurrentHedgehog; |
106 |
110 |
107 if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then |
111 if (Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then |
108 gear^.Z:= cHHZ+1 |
112 gear^.Z:= cHHZ+1 |
109 else gear^.Z:= cUsualZ; |
113 else gear^.Z:= cUsualZ; |
110 |
114 |
111 |
115 |
112 case Kind of |
116 case Kind of |
553 FreeTexture(Team^.AIKillsTex); |
565 FreeTexture(Team^.AIKillsTex); |
554 Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16); |
566 Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16); |
555 end |
567 end |
556 end; |
568 end; |
557 with Gear^ do |
569 with Gear^ do |
|
570 begin |
558 AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind)); |
571 AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind)); |
559 |
572 AddRandomness(X.round xor X.frac xor dX.round xor dX.frac xor Y.round xor Y.frac xor dY.round xor dY.frac) |
|
573 end; |
560 if CurAmmoGear = Gear then |
574 if CurAmmoGear = Gear then |
561 CurAmmoGear:= nil; |
575 CurAmmoGear:= nil; |
562 if FollowGear = Gear then |
576 if FollowGear = Gear then |
563 FollowGear:= nil; |
577 FollowGear:= nil; |
564 if lastGearByUID = Gear then |
578 if lastGearByUID = Gear then |