~ubuntu-branches/ubuntu/quantal/hedgewars/quantal

« back to all changes in this revision

Viewing changes to hedgewars/uConsole.pas

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2010-12-28 23:29:54 UTC
  • mfrom: (1.1.9 upstream) (3.2.10 sid)
  • Revision ID: james.westby@ubuntu.com-20101228232954-uvcytyhesmdhhd5e
Tags: 0.9.15-1
* New upstream version.
 + Ability to create, save and load hand drawn maps
 + New maps: Capture the Flag (Blizzard) Map
 + New themes: Christmas
 + Snowflakes on Christmas/Snow themes accumulates on the ground
 + New game modifiers: No wind, More wind
 + New missions: Dangerous ducklings, Diver, Spooky tree, Teamwork
 + New weapons: Mudball, Drill strike
 + Many more Lua hooks
 + Readytimer
 + Ability to edit seed
 + Ability to select gameplay scripts
 + New gameplay scripts: Capture the Flag, No jumping, Random weapon
 + New Lua unified translation framework
 + Code refactoring
 + Max teams upped to 8
 + Cosmetic enhancements to Napalm strike
 + Selecting a game scheme selects the corresponding weapon set
 + Dust when drills dig
 + New hats: beaver, porkey, sheep
 + Add density property to Gears
 + Reworked management of schemes and weapon sets
 + Will ask before deleting teams, schemes and weapon sets
 + Explosions detach rope from land
 + Allow hog speech when not your turn

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
unit uConsole;
22
22
interface
23
 
uses uFloat;
24
 
 
25
 
var isDeveloperMode: boolean;
26
 
type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean);
27
 
     TCommandHandler = procedure (var params: shortstring);
28
23
 
29
24
procedure initModule;
30
25
procedure freeModule;
31
26
procedure WriteToConsole(s: shortstring);
32
27
procedure WriteLnToConsole(s: shortstring);
33
 
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
34
 
procedure StopMessages(Message: Longword);
35
28
function  GetLastConsoleLine: shortstring;
36
29
 
37
 
procedure doPut(putX, putY: LongInt; fromAI: boolean);
38
 
 
39
30
implementation
40
 
uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uMobile,
41
 
     uRandom, uAmmos, uStats, uChat, SDLh, uSound, uVisualGears, uScript;
 
31
uses Types, uVariables, uUtils;
42
32
 
43
33
const cLineWidth: LongInt = 0;
44
 
      cLinesCount = 256;
 
34
      cLinesCount = 8;
45
35
 
46
 
type  PVariable = ^TVariable;
47
 
      TVariable = record
48
 
                     Next: PVariable;
49
 
                     Name: string[15];
50
 
                    VType: TVariableType;
51
 
                  Handler: pointer;
52
 
                  Trusted: boolean;
53
 
                  end;
 
36
type
54
37
      TTextLine = record
55
38
                  s: shortstring;
56
39
                  end;
57
40
 
58
41
var   ConsoleLines: array[byte] of TTextLine;
59
42
      CurrLine: LongInt;
60
 
      Variables: PVariable;
61
43
 
62
44
procedure SetLine(var tl: TTextLine; str: shortstring);
63
45
begin
65
47
     s:= str;
66
48
end;
67
49
 
68
 
function RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean): PVariable;
69
 
var value: PVariable;
70
 
begin
71
 
New(value);
72
 
TryDo(value <> nil, 'RegisterVariable: value = nil', true);
73
 
FillChar(value^, sizeof(TVariable), 0);
74
 
value^.Name:= Name;
75
 
value^.VType:= VType;
76
 
value^.Handler:= p;
77
 
value^.Trusted:= Trusted;
78
 
 
79
 
if Variables = nil then Variables:= value
80
 
                   else begin
81
 
                        value^.Next:= Variables;
82
 
                        Variables:= value
83
 
                        end;
84
 
 
85
 
RegisterVariable:= value;
86
 
