-
Notifications
You must be signed in to change notification settings - Fork 1
/
inc__r2bot.pas
490 lines (459 loc) · 20.6 KB
/
inc__r2bot.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
{*******************************************************************************
NFK [R2]
Bot Library
Contains:
function BD_Avail: boolean;
...
*******************************************************************************}
procedure DLL_RegisterProc1(ACallProc : TCallProcWordWordFunc); external 'bot.dll';
procedure DLL_RegisterProc2(ACallProc : TCallTextProc; ProcID: byte); external 'bot.dll';
procedure DLL_RegisterProc3(ACallProc : TCallProcSTR; ProcID: byte); external 'bot.dll';
procedure DLL_RegisterProc4(ACallProc : TCallProcCreatePlayer; ProcID: byte); external 'bot.dll';
procedure DLL_RegisterProc5(ACallProc : TCallProcWordByteFunc; ProcID: byte); external 'bot.dll';
procedure DLL_RegisterProc6(ACallProc : TCallProcWordWord_Bool; ProcID: byte); external 'bot.dll';
procedure DLL_RegisterProc7(ACallProc : TCallProcWordWordString; ProcID: byte); external 'bot.dll';
procedure DLL_RegisterProc8(ACallProc : TCallProcBrickStruct); external 'bot.dll';
procedure DLL_RegisterProc9(ACallProc : TCallProcObjectsStruct); external 'bot.dll';
procedure DLL_RegisterProc10(ACallProc : TCallProcSpecailObjectsStruct); external 'bot.dll';
procedure DLL_RegisterProc11(ACallProc : TCallProcWord); external 'bot.dll';
procedure DLL_RegisterProc12(ACallProc : TCallProcChat); external 'bot.dll';
procedure DLL_EVENT_BeginGame; external 'bot.dll';
procedure DLL_EVENT_ResetGame; external 'bot.dll';
procedure DLL_EVENT_MapChanged;external 'bot.dll';
procedure DLL_SYSTEM_AddPlayer(Player : TPlayerEx); external 'bot.dll'
procedure DLL_SYSTEM_UpdatePlayer(Player : TPlayerEx); external 'bot.dll'
procedure DLL_SYSTEM_RemovePlayer(DXID:WORD); external 'bot.dll'
procedure DLL_CMD(s:string); external 'bot.dll'
procedure DLL_SYSTEM_RemoveAllPlayers; external 'bot.dll'
procedure DLL_MainLoop; external 'bot.dll';
procedure DLL_DMGReceived(TargetDXID, AttackerDXID:Word; dmg : word); external 'bot.dll';
procedure DLL_ChatReceived(DXID:Word; Text : shortstring); external 'bot.dll';
procedure DLL_AddModel(s : shortstring); external 'bot.dll';
function DLL_QUERY_VERSION:shortstring; external 'bot.dll';
function BD_Avail: boolean;
begin
result := false;
if SYS_BOT = false then exit;
if ismultip=2 then exit;
if MATCH_DDEMOPLAY then exit;
if inmenu then exit;
result := true;
end;
// ----------------------------------------------------
// BOT.DLL STUFF
// ----------------------------------------------------
procedure BD_FirstBoot;
var i : word;
begin
if SYS_BOT_FIRSTBOOT then exit;
SYS_BOT_FIRSTBOOT := true;
AddMessage(DLL_QUERY_VERSION);
for i := 0 to NUM_MODELS-1 do
DLL_AddModel ( AllModels[i].classname+'+'+AllModels[i].skinname );
end;
procedure BD_AddMessage(S : shortstring);
begin
AddMessage(S);
end;
// ----------------------------------------------------
procedure BD_AddPlayer(Netname_, nfkmodel_: shortstring; team_: byte);
var a : TPlayer;
Msg: TMP_CreatePlayer;
MsgSize : word;
begin
if Getnumberofplayers >= OPT_SV_MAXPLAYERS then begin
addmessage('^3Cannot addbot, ^4sv_maxplayers ^3reached.');
exit;
end;
a := TPlayer.Create;
with a do begin
objname := 'player';
idd := 2; // BOT player.
control := 255; // no control
health := 125;
armor := 0;
x := 320;
y := 200;
netname := netname_;
netobject := false; // local player
nfkmodel := nfkmodel_;
dead := 0;
frame := 0;
netnosignal := 0;
DXID := AssignUniqueDXID($FFFF);
balloon := false;
netupdated:=true;
botrailcolor := random(7)+1;
ipaddress := inttostr(random(255))+'.'+inttostr(random(255))+'.'+inttostr(random(255))+'.'+inttostr(random(255));
if TeamGame then begin
team := team_; // reset to null team...
if team >= 2 then
if GetRedPlayers > GetBluePlayers then team := 0 else if GetRedPlayers < GetBluePlayers then team := 1 else team := random(2);
end;
addplayer(a);
resetplayer(a);
resetplayerstats(a);
// for demos
if MATCH_DRECORD then begin
DData.gametic := gametic;
DData.gametime := gametime;
DData.type0 := DDEMO_CREATEPLAYERV2;
DemoStream.Write(DData, Sizeof(DData));
DSpawnPlayerV2.x := round(a.x);
DSpawnPlayerV2.y := round(a.y);
DSpawnPlayerV2.dir := a.dir;
DSpawnPlayerV2.team := a.team;
DSpawnPlayerV2.dead := 0;
DSpawnPlayerV2.DXID := a.DXID;
DSpawnPlayerV2.modelname := a.nfkmodel;
DSpawnPlayerV2.netname := a.netname;
DSpawnPlayerV2.reserved := 0;
DemoStream.Write(DSpawnPlayerV2, Sizeof(DSpawnPlayerV2));
end;
// Multiplayer stuff.
if ismultip=1 then begin
MsgSize := SizeOf(TMP_CreatePlayer);
Msg.Data := MMP_CREATEPLAYER;
Msg.x := round(a.x);
Msg.y := round(a.y);
Msg.DXID := a.dxid;
Msg.ipaddress_ := a.IPAddress;
Msg.ClientId := 0;
Msg.netname := a.netname;
Msg.nfkmodel := a.nfkmodel;
Msg.Team := a.team;
mainform.BNETSendData2All (Msg, MsgSize, 1);
nfkLive.UpdateCurrentUsers(GetNumberOfPlayers); // conn: new point to update
end;
addmessage(a.netname+' ^7^njoin the game');
end;
AssignModel(a);
findrespawnpoint(a,false);
end;
// ----------------------------------------------------
procedure BD_UpdatePlayers;
var pl : TPlayerEx;
i: byte;
begin
if GetNumberOfBots > 0 then
for i := 0 to SYS_MAXPLAYERS-1 do if players[i] <> nil then
with pl do begin
DXID := players[i].DXID;
if players[i].dead > 0 then
dead := true else dead := false;
if players[i].idd = 2 then
bot := true else bot := false;
refire := players[i].refire;
weapchg := players[i].weapchg;
weapon := players[i].weapon;
threadweapon := players[i].threadweapon;
dir := players[i].dir;
gantl_state := players[i].gantl_state;
// conn: animated machinegun
machinegun_state := players[i].machinegun_state;
machinegun_speed := players[i].machinegun_speed;
air := players[i].air;
team := players[i].team;
health := players[i].health;
armor := players[i].armor;
frags := players[i].frags;
netname := players[i].netname;
nfkmodel := players[i].nfkmodel;
crouch := players[i].crouch;
balloon := players[i].balloon;
flagcarrier := players[i].flagcarrier;
Location := players[i].Location;
item_quad := players[i].item_quad;
item_regen := players[i].item_regen;
item_battle := players[i].item_battle;
item_flight := players[i].item_flight;
item_haste := players[i].item_haste;
item_invis := players[i].item_invis;
have_rl := players[i].have_rl;
have_gl := players[i].have_gl;
have_rg := players[i].have_rg;
have_bfg := players[i].have_bfg;
have_sg := players[i].have_sg;
have_sh := players[i].have_sh;
have_mg := players[i].have_mg;
have_pl := players[i].have_pl;
ammo_mg := players[i].ammo_mg;
ammo_sg := players[i].ammo_sg;
ammo_gl := players[i].ammo_gl;
ammo_rl := players[i].ammo_rl;
ammo_sh := players[i].ammo_sh;
ammo_rg := players[i].ammo_rg;
ammo_pl := players[i].ammo_pl;
ammo_bfg := players[i].ammo_bfg;
x := players[i].x;
y := players[i].y;
cx := players[i].cx;
cy := players[i].cy;
if players[i].idd <> 2 then begin // emulate player fangle
if (players[i].dir=0) or (players[i].dir=2) then
fangle := players[i].fangle*360/255 else
fangle := players[i].fangle*360/255+1;
end;
InertiaX := players[i].InertiaX;
InertiaY := players[i].InertiaY;
DLL_SYSTEM_UpdatePlayer(pl);
end;
end;
// ----------------------------------------------------
procedure BD_FixAngle(i : byte);
begin
if players[i]=nil then exit;
if players[i].idd <> 2 then exit;
if players[i].botangle < 0 then players[i].botangle := 360 + players[i].botangle;
if players[i].botangle > 360 then players[i].botangle := players[i].botangle - 360;
if (players[i].dir=1) or (players[i].dir=3) then begin
if (players[i].botangle > 180) then players[i].botangle:= 360 - players[i].botangle;
end else
if (players[i].botangle <= 180) then players[i].botangle:= 360 - players[i].botangle;
end;
// ----------------------------------------------------
procedure BD_SetAngle (DXID:Word; angle : word);
var i : byte;
ang : integer;
tmp : integer;
begin
for i := 0 to SYS_MAXPLAYERS-1 do if players[i] <> nil then if players[i].idd = 2 then
if players[i].dxid = dxid then begin
ang := round(angle);
if angle > 360 then angle := angle mod 360;
players[i].botangle := angle;
BD_FixAngle(i);
players[i].fangle := players[i].botangle * 255 / 360;
// grenade launcher optimization
if (players[i].dir = 1) or (players[i].dir = 3) then begin
if players[i].botangle >= 270 then players[i].botangle := 0;
if (players[i].botangle < 270) and (players[i].botangle > 180) then players[i].botangle := 180;
tmp := round(players[i].botangle * 200 / 180);
players[i].clippixel := tmp-100;
end else begin
// if (players[i].dir = 0) or (players[i].dir = 2) then begin
if players[i].botangle <= 90 then players[i].botangle := 360;
if (players[i].botangle > 90) and (players[i].botangle < 180) then players[i].botangle := 181;
tmp := round((players[i].botangle-180) * 200 / 180);
players[i].clippixel := -tmp+100;
end;
exit;
end;
end;
// ----------------------------------------------------
procedure BD_SetWeapon (DXID:Word; wpn : byte);
var i : byte;
begin
for i := 0 to SYS_MAXPLAYERS-1 do if players[i] <> nil then if players[i].idd = 2 then
if players[i].dxid = dxid then begin
if (wpn=1) and (players[i].have_mg = false) then exit;
if (wpn=2) and (players[i].have_sg = false) then exit;
if (wpn=3) and (players[i].have_gl = false) then exit;
if (wpn=4) and (players[i].have_rl = false) then exit;
if (wpn=5) and (players[i].have_sh = false) then exit;
if (wpn=6) and (players[i].have_rg = false) then exit;
if (wpn=7) and (players[i].have_pl = false) then exit;
if (wpn=8) and (players[i].have_bfg = false) then exit;
players[i].threadweapon := wpn;
exit;
end;
end;
// ----------------------------------------------------
procedure BD_SetKeys (DXID:Word; keys : byte);
var i : byte;
begin
for i := 0 to SYS_MAXPLAYERS-1 do if players[i] <> nil then if players[i].idd = 2 then
if players[i].dxid = dxid then begin
players[i].keys := keys;
exit;
end;
end;
// ----------------------------------------------------
procedure BD_SetBalloon(DXID:Word; balloon : byte);
var i : byte;
begin
for i := 0 to SYS_MAXPLAYERS-1 do if players[i] <> nil then if players[i].idd = 2 then
if players[i].dxid = dxid then begin
if balloon=0 then
players[i].balloon := false else
players[i].balloon := true;
exit;
end;
end;
// ----------------------------------------------------
function BD_Test_Blocked(x,y:word):boolean;
begin
if x > BRICK_X*32+32 then x := BRICK_X*32+32;
if y > BRICK_Y*16+16 then y := BRICK_Y*16+16;
result := AllBricks[ trunc(x) div 32, trunc(y) div 16].block;
end;
// ----------------------------------------------------
procedure BD_FontTextOut(x,y: word; text : shortstring);
begin
parsecolortext(text, x, y, 2);
end;
// ----------------------------------------------------
procedure BD_FontTextOutC(x,y: word; text : shortstring);
begin
parsecolortext(text, GX+x, GY+y, 2);
end;
// ----------------------------------------------------
function BD_GetBrickStructure(x,y:word):TBrick;
begin
result := AllBricks[x,y];
end;
// ----------------------------------------------------
function BD_GetSpecialObjectStructure(ID:byte):TMAPOBJV2;
begin
result := MapObjects[ID];
end;
// ----------------------------------------------------
function BD_GetObjectStructure(ID:word):TMonoSpriteBD;
begin
if ID>1000 then begin
ID := 1000;
addmessage('^1BOT.DLL ERROR: Wrong ID requested in BD_GetObjectStructure');
end;
result.dead := GameObjects[ID].dead;
result.speed := GameObjects[ID].speed;
result.fallt := GameObjects[ID].fallt;
result.weapon := GameObjects[ID].weapon;
result.doublejump := GameObjects[ID].doublejump;
result.refire := GameObjects[ID].refire;
result.imageindex := GameObjects[ID].imageindex;
result.dir := GameObjects[ID].dir;
result.idd := GameObjects[ID].idd;
result.clippixel := GameObjects[ID].clippixel;
if GameObjects[ID].spawner = nil then
result.spawnerDXID := 0 else result.spawnerDXID := GameObjects[ID].spawner.DXID;
result.frame := GameObjects[ID].frame;
result.health := GameObjects[ID].health;
result.x := GameObjects[ID].x;
result.y := GameObjects[ID].y;
result.cx := GameObjects[ID].cx;
result.cy := GameObjects[ID].cy;
result.fangle := GameObjects[ID].fangle;
result.fspeed := GameObjects[ID].fspeed;
result.objname := GameObjects[ID].objname;
result.DXID := GameObjects[ID].DXID;
result.mass := GameObjects[ID].mass;
result.InertiaX := GameObjects[ID].InertiaX;
result.InertiaY := GameObjects[ID].InertiaY;
end;
// ----------------------------------------------------
procedure BD_RemoveBot(par : word);
var d : byte;
msg : TMP_KickPlayer;
msgsize : word;
begin
for d := 0 to SYS_MAXPLAYERS-1 do if players[d] <> nil then if (players[d].dxid = par) and (players[d].idd=2) then begin
addmessage(players[d].netname +' ^7^nhas left the game.');
RespawnFlash(players[d].x-16, players[d].y);
if SYS_BOT then DLL_SYSTEM_RemovePlayer(players[d].DXID);
if SYS_BOT then
if (MATCH_GAMETYPE = GAMETYPE_CTF) and (players[d].flagcarrier = true) and (players[d].dead = 0) then begin
CTF_DropFlag(players[d]);
players[d].team := 2;
end;
if MATCH_DRECORD then begin
DData.type0 := DDEMO_DROPPLAYER;
DData.gametic := gametic;
DData.gametime := gametime;
DemoStream.Write( DData, Sizeof(DData));
DNETKickDropPlayer.DXID := players[D].DXID;
DemoStream.Write( DNETKickDropPlayer, Sizeof(DNETKickDropPlayer));
end;
if ismultip=1 then begin
MsgSize := SizeOf(TMP_KickPlayer);
Msg.DATA := MMP_IAMQUIT;
Msg.DXID := players[D].DXID;
mainform.BNETSendData2All (Msg, MsgSize, 1);
nfkLive.UpdateCurrentUsers(getNumberOfPLayers);
end;
players[d] := nil;
break;
end;
end;
// ----------------------------------------------------
procedure BD_RegisterConsoleCommand(S : shortstring);
var i : word;
begin
for i := 0 to contab.count-1 do
if contab[i]=strpar(lowercase(s),0) then exit;
contab.add(s);
contab.sort;
end;
// ----------------------------------------------------
procedure BD_SendChat(DXID:word; text : shortstring; teamchat: boolean);
var i : byte;
buf : array [0..$FF] of char;
buff : array [0..$FF] of char;
chatP : pointer;
msgsize:word;
begin
for i := 0 to SYS_MAXPLAYERS-1 do if players[i] <> nil then if players[i].idd = 2 then
if players[i].dxid = dxid then begin
// send a chat.
if not TeamGame then if teamchat = true then teamchat := false;
if (teamchat=false) then begin
addmessage(players[i].netname+'^7^n: ^4'+ text);
SND.play(SND_talk,0,0);
end else if (myTeamIS=players[i].team) or (players[i].team = C_TEAMNON) then begin
if players[i].location = '' then addmessage(players[i].netname+'^7^n: ^4'+text) else
addmessage(players[i].netname+'^7^n ('+players[i].location+'^7^n): ^4'+text);
SND.play(SND_talk,0,0);
end;
// record bot chat to demo
if MATCH_DRECORD then begin
DData.type0 := DDEMO_CHATMESSAGE;
DData.gametic := gametic;
DData.gametime := gametime;
DemoStream.Write( DData, Sizeof(DData));
DNETCHATMessage.DXID := players[i].DXID;
DNETCHATMessage.messagelenght := length(text);
DemoStream.Write( DNETCHATMessage, Sizeof(DNETCHATMessage));
StrLCopy(Buff, pchar(string(text)), length(text));
DemoStream.Write(buff, length(text));
end;
// send over multiplayer
if ismultip=1 then begin
chatP := @buf;
if teamchat then addbyte(chatP, MMP_CHATTEAMMESSAGE) else
addbyte(chatP, MMP_CHATMESSAGE);
addword(chatP, players[i].dxid);
AddString(chatP,text);
msgsize := length(text)+4;
mainform.BNETSendData2All (buf, MsgSize, 1);
end;
break;
end;
end;
// ----------------------------------------------------
procedure BD_Init;
begin
DLL_RegisterProc1(BD_SetAngle);
DLL_RegisterProc2(BD_AddMessage, 1);
DLL_RegisterProc2(BD_RegisterConsoleCommand, 2);
DLL_RegisterProc3(BD_GetSystemVariable, 1);
DLL_RegisterProc4(BD_AddPlayer, 1);
DLL_RegisterProc5(BD_SetKeys,1);
// DLL_RegisterProc5(BD_SetAngle,2);
DLL_RegisterProc5(BD_SetWeapon,3);
DLL_RegisterProc5(BD_SetBalloon,4);
DLL_RegisterProc6(BD_Test_Blocked, 1);
DLL_RegisterProc7(BD_FontTextOut,1);
DLL_RegisterProc7(BD_FontTextOutC,2);
DLL_RegisterProc8(BD_GetBrickStructure);
DLL_RegisterProc9(BD_GetObjectStructure);
DLL_RegisterProc10(BD_GetSpecialObjectStructure);
DLL_RegisterProc11(BD_RemoveBot);
DLL_RegisterProc12(BD_SendChat);
end;
// ------------------------------------
procedure BotThink (i : byte);
begin
if players[i].health <= 0 then exit;
if players[i].dead >= 1 then exit;
if random(6)=4 then Fire(players[i],0,0,0);
if players[0].x > players[i].x then players[i].dir := 1 else players[i].dir := 0;
end;