# HG changeset patch # User unc0rr # Date 1202234018 0 # Node ID 4f59db6f147d7a63c79b328cab460bdd27ce9b78 # Parent e2d2b84aa77614f029daa1b336982fffb564fe8a - New command 'set weapon' - Fixes bug with changing weapon while switching hedgehogs diff -r e2d2b84aa776 -r 4f59db6f147d doc/protocol.txt --- a/doc/protocol.txt Sun Feb 03 17:02:20 2008 +0000 +++ b/doc/protocol.txt Tue Feb 05 17:53:38 2008 +0000 @@ -10,7 +10,8 @@ 's' + <текст> /say '+' пустой пакет для постоянности лага '1'..'5' /timer 1..5 - chr(128+№) /slot № + chr(128+№) /slot № + 'w' /setweap 'p' /put 'j' /ljump 'J' /hjump diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/CCHandlers.inc Tue Feb 05 17:53:38 2008 +0000 @@ -294,34 +294,27 @@ procedure chSlot(var s: shortstring); var slot: LongWord; - caSlot, caAmmo: PLongword; begin if (s[0] <> #1) or CheckNoTeamOrHH then exit; bShowFinger:= false; slot:= byte(s[1]) - 49; if slot > cMaxSlotIndex then exit; if not CurrentTeam^.ExtDriven then SendIPC(char(byte(s[1]) + 79)); -with CurrentTeam^ do +with CurrentHedgehog^.Gear^ do begin - with Hedgehogs[CurrHedgehog] do - begin - if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) - or ((Gear^.State and gstHHDriven) = 0) then exit; - Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump); - if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end - else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; - if caSlot^ = slot then - begin - inc(caAmmo^); - if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo^[slot, caAmmo^].Count = 0) then caAmmo^:= 0 - end else - if Ammo^[slot, 0].Count > 0 then - begin - caSlot^:= slot; - caAmmo^:= 0; - end; - end; - ApplyAmmoChanges(Hedgehogs[CurrHedgehog]) + Message:= Message or gm_Slot; + MsgParam:= slot + end +end; + +procedure chSetWeapon(var s: shortstring); +begin +if (s[0] <> #1) or CheckNoTeamOrHH then exit; +if not CurrentTeam^.ExtDriven then SendIPC('w' + char(byte(s[1]) + 79)); +with CurrentHedgehog^.Gear^ do + begin + Message:= Message or gm_Weapon; + MsgParam:= byte(s[1]) - ord('a') end end; diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/HHHandlers.inc Tue Feb 05 17:53:38 2008 +0000 @@ -17,6 +17,55 @@ *) //////////////////////////////////////////////////////////////////////////////// +procedure ChangeAmmo(Gear: PGear); +var slot: Longword; + caSlot, caAmmo: PLongword; +begin +slot:= Gear^.MsgParam; + +with PHedgehog(Gear^.Hedgehog)^ do + begin + if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) + or ((Gear^.State and gstHHDriven) = 0) then exit; + + Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump or gm_Slot); + + if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end + else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; + + if caSlot^ = slot then + begin + inc(caAmmo^); + if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo^[slot, caAmmo^].Count = 0) then caAmmo^:= 0 + end else + if Ammo^[slot, 0].Count > 0 then + begin + caSlot^:= slot; + caAmmo^:= 0; + end; + end; +ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^) +end; + +procedure HHSetWeapon(Gear: PGear); +var t: LongInt; + weap: TAmmoType; +begin +weap:= TAmmoType(Gear^.MsgParam); +Gear^.MsgParam:= Ammoz[weap].Slot; + +t:= cMaxSlotAmmoIndex; + +Gear^.Message:= Gear^.Message and not gm_Weapon; + +with PHedgehog(Gear^.Hedgehog)^ do + while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do + begin + ChangeAmmo(Gear); + dec(t) + end +end; + procedure Attack(Gear: PGear); var xx, yy: hwFloat; begin @@ -282,7 +331,7 @@ end; if (Gear^.State <> 0) then DeleteCI(Gear); - + if (Gear^.State and gstMoving) <> 0 then if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then if not isFalling then @@ -362,6 +411,10 @@ exit end; +if ((Gear^.Message and gm_Slot) <> 0) then ChangeAmmo(Gear); + +if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear); + if ((Gear^.Message and gm_Attack) <> 0) or ((Gear^.State and gstAttacking) <> 0) then Attack(Gear); diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uAIActions.pas --- a/hedgewars/uAIActions.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uAIActions.pas Tue Feb 05 17:53:38 2008 +0000 @@ -60,7 +60,7 @@ procedure ProcessAction(var Actions: TActions; Me: PGear); implementation -uses uMisc, uTeams, uConsts, uConsole, uAIMisc, uAI; +uses uMisc, uTeams, uConsts, uConsole, uAIMisc, uAI, uAmmos; const ActionIdToStr: array[0..6] of string[16] = ( {aia_none} '', diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uAmmos.pas Tue Feb 05 17:53:38 2008 +0000 @@ -29,9 +29,10 @@ procedure OnUsedAmmo(var Hedgehog: THedgehog); procedure ApplyAmmoChanges(var Hedgehog: THedgehog); procedure SwitchNotHoldedAmmo(var Hedgehog: THedgehog); +procedure SetWeapon(weap: TAmmoType); implementation -uses uMisc, uGears, uWorld, uLocale; +uses uMisc, uGears, uWorld, uLocale, uConsole; type TAmmoCounts = array[TAmmoType] of Longword; var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo; StoreCnt: Longword = 0; @@ -214,4 +215,9 @@ end end; +procedure SetWeapon(weap: TAmmoType); +begin +ParseCommand('/setweap ' + chr(ord('a') + byte(weap)), true) +end; + end. diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uConsole.pas Tue Feb 05 17:53:38 2008 +0000 @@ -317,6 +317,7 @@ RegisterVariable('switch' , vtCommand, @chSwitch , false); RegisterVariable('nextturn', vtCommand, @chNextTurn , false); RegisterVariable('timer' , vtCommand, @chTimer , false); +RegisterVariable('setweap' , vtCommand, @chSetWeapon , false); RegisterVariable('slot' , vtCommand, @chSlot , false); RegisterVariable('put' , vtCommand, @chPut , false); RegisterVariable('ljump' , vtCommand, @chLJump , false); diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uConsts.pas Tue Feb 05 17:53:38 2008 +0000 @@ -170,6 +170,8 @@ gm_LJump = $00000040; gm_HJump = $00000080; gm_Destroy= $00000100; + gm_Slot = $00000200; // with param + gm_Weapon = $00000400; // with param cMaxSlotIndex = 8; cMaxSlotAmmoIndex = 2; diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uGears.pas --- a/hedgewars/uGears.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uGears.pas Tue Feb 05 17:53:38 2008 +0000 @@ -41,7 +41,7 @@ Timer : LongWord; Elasticity: hwFloat; Friction : hwFloat; - Message : Longword; + Message, MsgParam : Longword; Hedgehog: pointer; Health, Damage: LongInt; CollisionIndex: LongInt; diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uTeams.pas Tue Feb 05 17:53:38 2008 +0000 @@ -87,7 +87,6 @@ procedure RecountTeamHealth(team: PTeam); procedure RestoreTeamsFromSave; function CheckForWin: boolean; -procedure SetWeapon(weap: TAmmoType); procedure SendStats; implementation @@ -319,19 +318,6 @@ TeamsArray[t]^.ExtDriven:= false end; -procedure SetWeapon(weap: TAmmoType); -var t: LongInt; -begin -t:= cMaxSlotAmmoIndex; -with CurrentTeam^ do - with Hedgehogs[CurrHedgehog] do - while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do - begin - ParseCommand('/slot ' + chr(49 + Ammoz[TAmmoType(weap)].Slot), true); - dec(t) - end -end; - procedure SendStats; var i, t: LongInt; msd: Longword; msdhh: PHedgehog; diff -r e2d2b84aa776 -r 4f59db6f147d hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Sun Feb 03 17:02:20 2008 +0000 +++ b/hedgewars/uWorld.pas Tue Feb 05 17:53:38 2008 +0000 @@ -38,7 +38,7 @@ Frames: Longword = 0; implementation -uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL; +uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL, uAmmos; const FPS: Longword = 0; CountTicks: Longword = 0; SoundTimerTicks: Longword = 0;