end;
87
 
 
88
50
procedure WriteToConsole(s: shortstring);
89
51
var Len: LongInt;
90
52
    done: boolean;
91
53
begin
92
54
{$IFNDEF NOCONSOLE}
93
 
{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF}
 
55
{$IFDEF DEBUGFILE}AddFileLog('[Con] ' + s);{$ENDIF}
94
56
Write(s);
95
57
done:= false;
96
58
 
122
84
{$ENDIF}
123
85
end;
124
86
 
125
 
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
126
 
var ii: LongInt;
127
 
    s: shortstring;
128
 
    t: PVariable;
129
 
    c: char;
130
 
begin
131
 
//WriteLnToConsole(CmdStr);
132
 
if CmdStr[0]=#0 then exit;
133
 
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF}
134
 
c:= CmdStr[1];
135
 
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/';
136
 
s:= '';
137
 
SplitBySpace(CmdStr, s);
138
 
t:= Variables;
139
 
while t <> nil do
140
 
      begin
141
 
      if t^.Name = CmdStr then
142
 
         begin
143
 
         if TrustedSource or t^.Trusted then
144
 
            case t^.VType of
145
 
              vtCommand: if c='/' then
146
 
                         begin
147
 
                         TCommandHandler(t^.Handler)(s);
148
 
                         end;
149
 
              vtLongInt: if c='$' then
150
 
                         if s[0]=#0 then
151
 
                            begin
152
 
                            str(PLongInt(t^.Handler)^, s);
153
 
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
154
 
                            end else val(s, PLongInt(t^.Handler)^);
155
 
              vthwFloat: if c='$' then
156
 
                         if s[0]=#0 then
157
 
                            begin
158
 
                            //str(PhwFloat(t^.Handler)^:4:6, s);
159
 
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
160
 
                            end else; //val(s, PhwFloat(t^.Handler)^, i);
161
 
             vtBoolean: if c='$' then
162
 
                         if s[0]=#0 then
163
 
                            begin
164
 
                            str(ord(boolean(t^.Handler^)), s);
165
 
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
166
 
                            end else
167
 
                            begin
168
 
                            val(s, ii);
169
 
                            boolean(t^.Handler^):= not (ii = 0)
170
 
                            end;
171
 
              end;
172
 
         exit
173
 
         end else t:= t^.Next
174
 
      end;
175
 
case c of
176
 
     '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"')
177
 
     else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
178
 
end;
179
87
 
180
88
function GetLastConsoleLine: shortstring;
181
89
var valueStr: shortstring;
192
100
GetLastConsoleLine:= valueStr;
193
101
end;
194
102
 
195
 
procedure StopMessages(Message: Longword);
196
 
begin
197
 
if (Message and gmLeft) <> 0 then ParseCommand('/-left', true) else
198
 
if (Message and gmRight) <> 0 then ParseCommand('/-right', true) else
199
 
if (Message and gmUp) <> 0 then ParseCommand('/-up', true) else
200
 
if (Message and gmDown) <> 0 then ParseCommand('/-down', true) else
201
 
if (Message and gmAttack) <> 0 then ParseCommand('/-attack', true)
202
 
end;
203
 
 
204
 
{$INCLUDE "CCHandlers.inc"}
205
103
procedure initModule;
206
104
var i: LongInt;
207
105
begin
208
106
    CurrLine:= 0;
209
 
    Variables:= nil;
210
 
    isDeveloperMode:= true;
211
107
 
212
108
    // initConsole
213
109
    cLineWidth:= cScreenWidth div 10;
215
111
        cLineWidth:= 255;
216
112
    for i:= 0 to Pred(cLinesCount) do
217
113
        PByte(@ConsoleLines[i])^:= 0;
218
 
 
219
 
    // NOTE: please, keep most frequently used commands on bottom
220
 
    RegisterVariable('flag'    , vtCommand, @chFlag         , false);
221
 
    RegisterVariable('script'  , vtCommand, @chScript       , false);
222
 
    RegisterVariable('proto'   , vtCommand, @chCheckProto   , true );
