hedgewars/uGears.pas
changeset 2762 2fbc8d35eb52
parent 2760 420fe0344e5f
child 2770 851313907bcb
equal deleted inserted replaced
2761:1467c7298b10 2762:2fbc8d35eb52
    68     SuddenDeathDmg: Boolean;
    68     SuddenDeathDmg: Boolean;
    69     SpeechType: Longword;
    69     SpeechType: Longword;
    70     SpeechText: shortstring;
    70     SpeechText: shortstring;
    71     TrainingTargetGear: PGear;
    71     TrainingTargetGear: PGear;
    72     skipFlag: boolean;
    72     skipFlag: boolean;
       
    73     PlacingHogs: boolean; // a convenience flag to indicate placement of hogs is still in progress
    73     
    74     
    74 procedure init_uGears;
    75 procedure init_uGears;
    75 procedure free_uGears;
    76 procedure free_uGears;
    76 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    77 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    77 procedure ProcessGears;
    78 procedure ProcessGears;
    84 procedure AddMiscGears;
    85 procedure AddMiscGears;
    85 procedure AssignHHCoords;
    86 procedure AssignHHCoords;
    86 procedure InsertGearToList(Gear: PGear);
    87 procedure InsertGearToList(Gear: PGear);
    87 procedure RemoveGearFromList(Gear: PGear);
    88 procedure RemoveGearFromList(Gear: PGear);
    88 function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
    89 function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
       
    90 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
    89 
    91 
    90 implementation
    92 implementation
    91 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand, uIO, uLandGraphics,
    93 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand, uIO, uLandGraphics,
    92 	uAIMisc, uLocale, uAI, uAmmos, uTriggers, uStats, uVisualGears,
    94 	uAIMisc, uLocale, uAI, uAmmos, uTriggers, uStats, uVisualGears,
    93 {$IFDEF GLES11}
    95 {$IFDEF GLES11}
   113 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
   115 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
   114 //procedure AmmoFlameWork(Ammo: PGear); forward;
   116 //procedure AmmoFlameWork(Ammo: PGear); forward;
   115 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
   117 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
   116 procedure SpawnBoxOfSmth; forward;
   118 procedure SpawnBoxOfSmth; forward;
   117 procedure AfterAttack; forward;
   119 procedure AfterAttack; forward;
   118 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); forward;
       
   119 procedure HedgehogStep(Gear: PGear); forward;
   120 procedure HedgehogStep(Gear: PGear); forward;
   120 procedure doStepHedgehogMoving(Gear: PGear); forward;
   121 procedure doStepHedgehogMoving(Gear: PGear); forward;
   121 procedure HedgehogChAngle(Gear: PGear); forward;
   122 procedure HedgehogChAngle(Gear: PGear); forward;
   122 procedure ShotgunShot(Gear: PGear); forward;
   123 procedure ShotgunShot(Gear: PGear); forward;
   123 procedure PickUp(HH, Gear: PGear); forward;
   124 procedure PickUp(HH, Gear: PGear); forward;
   630 				or isInMultiShoot
   631 				or isInMultiShoot
   631 				or (TotalRounds = 0) then inc(step)
   632 				or (TotalRounds = 0) then inc(step)
   632 			else begin
   633 			else begin
   633 				bBetweenTurns:= true;
   634 				bBetweenTurns:= true;
   634 				HealthMachine;
   635 				HealthMachine;
   635                 SuddenDeathDmg:= true;
   636 				SuddenDeathDmg:= true;
   636 				step:= stChDmg
   637 				step:= stChDmg
   637 				end
   638 				end
   638 			end;
   639 			end;
   639 	stSpawn: begin
   640 	stSpawn: begin
   640 			if not isInMultiShoot then SpawnBoxOfSmth;
   641 			if not isInMultiShoot then SpawnBoxOfSmth;
   812 	hx, hy, cx, cy, tx, ty, sx, sy, m: LongInt;  // hedgehog, crosshair, temp, sprite, direction
   813 	hx, hy, cx, cy, tx, ty, sx, sy, m: LongInt;  // hedgehog, crosshair, temp, sprite, direction
   813 	lx, ly, dx, dy, ax, ay, aAngle, dAngle, hAngle: real;  // laser, change
   814 	lx, ly, dx, dy, ax, ay, aAngle, dAngle, hAngle: real;  // laser, change
   814 	defaultPos, HatVisible: boolean;
   815 	defaultPos, HatVisible: boolean;
   815     VertexBuffer: array [0..1] of TVertex2f;
   816     VertexBuffer: array [0..1] of TVertex2f;
   816 begin
   817 begin
       
   818 if PHedgehog(Gear^.Hedgehog)^.Unplaced then exit;
   817 m:= 1;
   819 m:= 1;
   818 if ((Gear^.State and gstHHHJump) <> 0) and not cArtillery then m:= -1;
   820 if ((Gear^.State and gstHHHJump) <> 0) and not cArtillery then m:= -1;
   819 if (Gear^.State and gstHHDeath) <> 0 then
   821 if (Gear^.State and gstHHDeath) <> 0 then
   820 	begin
   822 	begin
   821 	DrawSprite(sprHHDeath, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 26 + WorldDy, Gear^.Pos);
   823 	DrawSprite(sprHHDeath, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 26 + WorldDy, Gear^.Pos);
  1520        gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 0)
  1522        gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 0)
  1521                                      else DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 1);
  1523                                      else DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 1);
  1522          gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
  1524          gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
  1523         gtTeleport: begin
  1525         gtTeleport: begin
  1524                     HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  1526                     HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
  1525                     DrawRotatedF(sprTeleport, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, Gear^.Pos, hwSign(HHGear^.dX), 0);
  1527                     if not PHedgehog(Gear^.Hedgehog)^.Unplaced then DrawRotatedF(sprTeleport, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, Gear^.Pos, hwSign(HHGear^.dX), 0);
  1526                     DrawRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0);
  1528                     DrawRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0);
  1527                     end;
  1529                     end;
  1528         gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, (GameTicks shr 6) mod 12);
  1530         gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, (GameTicks shr 6) mod 12);
  1529           gtTarget: begin
  1531           gtTarget: begin
  1530 					glColor4f(1, 1, 1, Gear^.Timer / 1000);
  1532 					glColor4f(1, 1, 1, Gear^.Timer / 1000);
  1783 				with Teams[j]^ do
  1785 				with Teams[j]^ do
  1784 					for i:= 0 to cMaxHHIndex do
  1786 					for i:= 0 to cMaxHHIndex do
  1785 						with Hedgehogs[i] do
  1787 						with Hedgehogs[i] do
  1786 							if (Gear <> nil) and (Gear^.X.QWordValue = 0) then
  1788 							if (Gear <> nil) and (Gear^.X.QWordValue = 0) then
  1787 								begin
  1789 								begin
  1788 								FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil
  1790                                 FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil
  1789 								if Gear <> nil then
  1791 								if Gear <> nil then
  1790 									begin
  1792 									begin
  1791 									Gear^.Pos:= GetRandom(49);
  1793 									Gear^.Pos:= GetRandom(49);
  1792 									Gear^.dX.isNegative:= p = 1;
  1794 									Gear^.dX.isNegative:= p = 1;
  1793 									end
  1795 									end
  1794 								end;
  1796 								end;
  1795 		t:= LAND_WIDTH div 2
  1797 		t:= LAND_WIDTH div 2
  1796 		end
  1798 		end
  1797 	end else // mix hedgehogs
  1799 	end else // mix hedgehogs
  1798 	begin
  1800 	begin
       
  1801     if (GameFlags and gfPlaceHog) <> 0 then PlacingHogs:= true;
  1799 	Count:= 0;
  1802 	Count:= 0;
  1800 	for p:= 0 to Pred(TeamsCount) do
  1803 	for p:= 0 to Pred(TeamsCount) do
  1801 		with TeamsArray[p]^ do
  1804 		with TeamsArray[p]^ do
  1802 		begin
  1805 		begin
  1803 		for i:= 0 to cMaxHHIndex do
  1806 		for i:= 0 to cMaxHHIndex do
  1813     //it would be nice if divide teams, forts mode and hh per map could all be checked by the team widget, or maybe disable start button
  1816     //it would be nice if divide teams, forts mode and hh per map could all be checked by the team widget, or maybe disable start button
  1814 	TryDo(Count <= MaxHedgehogs, 'Too many hedgehogs for this map! (max # is ' + inttostr(MaxHedgehogs) + ')', true);
  1817 	TryDo(Count <= MaxHedgehogs, 'Too many hedgehogs for this map! (max # is ' + inttostr(MaxHedgehogs) + ')', true);
  1815 	while (Count > 0) do
  1818 	while (Count > 0) do
  1816 		begin
  1819 		begin
  1817 		i:= GetRandom(Count);
  1820 		i:= GetRandom(Count);
  1818 		FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH);
  1821         if PlacingHogs then ar[i]^.Unplaced:= true
       
  1822         else FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH);
  1819 		if ar[i]^.Gear <> nil then
  1823 		if ar[i]^.Gear <> nil then
  1820 			begin
  1824 			begin
  1821 			ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > LAND_WIDTH div 2;
  1825 			ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > LAND_WIDTH div 2;
  1822 			ar[i]^.Gear^.Pos:= GetRandom(19)
  1826 			ar[i]^.Gear^.Pos:= GetRandom(19)
  1823 			end;
  1827 			end;
  1897 
  1901 
  1898 procedure SpawnBoxOfSmth;
  1902 procedure SpawnBoxOfSmth;
  1899 var t: LongInt;
  1903 var t: LongInt;
  1900     i: TAmmoType;
  1904     i: TAmmoType;
  1901 begin
  1905 begin
  1902 if (cCaseFactor = 0) or
  1906 if (PlacingHogs) or
       
  1907    (cCaseFactor = 0) or
  1903    (CountGears(gtCase) >= 5) or
  1908    (CountGears(gtCase) >= 5) or
  1904    (getrandom(cCaseFactor) <> 0) then exit;
  1909    (getrandom(cCaseFactor) <> 0) then exit;
  1905 
  1910 
  1906 FollowGear:= nil;
  1911 FollowGear:= nil;
  1907 
  1912