(* * Hedgewars, a worms-like game * Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA *)function CheckNoTeamOrHH: boolean;var Result: boolean;beginResult:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);{$IFDEF DEBUGFILE}if Result then if CurrentTeam = nil then AddFileLog('CONSOLE: CurTeam = nil') else AddFileLog('CONSOLE: CurTeam <> nil, Gear = nil');{$ENDIF}CheckNoTeamOrHH:= Resultend;////////////////////////////////////////////////////////////////////////////////procedure chQuit(var s: shortstring);beginSendIPC('Q');GameState:= gsExitend;procedure chCheckProto(var s: shortstring);var i, c: LongInt;beginif isDeveloperMode then begin val(s, i, c); if (c <> 0) or (i = 0) then exit; TryDo(i <= cNetProtoVersion, 'Protocol version mismatch: engine is too old', true); TryDo(i >= cNetProtoVersion, 'Protocol version mismatch: engine is too new', true) endend;procedure chAddTeam(var s: shortstring);var Color: Longword; ts: shortstring;beginif isDeveloperMode then begin SplitBySpace(s, ts); val(s, Color); TryDo(Color <> 0, 'Error: black team color', true); AddTeam(Color); CurrentTeam^.TeamName:= ts; if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true endend;procedure chTeamLocal(var s: shortstring);beginif not isDeveloperMode then exit;if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/rdriven"', true);CurrentTeam^.ExtDriven:= trueend;procedure chGrave(var s: shortstring);beginif CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true);if s[1]='"' then Delete(s, 1, 1);if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);CurrentTeam^.GraveName:= send;procedure chFort(var s: shortstring);beginif CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true);if s[1]='"' then Delete(s, 1, 1);if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);CurrentTeam^.FortName:= send;procedure chAddHH(var id: shortstring);var s: shortstring; Gear: PGear;beginif (not isDeveloperMode) or (CurrentTeam = nil) then exit;with CurrentTeam^ do begin SplitBySpace(id, s); CurrentHedgehog:= @Hedgehogs[HedgehogsNumber]; val(id, CurrentHedgehog^.BotLevel); Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0); SplitBySpace(s, id); val(s, Gear^.Health); TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true); PHedgehog(Gear^.Hedgehog)^.Team:= CurrentTeam; Hedgehogs[HedgehogsNumber].AmmoStore:= TeamsCount - 1; // FIXME HACK to get ammostores work Hedgehogs[HedgehogsNumber].Gear:= Gear; Hedgehogs[HedgehogsNumber].Name:= id; inc(HedgehogsNumber) endend;procedure chSetHHCoords(var x: shortstring);var y: shortstring; t: Longint;beginif (not isDeveloperMode) or (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then exit;SplitBySpace(x, y);val(x, t);CurrentHedgehog^.Gear^.X:= int2hwFloat(t);val(y, t);CurrentHedgehog^.Gear^.Y:= int2hwFloat(t)end;procedure chAddAmmoStore(var descr: shortstring);beginAddAmmoStore(descr)end;procedure chBind(var id: shortstring);var s: shortstring; b: LongInt;beginif CurrentTeam = nil then exit;SplitBySpace(id, s);if s[1]='"' then Delete(s, 1, 1);if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);b:= KeyNameToCode(id);if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"', false) else CurrentTeam^.Binds[b]:= send;procedure chLeft_p(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;if not CurrentTeam^.ExtDriven then SendIPC('L');with CurrentHedgehog^.Gear^ do Message:= Message or gm_Leftend;procedure chLeft_m(var s: shortstring);beginif CheckNoTeamOrHH then exit;if not CurrentTeam^.ExtDriven then SendIPC('l');with CurrentHedgehog^.Gear^ do Message:= Message and not gm_Leftend;procedure chRight_p(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;if not CurrentTeam^.ExtDriven then SendIPC('R');with CurrentHedgehog^.Gear^ do Message:= Message or gm_Rightend;procedure chRight_m(var s: shortstring);beginif CheckNoTeamOrHH then exit;if not CurrentTeam^.ExtDriven then SendIPC('r');with CurrentHedgehog^.Gear^ do Message:= Message and not gm_Rightend;procedure chUp_p(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;if not CurrentTeam^.ExtDriven then SendIPC('U');with CurrentHedgehog^.Gear^ do Message:= Message or gm_Upend;procedure chUp_m(var s: shortstring);beginif CheckNoTeamOrHH then exit;if not CurrentTeam^.ExtDriven then SendIPC('u');with CurrentHedgehog^.Gear^ do Message:= Message and not gm_Upend;procedure chDown_p(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;if not CurrentTeam^.ExtDriven then SendIPC('D');with CurrentHedgehog^.Gear^ do Message:= Message or gm_Downend;procedure chDown_m(var s: shortstring);beginif CheckNoTeamOrHH then exit;if not CurrentTeam^.ExtDriven then SendIPC('d');with CurrentHedgehog^.Gear^ do Message:= Message and not gm_Downend;procedure chLJump(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;if not CurrentTeam^.ExtDriven then SendIPC('j');with CurrentHedgehog^.Gear^ do Message:= Message or gm_LJumpend;procedure chHJump(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;if not CurrentTeam^.ExtDriven then SendIPC('J');with CurrentHedgehog^.Gear^ do Message:= Message or gm_HJumpend;procedure chAttack_p(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= false;with CurrentHedgehog^.Gear^ do begin {$IFDEF DEBUGFILE}AddFileLog('/+attack: Gear^.State = '+inttostr(State));{$ENDIF} if ((State and gstHHDriven) <> 0) and ((State and (gstAttacked or gstHHChooseTarget)) = 0) then begin FollowGear:= CurrentHedgehog^.Gear; if not CurrentTeam^.ExtDriven then SendIPC('A'); Message:= Message or gm_Attack end endend;procedure chAttack_m(var s: shortstring);beginif CheckNoTeamOrHH then exit;with CurrentHedgehog^.Gear^ do begin if not CurrentTeam^.ExtDriven and ((Message and gm_Attack) <> 0) then SendIPC('a'); Message:= Message and not gm_Attack endend;procedure chSwitch(var s: shortstring);beginif CheckNoTeamOrHH then exit;if not CurrentTeam^.ExtDriven then SendIPC('S');with CurrentHedgehog^.Gear^ do Message:= Message or gm_Switchend;procedure chNextTurn(var s: shortstring);beginif AllInactive then begin if not CurrentTeam^.ExtDriven then SendIPC('N'); TickTrigger(trigTurns); {$IFDEF DEBUGFILE}AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));{$ENDIF} SwitchHedgehog; endend;procedure chSay(var s: shortstring);beginWriteLnToConsole('> ' + s);SendIPC('s'+s)end;procedure chTimer(var s: shortstring);beginif (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit;bShowFinger:= false;with CurrentHedgehog^ do if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then begin Ammo^[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48); with CurrentTeam^ do ApplyAmmoChanges(Hedgehogs[CurrHedgehog]); if not CurrentTeam^.ExtDriven then SendIPC(s); endend;procedure chSlot(var s: shortstring);var slot: LongWord; caSlot, caAmmo: PLongword;beginif (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 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]) endend;procedure doPut(putX, putY: LongInt; fromAI: boolean);beginif CheckNoTeamOrHH then exit;if bShowAmmoMenu then begin bSelected:= true; exit end;with CurrentHedgehog^.Gear^, CurrentHedgehog^ do if (State and gstHHChooseTarget) <> 0 then begin isCursorVisible:= false; if not CurrentTeam^.ExtDriven then begin if fromAI then begin TargetPoint.X:= putX; TargetPoint.Y:= putY end else begin SDL_GetMouseState(@TargetPoint.X, @TargetPoint.Y); dec(TargetPoint.X, WorldDx); dec(TargetPoint.Y, WorldDy) end; SendIPCXY('p', TargetPoint.X, TargetPoint.Y); end; State:= State and not gstHHChooseTarget; if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_AttackingPut) <> 0 then Message:= Message or gm_Attack; end else if CurrentTeam^.ExtDriven then OutError('got /put while not being in choose target mode', false)end;procedure chPut(var s: shortstring);begindoPut(0, 0, false)end;procedure chCapture(var s: shortstring);beginflagMakeCapture:= trueend;procedure chSkip(var s: shortstring);beginif not CurrentTeam^.ExtDriven then SendIPC(',');TurnTimeLeft:= 0end;procedure chSetMap(var s: shortstring);beginif isDeveloperMode then begin Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s; InitStepsFlags:= InitStepsFlags or cifMap endend;procedure chSetTheme(var s: shortstring);beginif isDeveloperMode then begin Pathz[ptCurrTheme]:= Pathz[ptThemes] + '/' + s; InitStepsFlags:= InitStepsFlags or cifTheme endend;procedure chSetSeed(var s: shortstring);beginif isDeveloperMode then begin SetRandomSeed(s); cSeed:= s; InitStepsFlags:= InitStepsFlags or cifRandomize endend;procedure chAmmoMenu(var s: shortstring);beginif CheckNoTeamOrHH then exit;with CurrentTeam^ do with Hedgehogs[CurrHedgehog] do begin bSelected:= false; if bShowAmmoMenu then bShowAmmoMenu:= false else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) or ((Gear^.State and gstHHDriven) = 0) then else bShowAmmoMenu:= true endend;procedure chFullScr(var s: shortstring);var flags: Longword;{$IFDEF DEBUGFILE} buf: array[byte] of char;{$ENDIF}beginif Length(s) = 0 then cFullScreen:= not cFullScreen else cFullScreen:= s = '1';flags:= SDL_HWSURFACE or SDL_DOUBLEBUF or SDL_HWACCEL;if cFullScreen then flags:= flags or SDL_FULLSCREEN else SDL_WM_SetCaption('Hedgewars', nil);SDL_FreeSurface(SDLPrimSurface);SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);{$IFDEF DEBUGFILE}AddFileLog('SDL video driver: ' + string(SDL_VideoDriverName(buf, sizeof(buf))));{$ENDIF}TryDo(SDLPrimSurface <> nil, errmsgCreateSurface, true);PixelFormat:= SDLPrimSurface^.formatend;procedure chVol_p(var s: shortstring);begininc(cVolumeDelta, 3)end;procedure chVol_m(var s: shortstring);begindec(cVolumeDelta, 3)end;procedure chFindhh(var s: shortstring);beginif CheckNoTeamOrHH then exit;bShowFinger:= true;FollowGear:= CurrentHedgehog^.Gearend;procedure chPause(var s: shortstring);beginisPaused:= not isPaused;SDL_ShowCursor(ord(isPaused))end;procedure chRotateMask(var s: shortstring);const map: array[0..7] of byte = (7,4,0,5,2,1,0,3);begincTagsMask:= map[cTagsMask]end;procedure chAddTrigger(var s: shortstring);var ttype, gt, geartrig, Ticks, Lives: LongWord; X, Y: LongInt; c: char; tmp: shortstring;beginc:= s[1];Delete(s, 1, 1);case c of 's': begin // s12345 1 1 33 0 0 123456 SplitBySpace(s, tmp); val(s, ttype); SplitBySpace(tmp, s); val(tmp, Ticks); SplitBySpace(s, tmp); val(s, Lives); SplitBySpace(tmp, s); val(tmp, gt); SplitBySpace(s, tmp); val(s, X); SplitBySpace(tmp, s); val(tmp, Y); SplitBySpace(s, tmp); val(s, geartrig); AddTriggerSpawner(ttype, Ticks, Lives, X, Y, TGearType(gt), geartrig); end; endend;