223
 
    RegisterVariable('spectate', vtBoolean, @fastUntilLag   , false);
224
 
    RegisterVariable('capture' , vtCommand, @chCapture      , true );
225
 
    RegisterVariable('rotmask' , vtCommand, @chRotateMask   , true );
226
 
    RegisterVariable('addteam' , vtCommand, @chAddTeam      , false);
227
 
    RegisterVariable('rdriven' , vtCommand, @chTeamLocal    , false);
228
 
    RegisterVariable('map'     , vtCommand, @chSetMap       , false);
229
 
    RegisterVariable('theme'   , vtCommand, @chSetTheme     , false);
230
 
    RegisterVariable('seed'    , vtCommand, @chSetSeed      , false);
231
 
    RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false);
232
 
    RegisterVariable('mapgen'  , vtLongInt, @cMapGen        , false);
233
 
    RegisterVariable('maze_size',vtLongInt, @cMazeSize      , false);
234
 
    RegisterVariable('delay'   , vtLongInt, @cInactDelay    , false);
235
 
    RegisterVariable('ready'   , vtLongInt, @cReadyDelay    , false);
236
 
    RegisterVariable('casefreq', vtLongInt, @cCaseFactor    , false);
237
 
    RegisterVariable('healthprob', vtLongInt, @cHealthCaseProb, false);
238
 
    RegisterVariable('hcaseamount', vtLongInt, @cHealthCaseAmount, false);
239
 
    RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns  , false);
240
 
    RegisterVariable('waterrise', vtLongInt, @cWaterRise    , false);
241
 
    RegisterVariable('healthdec', vtLongInt, @cHealthDecrease, false);
242
 
    RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false);
243
 
    RegisterVariable('minedudpct',vtLongInt,@cMineDudPercent, false);
244
 
    RegisterVariable('minesnum', vtLongInt, @cLandMines     , false);
245
 
    RegisterVariable('explosives',vtLongInt,@cExplosives    , false);
246
 
    RegisterVariable('gmflags' , vtLongInt, @GameFlags      , false);
247
 
    RegisterVariable('trflags' , vtLongInt, @TrainingFlags  , false);
248
 
    RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
249
 
    RegisterVariable('minestime',vtLongInt, @cMinesTime     , false);
250
 
    RegisterVariable('fort'    , vtCommand, @chFort         , false);
251
 
    RegisterVariable('voicepack',vtCommand, @chVoicepack    , false);
252
 
    RegisterVariable('grave'   , vtCommand, @chGrave        , false);
253
 
    RegisterVariable('bind'    , vtCommand, @chBind         , true );
254
 
    RegisterVariable('addhh'   , vtCommand, @chAddHH        , false);
255
 
    RegisterVariable('hat'     , vtCommand, @chSetHat       , false);
256
 
    RegisterVariable('hhcoords', vtCommand, @chSetHHCoords  , false);
257
 
    RegisterVariable('ammloadt', vtCommand, @chSetAmmoLoadout, false);
258
 
    RegisterVariable('ammdelay', vtCommand, @chSetAmmoDelay, false);
259
 
    RegisterVariable('ammprob',  vtCommand, @chSetAmmoProbability, false);
260
 
    RegisterVariable('ammreinf', vtCommand, @chSetAmmoReinforcement, false);
261
 
    RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
262
 
    RegisterVariable('quit'    , vtCommand, @chQuit         , true );
263
 
    RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
264
 
    RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
265
 
    RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
266
 
    RegisterVariable('zoomin'  , vtCommand, @chZoomIn       , true );
267
 
    RegisterVariable('zoomout' , vtCommand, @chZoomOut      , true );
268
 
    RegisterVariable('zoomreset',vtCommand, @chZoomReset    , true );
269
 
    RegisterVariable('skip'    , vtCommand, @chSkip         , false);
270
 
    RegisterVariable('history' , vtCommand, @chHistory      , true );
271
 
    RegisterVariable('chat'    , vtCommand, @chChat         , true );
