hedgewars/uGears.pas
changeset 294 92a7ccd67bb9
parent 293 00a532e8808e
child 295 8834f3cb620e
equal deleted inserted replaced
293:00a532e8808e 294:92a7ccd67bb9
    57 procedure DrawGears(Surface: PSDL_Surface);
    57 procedure DrawGears(Surface: PSDL_Surface);
    58 procedure FreeGearsList;
    58 procedure FreeGearsList;
    59 procedure AddMiscGears;
    59 procedure AddMiscGears;
    60 procedure AddClouds;
    60 procedure AddClouds;
    61 procedure AssignHHCoords;
    61 procedure AssignHHCoords;
       
    62 procedure InsertGearToList(Gear: PGear);
       
    63 procedure RemoveGearFromList(Gear: PGear);
    62 
    64 
    63 var CurAmmoGear: PGear = nil;
    65 var CurAmmoGear: PGear = nil;
    64     GearsList: PGear = nil;
    66     GearsList: PGear = nil;
    65 
    67 
    66 implementation
    68 implementation
   117                                                                doStepParachute,
   119                                                                doStepParachute,
   118                                                                doStepAirAttack,
   120                                                                doStepAirAttack,
   119                                                                doStepAirBomb
   121                                                                doStepAirBomb
   120                                                                );
   122                                                                );
   121 
   123 
       
   124 procedure InsertGearToList(Gear: PGear);
       
   125 var tmp: PGear;
       
   126 begin
       
   127 if GearsList = nil then
       
   128    GearsList:= Gear
       
   129    else begin
       
   130    // WARNING: this code assumes that the first gears added to the list are clouds (have maximal Z)
       
   131    tmp:= GearsList;
       
   132    while (tmp <> nil) and (tmp.Z < Gear.Z) do
       
   133           tmp:= tmp.NextGear;
       
   134 
       
   135    if tmp.PrevGear <> nil then tmp.PrevGear.NextGear:= Gear;
       
   136    Gear.PrevGear:= tmp.PrevGear;
       
   137    tmp.PrevGear:= Gear;
       
   138    Gear.NextGear:= tmp;
       
   139    if GearsList = tmp then GearsList:= Gear
       
   140    end
       
   141 end;
       
   142 
       
   143 procedure RemoveGearFromList(Gear: PGear);
       
   144 begin
       
   145 if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear;
       
   146 if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear
       
   147    else begin
       
   148    GearsList:= Gear.NextGear;
       
   149    if GearsList <> nil then GearsList.PrevGear:= nil
       
   150    end;
       
   151 end;
       
   152 
   122 function AddGear(X, Y: integer; Kind: TGearType; State: Longword; const dX: Double=0.0; dY: Double=0.0; Timer: LongWord=0): PGear;
   153 function AddGear(X, Y: integer; Kind: TGearType; State: Longword; const dX: Double=0.0; dY: Double=0.0; Timer: LongWord=0): PGear;
   123 const Counter: Longword = 0;
   154 const Counter: Longword = 0;
   124 var tmp: PGear;
       
   125 begin
   155 begin
   126 inc(Counter);
   156 inc(Counter);
   127 {$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF}
   157 {$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF}
   128 New(Result);
   158 New(Result);
   129 {$IFDEF DEBUGFILE}AddFileLog('AddGear: type = '+inttostr(ord(Kind))+'; handle = '+inttostr(integer(Result)));{$ENDIF}
   159 {$IFDEF DEBUGFILE}AddFileLog('AddGear: type = '+inttostr(ord(Kind))+'; handle = '+inttostr(integer(Result)));{$ENDIF}
   150     gtHedgehog: begin
   180     gtHedgehog: begin
   151                 Result.Radius:= cHHRadius;
   181                 Result.Radius:= cHHRadius;
   152                 Result.Elasticity:= 0.35;
   182                 Result.Elasticity:= 0.35;
   153                 Result.Friction:= 0.999;
   183                 Result.Friction:= 0.999;
   154                 Result.Angle:= cMaxAngle div 2;
   184                 Result.Angle:= cMaxAngle div 2;
   155                 Result.Z:= 1000;
   185                 Result.Z:= cHHZ;
   156                 end;
   186                 end;
   157 gtAmmo_Grenade: begin
   187 gtAmmo_Grenade: begin
   158                 Result.Radius:= 4;
   188                 Result.Radius:= 4;
   159                 end;
   189                 end;
   160    gtHealthTag: begin
   190    gtHealthTag: begin
   231                 end;
   261                 end;
   232     gtAirBomb: begin
   262     gtAirBomb: begin
   233                Result.Radius:= 10;
   263                Result.Radius:= 10;
   234                end;
   264                end;
   235      end;
   265      end;
   236 
   266 InsertGearToList(Result)
   237 if GearsList = nil then GearsList:= Result
       
   238                    else begin
       
   239                    // WARNING: this code assumes that the first gears added to the list are clouds (have maximal Z)
       
   240                    tmp:= GearsList;
       
   241                    while (tmp <> nil) and (tmp.Z < Result.Z) do
       
   242                          tmp:= tmp.NextGear;
       
   243 
       
   244                    if tmp.PrevGear <> nil then tmp.PrevGear.NextGear:= Result;
       
   245                    Result.PrevGear:= tmp.PrevGear;
       
   246                    tmp.PrevGear:= Result;
       
   247                    Result.NextGear:= tmp;
       
   248                    if GearsList = tmp then GearsList:= Result
       
   249                    end
       
   250 end;
   267 end;
   251 
   268 
   252 procedure DeleteGear(Gear: PGear);
   269 procedure DeleteGear(Gear: PGear);
   253 var team: PTeam;
   270 var team: PTeam;
   254 begin
   271 begin
   272       RecountTeamHealth(team);
   289       RecountTeamHealth(team);
   273       end;
   290       end;
   274 {$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF}
   291 {$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF}
   275 if CurAmmoGear = Gear then CurAmmoGear:= nil;
   292 if CurAmmoGear = Gear then CurAmmoGear:= nil;
   276 if FollowGear = Gear then FollowGear:= nil;
   293 if FollowGear = Gear then FollowGear:= nil;
   277 if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear;
   294 RemoveGearFromList(Gear);
   278 if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear
       
   279                         else begin
       
   280                         GearsList:= Gear^.NextGear;
       
   281                         if GearsList <> nil then GearsList.PrevGear:= nil
       
   282                         end;
       
   283 Dispose(Gear)
   295 Dispose(Gear)
   284 end;
   296 end;
   285 
   297 
   286 function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs
   298 function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs
   287 var Gear: PGear;
   299 var Gear: PGear;