hedgewars/uGears.pas
changeset 2695 ed789a7ef68d
parent 2659 947fa21d5cd8
child 2699 249adefa9c1c
equal deleted inserted replaced
2694:dcd248e04f3d 2695:ed789a7ef68d
   207 	GearsList:= Gear^.NextGear
   207 	GearsList:= Gear^.NextGear
   208 end;
   208 end;
   209 
   209 
   210 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
   210 function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
   211 const Counter: Longword = 0;
   211 const Counter: Longword = 0;
   212 var Result: PGear;
   212 var gear: PGear;
   213 begin
   213 begin
   214 inc(Counter);
   214 inc(Counter);
   215 {$IFDEF DEBUGFILE}
   215 {$IFDEF DEBUGFILE}
   216 AddFileLog('AddGear: #' + inttostr(Counter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + inttostr(ord(Kind)));
   216 AddFileLog('AddGear: #' + inttostr(Counter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + inttostr(ord(Kind)));
   217 {$ENDIF}
   217 {$ENDIF}
   218 
   218 
   219 New(Result);
   219 New(gear);
   220 FillChar(Result^, sizeof(TGear), 0);
   220 FillChar(gear^, sizeof(TGear), 0);
   221 Result^.X:= int2hwFloat(X);
   221 gear^.X:= int2hwFloat(X);
   222 Result^.Y:= int2hwFloat(Y);
   222 gear^.Y:= int2hwFloat(Y);
   223 Result^.Kind := Kind;
   223 gear^.Kind := Kind;
   224 Result^.State:= State;
   224 gear^.State:= State;
   225 Result^.Active:= true;
   225 gear^.Active:= true;
   226 Result^.dX:= dX;
   226 gear^.dX:= dX;
   227 Result^.dY:= dY;
   227 gear^.dY:= dY;
   228 Result^.doStep:= doStepHandlers[Kind];
   228 gear^.doStep:= doStepHandlers[Kind];
   229 Result^.CollisionIndex:= -1;
   229 gear^.CollisionIndex:= -1;
   230 Result^.Timer:= Timer;
   230 gear^.Timer:= Timer;
   231 Result^.Z:= cUsualZ;
   231 gear^.Z:= cUsualZ;
   232 Result^.FlightTime:= 0;
   232 gear^.FlightTime:= 0;
   233 Result^.uid:= Counter;
   233 gear^.uid:= Counter;
   234 
   234 
   235 if CurrentTeam <> nil then
   235 if CurrentTeam <> nil then
   236 	begin
   236 	begin
   237 	Result^.Hedgehog:= CurrentHedgehog;
   237 	gear^.Hedgehog:= CurrentHedgehog;
   238 	Result^.IntersectGear:= CurrentHedgehog^.Gear
   238 	gear^.IntersectGear:= CurrentHedgehog^.Gear
   239 	end;
   239 	end;
   240 
   240 
   241 case Kind of
   241 case Kind of
   242    gtAmmo_Bomb,
   242    gtAmmo_Bomb,
   243  gtClusterBomb: begin
   243  gtClusterBomb: begin
   244                 Result^.Radius:= 4;
   244                 gear^.Radius:= 4;
   245                 Result^.Elasticity:= _0_6;
   245                 gear^.Elasticity:= _0_6;
   246                 Result^.Friction:= _0_96;
   246                 gear^.Friction:= _0_96;
   247                 Result^.RenderTimer:= true;
   247                 gear^.RenderTimer:= true;
   248                 if Result^.Timer = 0 then Result^.Timer:= 3000
   248                 if gear^.Timer = 0 then gear^.Timer:= 3000
   249                 end;
   249                 end;
   250   gtWatermelon: begin
   250   gtWatermelon: begin
   251                 Result^.Radius:= 4;
   251                 gear^.Radius:= 4;
   252                 Result^.Elasticity:= _0_8;
   252                 gear^.Elasticity:= _0_8;
   253                 Result^.Friction:= _0_995;
   253                 gear^.Friction:= _0_995;
   254                 Result^.RenderTimer:= true;
   254                 gear^.RenderTimer:= true;
   255                 if Result^.Timer = 0 then Result^.Timer:= 3000
   255                 if gear^.Timer = 0 then gear^.Timer:= 3000
   256                 end;
   256                 end;
   257     gtHedgehog: begin
   257     gtHedgehog: begin
   258                 Result^.Radius:= cHHRadius;
   258                 gear^.Radius:= cHHRadius;
   259                 Result^.Elasticity:= _0_35;
   259                 gear^.Elasticity:= _0_35;
   260                 Result^.Friction:= _0_999;
   260                 gear^.Friction:= _0_999;
   261                 Result^.Angle:= cMaxAngle div 2;
   261                 gear^.Angle:= cMaxAngle div 2;
   262                 Result^.Z:= cHHZ;
   262                 gear^.Z:= cHHZ;
   263                 end;
   263                 end;
   264 gtAmmo_Grenade: begin // bazooka
   264 gtAmmo_Grenade: begin // bazooka
   265                 Result^.Radius:= 4;
   265                 gear^.Radius:= 4;
   266                 end;
   266                 end;
   267    gtHealthTag: begin
   267    gtHealthTag: begin
   268                 Result^.Timer:= 1500;
   268                 gear^.Timer:= 1500;
   269                 Result^.Z:= 2002;
   269                 gear^.Z:= 2002;
   270                 end;
   270                 end;
   271        gtGrave: begin
   271        gtGrave: begin
   272                 Result^.Radius:= 10;
   272                 gear^.Radius:= 10;
   273                 Result^.Elasticity:= _0_6;
   273                 gear^.Elasticity:= _0_6;
   274                 end;
   274                 end;
   275          gtUFO: begin
   275          gtUFO: begin
   276                 Result^.Radius:= 5;
   276                 gear^.Radius:= 5;
   277                 Result^.Timer:= 500;
   277                 gear^.Timer:= 500;
   278                 Result^.RenderTimer:= true;
   278                 gear^.RenderTimer:= true;
   279                 Result^.Elasticity:= _0_9
   279                 gear^.Elasticity:= _0_9
   280                 end;
   280                 end;
   281  gtShotgunShot: begin
   281  gtShotgunShot: begin
   282                 Result^.Timer:= 900;
   282                 gear^.Timer:= 900;
   283                 Result^.Radius:= 2
   283                 gear^.Radius:= 2
   284                 end;
   284                 end;
   285   gtPickHammer: begin
   285   gtPickHammer: begin
   286                 Result^.Radius:= 10;
   286                 gear^.Radius:= 10;
   287                 Result^.Timer:= 4000
   287                 gear^.Timer:= 4000
   288                 end;
   288                 end;
   289   gtSmokeTrace,
   289   gtSmokeTrace,
   290    gtEvilTrace: begin
   290    gtEvilTrace: begin
   291                 Result^.X:= Result^.X - _16;
   291                 gear^.X:= gear^.X - _16;
   292                 Result^.Y:= Result^.Y - _16;
   292                 gear^.Y:= gear^.Y - _16;
   293                 Result^.State:= 8;
   293                 gear^.State:= 8;
   294                 Result^.Z:= cSmokeZ
   294                 gear^.Z:= cSmokeZ
   295                 end;
   295                 end;
   296         gtRope: begin
   296         gtRope: begin
   297                 Result^.Radius:= 3;
   297                 gear^.Radius:= 3;
   298                 Result^.Friction:= _450;
   298                 gear^.Friction:= _450;
   299                 RopePoints.Count:= 0;
   299                 RopePoints.Count:= 0;
   300                 end;
   300                 end;
   301    gtExplosion: begin
   301    gtExplosion: begin
   302                 Result^.X:= Result^.X;
   302                 gear^.X:= gear^.X;
   303                 Result^.Y:= Result^.Y;
   303                 gear^.Y:= gear^.Y;
   304                 end;
   304                 end;
   305         gtMine: begin
   305         gtMine: begin
   306                 Result^.State:= Result^.State or gstMoving;
   306                 gear^.State:= gear^.State or gstMoving;
   307                 Result^.Radius:= 2;
   307                 gear^.Radius:= 2;
   308                 Result^.Elasticity:= _0_55;
   308                 gear^.Elasticity:= _0_55;
   309                 Result^.Friction:= _0_995;
   309                 gear^.Friction:= _0_995;
   310                 if cMinesTime < 0 then
   310                 if cMinesTime < 0 then
   311                     Result^.Timer:= getrandom(4)*1000
   311                     gear^.Timer:= getrandom(4)*1000
   312                 else
   312                 else
   313                     Result^.Timer:= cMinesTime*1;
   313                     gear^.Timer:= cMinesTime*1;
   314                 end;
   314                 end;
   315         gtCase: begin
   315         gtCase: begin
   316                 Result^.Radius:= 16;
   316                 gear^.Radius:= 16;
   317                 Result^.Elasticity:= _0_3
   317                 gear^.Elasticity:= _0_3
   318                 end;
   318                 end;
   319   gtDEagleShot: begin
   319   gtDEagleShot: begin
   320                 Result^.Radius:= 1;
   320                 gear^.Radius:= 1;
   321                 Result^.Health:= 50
   321                 gear^.Health:= 50
   322                 end;
   322                 end;
   323   gtSniperRifleShot: begin
   323   gtSniperRifleShot: begin
   324                 Result^.Radius:= 1;
   324                 gear^.Radius:= 1;
   325                 Result^.Health:= 50
   325                 gear^.Health:= 50
   326                 end;
   326                 end;
   327     gtDynamite: begin
   327     gtDynamite: begin
   328                 Result^.Radius:= 3;
   328                 gear^.Radius:= 3;
   329                 Result^.Elasticity:= _0_55;
   329                 gear^.Elasticity:= _0_55;
   330                 Result^.Friction:= _0_03;
   330                 gear^.Friction:= _0_03;
   331                 Result^.Timer:= 5000;
   331                 gear^.Timer:= 5000;
   332                 end;
   332                 end;
   333      gtCluster: begin
   333      gtCluster: begin
   334                 Result^.Radius:= 2;
   334                 gear^.Radius:= 2;
   335                 Result^.RenderTimer:= true
   335                 gear^.RenderTimer:= true
   336                 end;
   336                 end;
   337       gtShover: Result^.Radius:= 20;
   337       gtShover: gear^.Radius:= 20;
   338        gtFlame: begin
   338        gtFlame: begin
   339                 Result^.Tag:= GetRandom(32);
   339                 gear^.Tag:= GetRandom(32);
   340                 Result^.Radius:= 1;
   340                 gear^.Radius:= 1;
   341                 Result^.Health:= 5;
   341                 gear^.Health:= 5;
   342                 if (Result^.dY.QWordValue = 0) and (Result^.dX.QWordValue = 0) then
   342                 if (gear^.dY.QWordValue = 0) and (gear^.dX.QWordValue = 0) then
   343                 	begin
   343                 	begin
   344                 	Result^.dY:= (getrandom - _0_8) * _0_03;
   344                 	gear^.dY:= (getrandom - _0_8) * _0_03;
   345                 	Result^.dX:= (getrandom - _0_5) * _0_4
   345                 	gear^.dX:= (getrandom - _0_5) * _0_4
   346                 	end
   346                 	end
   347                 end;
   347                 end;
   348    gtFirePunch: begin
   348    gtFirePunch: begin
   349                 Result^.Radius:= 15;
   349                 gear^.Radius:= 15;
   350                 Result^.Tag:= Y
   350                 gear^.Tag:= Y
   351                 end;
   351                 end;
   352      gtAirBomb: begin
   352      gtAirBomb: begin
   353                 Result^.Radius:= 5;
   353                 gear^.Radius:= 5;
   354                 end;
   354                 end;
   355    gtBlowTorch: begin
   355    gtBlowTorch: begin
   356                 Result^.Radius:= cHHRadius + cBlowTorchC;
   356                 gear^.Radius:= cHHRadius + cBlowTorchC;
   357                 Result^.Timer:= 7500
   357                 gear^.Timer:= 7500
   358                 end;
   358                 end;
   359     gtSwitcher: begin
   359     gtSwitcher: begin
   360                 Result^.Z:= cCurrHHZ
   360                 gear^.Z:= cCurrHHZ
   361                 end;
   361                 end;
   362       gtTarget: begin
   362       gtTarget: begin
   363                 Result^.Radius:= 10;
   363                 gear^.Radius:= 10;
   364                 Result^.Elasticity:= _0_3;
   364                 gear^.Elasticity:= _0_3;
   365 				Result^.Timer:= 0
   365 				gear^.Timer:= 0
   366                 end;
   366                 end;
   367       gtMortar: begin
   367       gtMortar: begin
   368                 Result^.Radius:= 4;
   368                 gear^.Radius:= 4;
   369                 Result^.Elasticity:= _0_2;
   369                 gear^.Elasticity:= _0_2;
   370                 Result^.Friction:= _0_08
   370                 gear^.Friction:= _0_08
   371                 end;
   371                 end;
   372         gtWhip: Result^.Radius:= 20;
   372         gtWhip: gear^.Radius:= 20;
   373     gtKamikaze: begin
   373     gtKamikaze: begin
   374                 Result^.Health:= 2048;
   374                 gear^.Health:= 2048;
   375                 Result^.Radius:= 20
   375                 gear^.Radius:= 20
   376                 end;
   376                 end;
   377         gtCake: begin
   377         gtCake: begin
   378                 Result^.Health:= 2048;
   378                 gear^.Health:= 2048;
   379                 Result^.Radius:= 7;
   379                 gear^.Radius:= 7;
   380                 Result^.Z:= cOnHHZ;
   380                 gear^.Z:= cOnHHZ;
   381                 Result^.RenderTimer:= true;
   381                 gear^.RenderTimer:= true;
   382                 if not dX.isNegative then Result^.Angle:= 1 else Result^.Angle:= 3
   382                 if not dX.isNegative then gear^.Angle:= 1 else gear^.Angle:= 3
   383                 end;
   383                 end;
   384  gtHellishBomb: begin
   384  gtHellishBomb: begin
   385                 Result^.Radius:= 4;
   385                 gear^.Radius:= 4;
   386                 Result^.Elasticity:= _0_5;
   386                 gear^.Elasticity:= _0_5;
   387                 Result^.Friction:= _0_96;
   387                 gear^.Friction:= _0_96;
   388                 Result^.RenderTimer:= true;
   388                 gear^.RenderTimer:= true;
   389                 Result^.Timer:= 5000
   389                 gear^.Timer:= 5000
   390                 end;
   390                 end;
   391        gtDrill: begin
   391        gtDrill: begin
   392                 Result^.Timer:= 5000;
   392                 gear^.Timer:= 5000;
   393                 Result^.Radius:= 4
   393                 gear^.Radius:= 4
   394                 end;
   394                 end;
   395         gtBall: begin
   395         gtBall: begin
   396                 Result^.Radius:= 5;
   396                 gear^.Radius:= 5;
   397                 Result^.Tag:= random(8);
   397                 gear^.Tag:= random(8);
   398                 Result^.Timer:= 5000;
   398                 gear^.Timer:= 5000;
   399                 Result^.Elasticity:= _0_7;
   399                 gear^.Elasticity:= _0_7;
   400                 Result^.Friction:= _0_995;
   400                 gear^.Friction:= _0_995;
   401                 end;
   401                 end;
   402      gtBallgun: begin
   402      gtBallgun: begin
   403                 Result^.Timer:= 5001;
   403                 gear^.Timer:= 5001;
   404                 end;
   404                 end;
   405      gtRCPlane: begin
   405      gtRCPlane: begin
   406                 Result^.Timer:= 15000;
   406                 gear^.Timer:= 15000;
   407                 Result^.Health:= 3;
   407                 gear^.Health:= 3;
   408                 Result^.Radius:= 8
   408                 gear^.Radius:= 8
   409                 end;
   409                 end;
   410      gtJetpack: begin
   410      gtJetpack: begin
   411                 Result^.Health:= 2000;
   411                 gear^.Health:= 2000;
   412                 end;
   412                 end;
   413      gtMolotov: begin 
   413      gtMolotov: begin 
   414                 Result^.Radius:= 8;
   414                 gear^.Radius:= 8;
   415                 end;
   415                 end;
   416      end;
   416      end;
   417 InsertGearToList(Result);
   417 InsertGearToList(gear);
   418 AddGear:= Result
   418 AddGear:= gear;
   419 end;
   419 end;
   420 
   420 
   421 procedure DeleteGear(Gear: PGear);
   421 procedure DeleteGear(Gear: PGear);
   422 var team: PTeam;
   422 var team: PTeam;
   423 	t: Longword;
   423 	t: Longword;
  1856 CheckGearsNear:= nil
  1856 CheckGearsNear:= nil
  1857 end;
  1857 end;
  1858 
  1858 
  1859 function CountGears(Kind: TGearType): Longword;
  1859 function CountGears(Kind: TGearType): Longword;
  1860 var t: PGear;
  1860 var t: PGear;
  1861     Result: Longword;
  1861     count: Longword = 0;
  1862 begin
  1862 begin
  1863 Result:= 0;
  1863 
  1864 t:= GearsList;
  1864 t:= GearsList;
  1865 while t <> nil do
  1865 while t <> nil do
  1866 	begin
  1866 	begin
  1867 	if t^.Kind = Kind then inc(Result);
  1867 	if t^.Kind = Kind then inc(count);
  1868 	t:= t^.NextGear
  1868 	t:= t^.NextGear
  1869 	end;
  1869 	end;
  1870 CountGears:= Result
  1870 CountGears:= count;
  1871 end;
  1871 end;
  1872 
  1872 
  1873 procedure SpawnBoxOfSmth;
  1873 procedure SpawnBoxOfSmth;
  1874 var t: LongInt;
  1874 var t: LongInt;
  1875     i: TAmmoType;
  1875     i: TAmmoType;
  1955 
  1955 
  1956 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
  1956 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
  1957 
  1957 
  1958 	function CountNonZeroz(x, y, r, c: LongInt): LongInt;
  1958 	function CountNonZeroz(x, y, r, c: LongInt): LongInt;
  1959 	var i: LongInt;
  1959 	var i: LongInt;
  1960 		Result: LongInt;
  1960 		count: LongInt = 0;
  1961 	begin
  1961 	begin
  1962 	Result:= 0;
       
  1963 	if (y and LAND_HEIGHT_MASK) = 0 then
  1962 	if (y and LAND_HEIGHT_MASK) = 0 then
  1964 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
  1963 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
  1965 			if Land[y, i] <> 0 then
  1964 			if Land[y, i] <> 0 then
  1966                begin
  1965                begin
  1967                inc(Result);
  1966                inc(count);
  1968                if Result = c then exit(Result)
  1967                if count = c then exit(count)
  1969                end;
  1968                end;
  1970 	CountNonZeroz:= Result
  1969 	CountNonZeroz:= count;
  1971 	end;
  1970 	end;
  1972 
  1971 
  1973 var x: LongInt;
  1972 var x: LongInt;
  1974 	y, sy: LongInt;
  1973 	y, sy: LongInt;
  1975 	ar: array[0..511] of TPoint;
  1974 	ar: array[0..511] of TPoint;