272
 
    RegisterVariable('say'     , vtCommand, @chSay          , true );
273
 
    RegisterVariable('hogsay'  , vtCommand, @chHogSay       , true );
274
 
    RegisterVariable('team'    , vtCommand, @chTeamSay      , true );
275
 
    RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , true);
276
 
    RegisterVariable('+precise', vtCommand, @chPrecise_p    , false);
277
 
    RegisterVariable('-precise', vtCommand, @chPrecise_m    , false);
278
 
    RegisterVariable('+left'   , vtCommand, @chLeft_p       , false);
279
 
    RegisterVariable('-left'   , vtCommand, @chLeft_m       , false);
280
 
    RegisterVariable('+right'  , vtCommand, @chRight_p      , false);
281
 
    RegisterVariable('-right'  , vtCommand, @chRight_m      , false);
282
 
    RegisterVariable('+up'     , vtCommand, @chUp_p         , false);
283
 
    RegisterVariable('-up'     , vtCommand, @chUp_m         , false);
284
 
    RegisterVariable('+down'   , vtCommand, @chDown_p       , false);
285
 
    RegisterVariable('-down'   , vtCommand, @chDown_m       , false);
286
 
    RegisterVariable('+attack' , vtCommand, @chAttack_p     , false);
287
 
    RegisterVariable('-attack' , vtCommand, @chAttack_m     , false);
288
 
    RegisterVariable('switch'  , vtCommand, @chSwitch       , false);
289
 
    RegisterVariable('nextturn', vtCommand, @chNextTurn     , false);
290
 
    RegisterVariable('timer'   , vtCommand, @chTimer        , false);
291
 
    RegisterVariable('taunt'   , vtCommand, @chTaunt        , false);
292
 
    RegisterVariable('setweap' , vtCommand, @chSetWeapon    , false);
293
 
    RegisterVariable('slot'    , vtCommand, @chSlot         , false);
294
 
    RegisterVariable('put'     , vtCommand, @chPut          , false);
295
 
    RegisterVariable('ljump'   , vtCommand, @chLJump        , false);
296
 
    RegisterVariable('hjump'   , vtCommand, @chHJump        , false);
297
 
    RegisterVariable('fullscr' , vtCommand, @chFullScr      , true );
298
 
    RegisterVariable('+volup'  , vtCommand, @chVol_p        , true );
299
 
    RegisterVariable('-volup'  , vtCommand, @chVol_m        , true );
300
 
    RegisterVariable('+voldown', vtCommand, @chVol_m        , true );
301
 
    RegisterVariable('-voldown', vtCommand, @chVol_p        , true );
302
 
    RegisterVariable('findhh'  , vtCommand, @chFindhh       , true );
303
 
    RegisterVariable('pause'   , vtCommand, @chPause        , true );
304
 
    RegisterVariable('+cur_u'  , vtCommand, @chCurU_p       , true );
305
 
    RegisterVariable('-cur_u'  , vtCommand, @chCurU_m       , true );
306
 
    RegisterVariable('+cur_d'  , vtCommand, @chCurD_p       , true );
307
 
    RegisterVariable('-cur_d'  , vtCommand, @chCurD_m       , true );
308
 
    RegisterVariable('+cur_l'  , vtCommand, @chCurL_p       , true );
309
 
    RegisterVariable('-cur_l'  , vtCommand, @chCurL_m       , true );
310
 
    RegisterVariable('+cur_r'  , vtCommand, @chCurR_p       , true );
311
 
    RegisterVariable('-cur_r'  , vtCommand, @chCurR_m       , true );
312
114
end;
313
115
 
314
116
procedure freeModule;
315
 
var t, tt: PVariable;
316
117
begin
317
 
    tt:= Variables;
318
 
    Variables:= nil;
319
 
    while tt <> nil do
320
 
    begin
321
 
        t:= tt;
322
 
        tt:= tt^.Next;
323
 
        Dispose(t)
324
 
    end;
 
118
 
325
119
end;
326
120
 
327
121
end.