This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
console.cpp
1394 lines (1223 loc) · 35.6 KB
/
console.cpp
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/console.cpp $
// $Revision:: 68 $
// $Author:: Jimdose $
// $Date:: 12/18/98 11:03p $
//
// Copyright (C) 1997 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/console.cpp $
//
// 68 12/18/98 11:03p Jimdose
// removed include of qcommon.h
//
// 67 11/07/98 5:28p Aldie
// Only filter missioncon for coop
//
// 66 11/07/98 3:52p Aldie
// Fixed loop bug for console parsing
//
// 65 11/07/98 2:25p Aldie
// Fixed check for ---
//
// 64 11/07/98 2:21p Aldie
// Added coop filter for some console stuff
//
// 63 10/27/98 1:42p Markd
// Fixed de-slashify stuff
//
// 62 10/19/98 11:50p Aldie
// Added slashfix to menufiles.
//
//
// 60 10/17/98 8:16p Jimdose
// Got rid of code posting the event 1 second later when console wasn't found.
// Functions just return now.
// Made ConsoleExists print out warning during any developer setting, not just
// > 1
//
// 59 10/11/98 12:02a Aldie
// Console savegame fix
//
// 58 10/10/98 9:59p Jimdose
// working on console savegames
//
// 57 10/07/98 11:43p Jimdose
// Got savegames working
//
// 56 9/23/98 10:07p Aldie
// Don't remove consoles that aren't in the manager
//
// 55 9/14/98 6:42p Aldie
// Fixed a bug with the nouse spawnflag which was setting hideModel()
// incorrectly
//
// 54 9/10/98 8:39p Markd
// Removed level.hidestats, replaced it with a player event
//
// 53 8/19/98 2:24p Aldie
// Moved warning message to developer 2
//
// 52 8/17/98 6:19p Markd
// Changed SetCamera to a Player method
//
// 51 8/15/98 3:00p Markd
// Fixed camera/console issues with weapons
//
// 50 8/08/98 1:59p Aldie
// Fixed console commands so they can be recieved from the client
//
// 49 8/06/98 10:53p Aldie
// Added weapon tweaks and kickback. Also modified blast radius damage and
// rocket jumping.
//
// 48 7/31/98 8:09p Jimdose
// Script commands now include flags to indicate cheats and console commands
//
// 47 7/29/98 3:38p Aldie
// Don't use a camera if there isn't one.
//
// 46 7/26/98 4:14a Aldie
// Console camera fun stuff.
//
// 45 7/26/98 1:17a Aldie
// Camera system for consoles
//
// 44 7/23/98 2:38p Aldie
// Made mission computer not be in the PVS
//
// 43 7/21/98 7:32p Aldie
// Changed mission computer defaults
//
// 42 7/21/98 1:10p Aldie
// Added meansofdeath to obituaries
//
// 41 7/09/98 9:35p Jimdose
// Removed RF_CONSOLE renderfx flag
//
// 40 7/09/98 4:45p Markd
// hid non-use consoles
//
// 39 7/09/98 4:33p Markd
// added pvs support for consoles
//
// 38 7/03/98 12:00p Aldie
// Better error checking when setting a layout.
//
// 37 7/01/98 7:01p Aldie
// Added mission computer
//
// 36 5/25/98 2:28p Aldie
// Fixed issues with not loading game dll
//
// 35 5/24/98 8:46p Jimdose
// Made a lot of functions more str-friendly.
// Got rid of a lot of char * based strings
// Cleaned up get spawn arg functions and sound functions
// sound functions now use consistant syntax
//
// 34 5/24/98 4:48p Jimdose
// Made char *'s const
//
// 33 5/17/98 8:13p Aldie
// New menu cutover changes.
//
// 32 5/02/98 8:38p Aldie
// More console stuff for demos
//
// 31 4/30/98 4:46p Aldie
// Server side console states.
//
// 30 4/21/98 2:24p Aldie
// Added ability to kick users.
//
// 29 4/18/98 6:09p Aldie
// Added generic status bars.
//
// 28 4/08/98 4:55p Aldie
// Alpha characters on consoles.
//
// 27 4/07/98 3:49p Aldie
// Added more menu control.
//
// 26 4/05/98 9:28p Aldie
// Added foreground color to consoles.
//
// 25 4/05/98 5:19p Aldie
// Rearranged console rendering
//
// 24 4/04/98 6:02p Jimdose
// Made response from EV_Trigger_ActivateTargets to EV_Trigger_Effect
//
// 23 4/03/98 1:10p Aldie
// Made all commands wait until console is actually created.
//
// 22 3/31/98 7:50p Aldie
// Fixed menufile bug.
//
// 21 3/31/98 7:35p Aldie
// Fixed menufile and focus.
//
// 20 3/31/98 11:55a Aldie
// Fixed loadmenufile.
//
// 19 3/30/98 11:46p Aldie
// Update to use triggers.
//
// 18 3/30/98 11:06p Aldie
// Added menus.
//
// 17 3/28/98 3:28p Aldie
// Added layout files.
//
// 16 3/27/98 6:23p Aldie
// Added rows, cols, and clear.
//
// 15 3/27/98 12:05p Aldie
// Changed an event name.
//
// 14 3/26/98 7:15p Aldie
// Added deactivate but it won't be used.
//
// 13 3/26/98 6:22p Aldie
// Fixed sending of layout commands.
//
// 12 3/26/98 4:09p Aldie
// Virtual width and height support.
//
// 11 3/26/98 2:51p Aldie
// Added interface between consoles and scripts.
//
// 10 3/24/98 4:29p Aldie
// New event system changes.
//
// 9 3/24/98 12:28p Aldie
// Added some commands to test consoles.
//
// 8 3/23/98 1:08p Aldie
// Added console entity.
//
// 6 12/12/97 4:22p Jimdose
// Added "message" key to console.
//
// 5 12/06/97 4:51p Markd
// Added GetArgs as commands for future processing
//
// 4 10/27/97 3:34p Jimdose
// Included stdarg.h
//
// 3 10/27/97 3:29p Jimdose
// Removed dependency on quakedef.h
//
// 2 9/26/97 5:23p Jimdose
// Added standard Ritual headers
//
// DESCRIPTION:
// Consoles are script controlled decals that can change dynamically. Eventually,
// their behaviour will be expanded to include interaction with the player as well.
//
#include "console.h"
#include "scriptmaster.h"
#include "camera.h"
#include "Player.h"
ConsoleManager consoleManager;
Event EV_Console_Activate( "conactivate" );
CLASS_DECLARATION( TriggerUse, Console, "console" );
ResponseDef Console::Responses[] =
{
{ &EV_Console_Activate, ( Response )Console::Activate },
{ &EV_Trigger_Effect, ( Response )Console::Activate },
{ &EV_Use, ( Response )Console::Use },
{ NULL, NULL }
};
/*****************************************************************************/
/*SINED console (0 .5 .8) ? NOUSE SCROLL MENU NOPVS
consolename (required)
virtualwidth
virtualheight
fraction
rows
cols
menufile
scroll
menu
/*****************************************************************************/
Console::Console()
{
netconsole_t *con;
str mfile;
if ( LoadingSavegame )
{
// Increment the global number of consoles and return
globals.num_consoles++;
return;
}
showModel();
setMoveType( MOVETYPE_PUSH );
setSolidType( SOLID_BSP );
console_name = G_GetSpawnArg( "consolename", "" );
if ( !LoadingSavegame && !console_name.length() )
{
error("Console", "consolename is undefined\n" );
}
if ( console_name == MAIN_CONSOLE )
{
error("Console", "console name \"maincon\" is reserved\n");
}
if ( console_name == MISSION_CONSOLE )
{
error("Console", "console name \"missioncon\" is reserved\n");
}
wait = G_GetFloatArg("wait",1.0f);
virtual_width = G_GetFloatArg("virtualwidth",640.0f);
virtual_height = G_GetFloatArg("virtualheight",480.0f);
fraction = G_GetFloatArg("fraction",1.0f);
rows = G_GetIntArg("rows",32);
cols = G_GetIntArg("cols",80);
mfile = G_GetSpawnArg("menufile", "");
scroll = G_GetIntArg("scroll",0);
menu = G_GetIntArg("menu",0);
respondto = TRIGGER_PLAYERS;
menufile = G_FixSlashes( mfile.c_str() );
if (scroll)
spawnflags |= 2;
if (menu)
spawnflags |= 4;
// A console of this name already exists, so just assign it's number to the number of the
// one that already exists
if ( !LoadingSavegame )
{
console_number = consoleManager.ConsoleExists( console_name );
if ( console_number )
{
return;
}
}
// Check for a free console on the server
if (globals.num_consoles >= globals.max_consoles)
error("Console::Create", "No free consoles\n" );
// Increment the global number of consoles.
globals.num_consoles++;
console_number = globals.num_consoles;
con = &g_consoles[globals.num_consoles];
con->inuse = true;
con->s.spawnflags = spawnflags;
con->s.consoleactive = true;
con->s.create_time = -1;
con->s.number = globals.num_consoles;
con->s.virtual_width = virtual_width;
con->s.virtual_height = virtual_height;
con->s.fraction = fraction;
con->s.rows = rows;
con->s.cols = cols;
con->s.menu_file[0] = 0;
con->s.linepos = 1;
con->s.console_owner = entnum;
created = true;
if ( menufile.length() )
{
strcpy( con->s.menu_file, menufile.c_str() );
con->s.menufile_update_time = -1;
}
else
{
con->s.menufile_update_time = 0;
}
strcpy( con->s.console_name, console_name.c_str() );
con->s.name_update_time = -1;
con->s.console_return_time = 0;
if ( !LoadingSavegame )
{
// Add it to the manager
consoleManager.AddConsole(this);
}
}
Console::~Console()
{
consoleManager.RemoveConsole(this);
}
void Console::Use( Event *ev )
{
// Don't respond to users using me!
if (spawnflags & 1)
return;
TriggerStuff(ev);
}
void Console::Activate( Event *ev )
{
char string[1024];
Entity *other;
Event *ev2;
Camera *cam;
int num;
if (!created)
{
Event *ev1;
ev1 = new Event(ev);
PostEvent(ev1,0.1);
return;
}
assert(created);
other = ev->GetEntity(1);
num = G_FindTarget( 0, Target() );
if ( num && other->isClient() )
{
Player * client;
client = ( Player * )other;
cam = (Camera *) G_GetEntity( num );
assert( cam );
client->SetCamera( cam );
ev2 = new Event( EV_Player_HideStats );
client->ProcessEvent( ev2 );
}
Com_sprintf( string, sizeof( string ), "use %s", console_name.c_str() );
gi.WriteByte (svc_console_command);
gi.WriteString (string);
gi.unicast (other->edict, true);
ev2 = new Event(EV_EnterConsole);
ev2->AddString(console_name);
other->PostEvent(ev2,0);
}
CLASS_DECLARATION( Listener, ConsoleManager, "consolemgr" );
Event EV_ConsoleManager_ProcessCommand( "consolecmd", EV_CONSOLE );
Event EV_ConsoleManager_ProcessVariable( "consolevar", EV_CONSOLE );
Event EV_ConsoleManager_ConPositionPositive( "consolepos", EV_CONSOLE );
Event EV_ConsoleManager_ConPositionNegative( "consoleneg", EV_CONSOLE );
Event EV_ConsoleManager_ConPositionReturn( "consoleret", EV_CONSOLE );
Event EV_ConsoleManager_ConMenuInfo( "consolemenu", EV_CONSOLE );
Event EV_ConsoleManager_ConPrint( "conprint" );
Event EV_ConsoleManager_ConNewline( "connewline" );
Event EV_ConsoleManager_ConLayout( "conlayout" );
Event EV_ConsoleManager_ConAppLayout( "conapplayout" );
Event EV_ConsoleManager_ConClearLayout( "conclearlayout" );
Event EV_ConsoleManager_ConVirtualWidth( "convirtualwidth" );
Event EV_ConsoleManager_ConVirtualHeight( "convirtualheight" );
Event EV_ConsoleManager_ConFraction( "confraction" );
Event EV_ConsoleManager_ConDeactivate( "condeactivate" );
Event EV_ConsoleManager_ConActivate( "conactivate" );
Event EV_ConsoleManager_ConRows( "rows" );
Event EV_ConsoleManager_ConColumns( "cols" );
Event EV_ConsoleManager_ConClear( "conclear" );
Event EV_ConsoleManager_ConLayoutFile( "conlayoutfile" );
Event EV_ConsoleManager_ConLoadMenuFile( "conmenufile" );
Event EV_ConsoleManager_ConFocus( "focus" );
Event EV_ConsoleManager_ConForeground( "foreground" );
Event EV_ConsoleManager_MenuActive( "menuactive" );
Event EV_ConsoleManager_MenuInactive( "menuinactive" );
Event EV_ConsoleManager_ConStatusBar( "sbar" );
Event EV_ConsoleManager_ConStatusBarValue( "sbarvalue" );
Event EV_ConsoleManager_ConKickUsers( "kick" );
Event EV_KickFromConsole( "kickcon" );
Event EV_EnterConsole( "entercon" );
Event EV_ExitConsole( "exitcon", EV_CONSOLE );
ResponseDef ConsoleManager::Responses[] =
{
{ &EV_ConsoleManager_ProcessCommand, ( Response )ConsoleManager::ProcessCmd },
{ &EV_ConsoleManager_ProcessVariable, ( Response )ConsoleManager::ProcessVar },
{ &EV_ConsoleManager_ConPositionPositive, ( Response )ConsoleManager::ConsolePositionPositive },
{ &EV_ConsoleManager_ConPositionNegative, ( Response )ConsoleManager::ConsolePositionNegative },
{ &EV_ConsoleManager_ConPositionReturn, ( Response )ConsoleManager::ConsolePositionReturn },
{ &EV_ConsoleManager_ConMenuInfo, ( Response )ConsoleManager::ConsoleMenuInfo },
{ &EV_ConsoleManager_ConPrint, ( Response )ConsoleManager::ConsolePrint },
{ &EV_ConsoleManager_ConPrint, ( Response )ConsoleManager::ConsolePrint },
{ &EV_ConsoleManager_ConNewline, ( Response )ConsoleManager::ConsoleNewline },
{ &EV_ConsoleManager_ConLayout, ( Response )ConsoleManager::ConsoleLayout },
{ &EV_ConsoleManager_ConLayoutFile, ( Response )ConsoleManager::ConsoleLayoutFile },
{ &EV_ConsoleManager_ConAppLayout, ( Response )ConsoleManager::ConsoleAppLayout },
{ &EV_ConsoleManager_ConClearLayout, ( Response )ConsoleManager::ConsoleClearLayout },
{ &EV_ConsoleManager_ConVirtualWidth, ( Response )ConsoleManager::ConsoleVirtualWidth },
{ &EV_ConsoleManager_ConVirtualHeight, ( Response )ConsoleManager::ConsoleVirtualHeight },
{ &EV_ConsoleManager_ConFraction, ( Response )ConsoleManager::ConsoleFraction },
{ &EV_ConsoleManager_ConDeactivate, ( Response )ConsoleManager::ConsoleDeactivate },
{ &EV_ConsoleManager_ConActivate, ( Response )ConsoleManager::ConsoleActivate },
{ &EV_ConsoleManager_ConRows, ( Response )ConsoleManager::ConsoleRows },
{ &EV_ConsoleManager_ConColumns, ( Response )ConsoleManager::ConsoleColumns },
{ &EV_ConsoleManager_ConClear, ( Response )ConsoleManager::ConsoleClear },
{ &EV_ConsoleManager_ConLoadMenuFile, ( Response )ConsoleManager::ConsoleLoadMenuFile },
{ &EV_ConsoleManager_ConFocus, ( Response )ConsoleManager::ConsoleFocus },
{ &EV_ConsoleManager_ConForeground, ( Response )ConsoleManager::ConsoleForeground },
{ &EV_ConsoleManager_MenuActive, ( Response )ConsoleManager::ConsoleMenuActive },
{ &EV_ConsoleManager_MenuInactive, ( Response )ConsoleManager::ConsoleMenuInactive },
{ &EV_ConsoleManager_ConStatusBar, ( Response )ConsoleManager::ConsoleStatusBar },
{ &EV_ConsoleManager_ConStatusBarValue, ( Response )ConsoleManager::ConsoleStatusBarValue },
{ &EV_ConsoleManager_ConKickUsers, ( Response )ConsoleManager::ConsoleKickUsers },
{ NULL, NULL }
};
//=============
//ConsoleExists - returns the number of the console, 0 if not found.
//=============
int ConsoleManager::ConsoleExists
(
str con_name
)
{
int num,i;
Console *p;
// Check for mission computer
if ( con_name == "missioncon" )
return mission_console_number;
num = consoleList.NumObjects();
for( i = 1; i <= num; i++ )
{
p = ( Console * )consoleList.ObjectAt( i );
if ( con_name == p->ConsoleName() )
{
return p->ConsoleNumber();
}
}
gi.dprintf( "Console %s does not exist\n", con_name.c_str() );
return 0;
}
//=============
//ConsoleExists
//=============
qboolean ConsoleManager::ConsoleExists
(
int con_number
)
{
int num,i;
Console *p;
// Check for mission computer
if ( con_number == mission_console_number )
return true;
num = consoleList.NumObjects();
for( i = 1; i <= num; i++ )
{
p = ( Console * )consoleList.ObjectAt( i );
if (p->ConsoleNumber() == con_number)
return true;
}
return false;
}
//==========
//ProcessCmd - Send this command to the script director.
//==========
void ConsoleManager::ProcessCmd
(
Event *ev
)
{
Director.ConsoleInput(ev->GetToken(1),ev->GetToken(2));
}
//==========
//ProcessVar - Send this variable to the script director.
//==========
void ConsoleManager::ProcessVar
(
Event *ev
)
{
Director.ConsoleVariable(ev->GetToken(1),ev->GetToken(2));
}
//=====================
//ConsolePositionReturn
//=====================
void ConsoleManager::ConsolePositionReturn
(
Event *ev
)
{
netconsole_t *svcon;
int num = ev->GetInteger(1);
if (!ConsoleExists(num))
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
svcon->s.linepos = 1;
svcon->s.cmdline[svcon->s.linepos] = 0;
svcon->s.console_return_time = level.time;
}
//=======================
//ConsolePositionPositive
//=======================
void ConsoleManager::ConsolePositionPositive
(
Event *ev
)
{
netconsole_t *svcon;
int num = ev->GetInteger(1);
if (!ConsoleExists(num))
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
if (svcon->s.linepos < MAXCMDLINE-1)
{
svcon->s.cmdline[svcon->s.linepos] = ev->GetInteger(2);
svcon->s.linepos++;
svcon->s.cmdline[svcon->s.linepos] = 0;
}
}
//=======================
//ConsolePositionNegative
//=======================
void ConsoleManager::ConsolePositionNegative
(
Event *ev
)
{
netconsole_t *svcon;
int num = ev->GetInteger(1);
if (!ConsoleExists(num))
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
if (svcon->s.linepos > 1)
{
svcon->s.linepos--;
svcon->s.cmdline[svcon->s.linepos] = 0;
}
}
//===============
//ConsoleMenuInfo
//===============
void ConsoleManager::ConsoleMenuInfo
(
Event *ev
)
{
netconsole_t *svcon;
int num = ev->GetInteger(1);
if (!ConsoleExists(num))
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
svcon->s.menu_level = ev->GetInteger(2);
svcon->s.sel_menu_item = ev->GetInteger(3);
}
void ConsoleManager::CreateMissionComputer
(
void
)
{
netconsole_t *con;
// Check for a free console on the server
if (globals.num_consoles >= globals.max_consoles)
gi.error("Console::CreateMissionComputer", "No free consoles\n" );
// Increment the global number of consoles.
globals.num_consoles++;
mission_console_number = globals.num_consoles;
con = &g_consoles[globals.num_consoles];
con->inuse = true;
con->s.spawnflags = 2|8;
con->s.consoleactive = true;
con->s.create_time = -1;
con->s.number = globals.num_consoles;
con->s.virtual_width = 320;
con->s.virtual_height = 240;
con->s.fraction = 1.0f;
con->s.rows = 30;
con->s.cols = 40;
con->s.menu_file[0] = 0;
con->s.linepos = 1;
con->s.menufile_update_time = 0;
strcpy( con->s.console_name, MISSION_CONSOLE );
con->s.name_update_time = -1;
con->s.console_return_time = 0;
}
void ConsoleManager::Reset
(
void
)
{
globals.num_consoles = 0;
mission_console_number = 0;
consoleList.ClearObjectList();
}
//==========
//AddConsole - Add a console to the manager
//==========
int ConsoleManager::AddConsole
(
Console *console
)
{
int num;
num = consoleList.AddObject( console );
return num;
}
//=============
//RemoveConsole - Remove a console from the manager
//=============
void ConsoleManager::RemoveConsole
(
Console *console
)
{
// Make sure that this exists in the manager
if ( consoleList.IndexOfObject( console ) )
consoleList.RemoveObject( console );
}
//============
//ConsolePrint - Print a string to the buffer of the console
//============
void ConsoleManager::ConsolePrint
(
Event *ev
)
{
char *bufptr;
const char *str;
netconbuffer_t *svbuff;
netconsole_t *svcon;
int *start;
int *end;
int num;
num = ConsoleExists( ev->GetString( 1 ) );
if ( !num )
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
svbuff = &g_conbuffers[num];
bufptr = &svbuff->s.buffer[0];
start = &svbuff->s.start;
end = &svbuff->s.end;
str = ev->GetString(2);
svbuff->s.end_index += strlen(str);
while (*str)
{
if ( (*end+1)%MAX_BUFFER_LENGTH == (*start) )
{
svbuff->s.start_index += 1;
*start = (*start + 1)%MAX_BUFFER_LENGTH;
}
bufptr[*end]=*str;
*end = (*end+1) % MAX_BUFFER_LENGTH;
str++;
}
}
//==============
//ConsoleNewline - Prints a newline to the buffer of the console
//==============
void ConsoleManager::ConsoleNewline
(
Event *ev
)
{
ev->AddString("\n");
ConsolePrint(ev);
}
//=================
//ConsoleLayoutFile - Orders the console to load a client side layout file
//=================
void ConsoleManager::ConsoleLayoutFile
(
Event *ev
)
{
netconsole_t *svcon;
int num;
const char *layout_filename;
num = ConsoleExists(ev->GetString( 1 ));
if (!num)
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
layout_filename = ev->GetString(2);
strcpy(svcon->s.layout_file, layout_filename);
svcon->s.layoutfile_update_time = level.time;
}
//=============
//ConsoleLayout - Set the layout string
//=============
void ConsoleManager::ConsoleLayout
(
Event *ev
)
{
str console_name;
netconsole_t *svcon;
int num;
char *layout;
char *token;
char newlayout[ MAX_LAYOUT_LENGTH ];
static const char *seps = " ";
console_name = ev->GetString( 1 );
num = ConsoleExists( console_name );
if ( !num )
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[ num ];
layout = strdup( ev->GetString( 2 ) );
if ( strlen( layout ) > MAX_LAYOUT_LENGTH )
error( "ConsoleManager::ConsoleLayout", "Max layout length exceeded for %s\n", ev->GetString( 1 ) );
strcpy( newlayout, layout );
if ( coop->value && ( console_name == "missioncon" ) )
{
newlayout[ 0 ] = 0;
token = strtok( layout, seps );
while ( token )
{
// Skip over "fc" console commands in coop
if ( !strcmp( token, "fc" ) )
{
strtok( NULL, seps );
strtok( NULL, seps );
strtok( NULL, seps );
strtok( NULL, seps );
}
else if ( strstr( token, "---" ) )
{
strcat( newlayout, " " );
strcat( newlayout, "\"\"" );
// Skip over extraneous lines of characters
}
else
{
strcat( newlayout, " " );
strcat( newlayout, token );
}
token = strtok( NULL, seps );
}
}
free( layout );
strcpy( svcon->s.layout, newlayout );
svcon->s.layout_update_time = level.time;
}
//================
//ConsoleAppLayout - Append to the layout string
//================
void ConsoleManager::ConsoleAppLayout
(
Event *ev
)
{
netconsole_t *svcon;
int layout_length, num;
char *layout;
const char *token;
char newlayout[ MAX_LAYOUT_LENGTH ];
static const char *seps = " ";
str consolename;
consolename = ev->GetString( 1 );
num = ConsoleExists( consolename );
if (!num)
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
layout = strdup( ev->GetString( 2 ) );
layout_length = strlen(layout) + strlen(svcon->s.layout) + 1;
if ( layout_length > MAX_LAYOUT_LENGTH )
error("ConsoleManager::ConsoleAppLayout", "Max layout length exceeded for %s\n", ev->GetString(1) );
strcpy( newlayout, layout );
if ( coop->value && ( consolename == "missioncon" ) )
{
newlayout[ 0 ] = 0;
token = strtok( layout, seps );
while ( token )
{
// Skip over "fc" console commands in coop
if ( !strcmp( token, "fc" ) )
{
strtok ( NULL, seps );
strtok ( NULL, seps );
strtok ( NULL, seps );
strtok ( NULL, seps );
}
else if ( strstr( token, "---" ) )
{
strcat( newlayout, "\"\"" );
// Skip over extraneous lines of characters
}
else
{
strcat( newlayout, " " );
strcat( newlayout, token );
}
token = strtok( NULL, seps );
}
}
free( layout );
strcat(svcon->s.layout, " ");
strcat(svcon->s.layout, newlayout);
svcon->s.layout_update_time = level.time;
}
//==================
//ConsoleClearLayout - Clear the layout string
//==================
void ConsoleManager::ConsoleClearLayout
(
Event *ev
)
{
netconsole_t *svcon;
int num;
num = ConsoleExists(ev->GetString( 1 ));
if (!num)
{
// ConsoleExists will give a warning about this console not existing
return;
}
svcon = &g_consoles[num];
svcon->s.layout[0] = 0;
svcon->s.layout_update_time = level.time;
}
//===========
//ConsoleRows - Set the number of rows in the console
//===========
void ConsoleManager::ConsoleRows
(
Event *ev
)
{
netconsole_t *svcon;
int num;
num = ConsoleExists(ev->GetString( 1 ));