-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathkeycontrol.cpp
More file actions
2927 lines (2476 loc) · 75.8 KB
/
Copy pathkeycontrol.cpp
File metadata and controls
2927 lines (2476 loc) · 75.8 KB
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
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "globalincs/pstypes.h"
#include "globalincs/globals.h"
#include "globalincs/linklist.h"
#include "io/key.h"
#include "io/joy.h"
#include "io/timer.h"
#include "ship/ship.h"
#include "playerman/player.h"
#include "weapon/weapon.h"
#include "hud/hud.h"
#include "gamesequence/gamesequence.h"
#include "mission/missiongoals.h"
#include "hud/hudets.h"
#include "gamesnd/gamesnd.h"
#include "hud/hudsquadmsg.h"
#include "gamesnd/eventmusic.h"
#include "freespace.h"
#include "mission/missionhotkey.h"
#include "hud/hudescort.h"
#include "hud/hudshield.h"
#include "io/keycontrol.h"
#include "ship/shiphit.h"
#include "ship/shipfx.h"
#include "mission/missionlog.h"
#include "hud/hudtargetbox.h"
#include "popup/popup.h"
#include "object/objcollide.h"
#include "object/object.h"
#include "hud/hudconfig.h"
#include "hud/hudmessage.h"
#include "network/multi_pmsg.h"
#include "starfield/supernova.h"
#include "mission/missionmessage.h"
#include "menuui/mainhallmenu.h"
#include "missionui/missionpause.h"
#include "hud/hudgauges.h"
#include "freespace.h" //For time compression stuff
#include "species_defs/species_defs.h"
#include "asteroid/asteroid.h"
#include "iff_defs/iff_defs.h"
#include "network/multi.h"
#include "network/multiutil.h"
#include "network/multimsgs.h"
#include "network/multi_pause.h"
#include "network/multi_observer.h"
#include "network/multi_endgame.h"
#include "autopilot/autopilot.h"
#include "cmdline/cmdline.h"
#include "object/objectshield.h"
/**
* Natural number factor lookup class.
*/
class factor_table
{
public:
/**
* Constructor.
*
* @param size The desired initial size of the lookup table.
*/
factor_table(size_t size = 6);
/**
* Destructor.
*/
~factor_table();
/**
* Returns the next natural number factor for the given number and current factor.
*
* @param maximum The number to lookup the next natural number factor for.
* @param current The current natural number factor.
* @return A natural number factor.
*/
size_t getNext(size_t n, size_t current);
private:
SCP_vector< SCP_vector<size_t> > _lookup;
/**
* Grow the internal lookup table based on the desired size.
*
* @param size The desired size.
*/
void resize(size_t size);
/**
* Returns true if the given factor is a natural number factor for the given value.
*
* @param factor The factor.
* @param n The value.
*/
static bool isNaturalNumberFactor(size_t factor, size_t n);
};
factor_table::factor_table(size_t size)
{
resize(size);
}
factor_table::~factor_table() {}
size_t factor_table::getNext(size_t n, size_t current)
{
Assertion(n >= 1, "factor_table::getNext() called with " SIZE_T_ARG ", when only natural numbers make sense; get a coder!\n", n);
// Resize lookup table if the value is greater than the current size
if (n > _lookup.size())
resize(n);
size_t index = n - 1;
for (size_t i = 0; i < _lookup[index].size(); ++i)
{
if (_lookup[index][i] == current)
{
if (_lookup[index].size() == i + 1)
{
// Overflow back to 1
return 1;
}
else
{
// Next factor in the table
return _lookup[index][i + 1];
}
}
}
Assertion(false, "For some reason, factor_table::getNext() was unable to locate the current factor. This should never happen; get a coder!\n");
return 1;
}
void factor_table::resize(size_t size)
{
size_t oldSize = _lookup.size();
_lookup.resize(size);
// Fill lookup table for the missing values
for (size_t i = oldSize; i < size; ++i)
{
for (size_t j = 1; j <= i + 1; ++j)
{
if (isNaturalNumberFactor(j, i + 1))
{
_lookup[i].push_back(j);
}
}
}
}
bool factor_table::isNaturalNumberFactor(size_t factor, size_t n)
{
return ((float)n / (float)factor) == n / factor;
}
// Natural number factor lookup table
factor_table ftables;
// --------------------------------------------------------------
// Global to file
// --------------------------------------------------------------
// time compression/dilation values - Goober5000
// (Volition sez "can't compress below 0.25"... not sure if
// this is arbitrary or dictated by code)
#define MAX_TIME_MULTIPLIER 64
#define MAX_TIME_DIVIDER 4
#define CHEAT_BUFFER_LEN 17
char CheatBuffer[CHEAT_BUFFER_LEN+1];
enum cheatCode {
CHEAT_CODE_NONE = 0,
CHEAT_CODE_FREESPACE,
CHEAT_CODE_FISH,
CHEAT_CODE_HEADZ,
CHEAT_CODE_TOOLED,
CHEAT_CODE_PIRATE,
CHEAT_CODE_SKIP
};
struct Cheat {
cheatCode code;
char* data;
};
static struct Cheat cheatsTable[] = {
{ CHEAT_CODE_FREESPACE, "www.freespace2.com" },
{ CHEAT_CODE_FISH, "vasudanswuvfishes" },
{ CHEAT_CODE_HEADZ, "humanheadsinside." },
{ CHEAT_CODE_TOOLED, "tooledworkedowned" },
{ CHEAT_CODE_PIRATE, "arrrrwalktheplank" },
{ CHEAT_CODE_SKIP, "skipmemymissionyo" }
};
#define CHEATS_TABLE_LEN 6
int Tool_enabled = 0;
bool Perspective_locked=false;
bool quit_mission_popup_shown = false;
extern int AI_watch_object;
extern int Countermeasures_enabled;
extern float do_subobj_hit_stuff(object *ship_obj, object *other_obj, vec3d *hitpos, int submodel_num, float damage, bool *hull_should_apply_armor);
extern void mission_goal_mark_all_true( int type );
int Normal_key_set[] = {
TARGET_NEXT,
TARGET_PREV,
TARGET_NEXT_CLOSEST_HOSTILE,
TARGET_PREV_CLOSEST_HOSTILE,
TARGET_NEXT_CLOSEST_FRIENDLY,
TARGET_PREV_CLOSEST_FRIENDLY,
TARGET_TARGETS_TARGET,
TARGET_SHIP_IN_RETICLE,
TARGET_LAST_TRANMISSION_SENDER,
TARGET_CLOSEST_SHIP_ATTACKING_TARGET,
TARGET_CLOSEST_SHIP_ATTACKING_SELF,
STOP_TARGETING_SHIP,
TOGGLE_AUTO_TARGETING,
TARGET_SUBOBJECT_IN_RETICLE,
TARGET_PREV_SUBOBJECT,
TARGET_NEXT_SUBOBJECT,
STOP_TARGETING_SUBSYSTEM,
TARGET_NEXT_UNINSPECTED_CARGO,
TARGET_PREV_UNINSPECTED_CARGO,
TARGET_NEWEST_SHIP,
TARGET_NEXT_LIVE_TURRET,
TARGET_PREV_LIVE_TURRET,
TARGET_NEXT_BOMB,
TARGET_PREV_BOMB,
ATTACK_MESSAGE,
DISARM_MESSAGE,
DISABLE_MESSAGE,
ATTACK_SUBSYSTEM_MESSAGE,
CAPTURE_MESSAGE,
ENGAGE_MESSAGE,
FORM_MESSAGE,
PROTECT_MESSAGE,
COVER_MESSAGE,
WARP_MESSAGE,
REARM_MESSAGE,
IGNORE_MESSAGE,
SQUADMSG_MENU,
VIEW_CHASE,
VIEW_OTHER_SHIP,
VIEW_TOPDOWN,
VIEW_TRACK_TARGET,
SHOW_GOALS,
END_MISSION,
ADD_REMOVE_ESCORT,
ESCORT_CLEAR,
TARGET_NEXT_ESCORT_SHIP,
XFER_SHIELD,
XFER_LASER,
INCREASE_SHIELD,
INCREASE_WEAPON,
INCREASE_ENGINE,
DECREASE_SHIELD,
DECREASE_WEAPON,
DECREASE_ENGINE,
ETS_EQUALIZE,
SHIELD_EQUALIZE,
SHIELD_XFER_TOP,
SHIELD_XFER_BOTTOM,
SHIELD_XFER_RIGHT,
SHIELD_XFER_LEFT,
CYCLE_NEXT_PRIMARY,
CYCLE_PREV_PRIMARY,
CYCLE_SECONDARY,
CYCLE_NUM_MISSLES,
RADAR_RANGE_CYCLE,
MATCH_TARGET_SPEED,
TOGGLE_AUTO_MATCH_TARGET_SPEED,
VIEW_EXTERNAL,
VIEW_EXTERNAL_TOGGLE_CAMERA_LOCK,
LAUNCH_COUNTERMEASURE,
ONE_THIRD_THROTTLE,
TWO_THIRDS_THROTTLE,
PLUS_5_PERCENT_THROTTLE,
MINUS_5_PERCENT_THROTTLE,
ZERO_THROTTLE,
MAX_THROTTLE,
TARGET_CLOSEST_REPAIR_SHIP,
MULTI_MESSAGE_ALL,
MULTI_MESSAGE_FRIENDLY,
MULTI_MESSAGE_HOSTILE,
MULTI_MESSAGE_TARGET,
MULTI_OBSERVER_ZOOM_TO,
TIME_SPEED_UP,
TIME_SLOW_DOWN,
TOGGLE_HUD_CONTRAST,
MULTI_TOGGLE_NETINFO,
MULTI_SELF_DESTRUCT,
TOGGLE_HUD,
HUD_TARGETBOX_TOGGLE_WIREFRAME,
AUTO_PILOT_TOGGLE,
NAV_CYCLE,
TOGGLE_GLIDING,
CYCLE_PRIMARY_WEAPON_SEQUENCE,
TOGGLE_AUTO_SHIELD_EQUALIZE,
};
int Dead_key_set[] = {
TARGET_NEXT,
TARGET_PREV,
TARGET_NEXT_CLOSEST_HOSTILE,
TARGET_PREV_CLOSEST_HOSTILE,
TARGET_NEXT_CLOSEST_FRIENDLY,
TARGET_PREV_CLOSEST_FRIENDLY,
TARGET_TARGETS_TARGET,
TARGET_CLOSEST_SHIP_ATTACKING_TARGET,
STOP_TARGETING_SHIP,
TOGGLE_AUTO_TARGETING,
TARGET_SUBOBJECT_IN_RETICLE,
TARGET_PREV_SUBOBJECT,
TARGET_NEXT_SUBOBJECT,
STOP_TARGETING_SUBSYSTEM,
TARGET_NEWEST_SHIP,
TARGET_NEXT_LIVE_TURRET,
TARGET_PREV_LIVE_TURRET,
TARGET_NEXT_BOMB,
TARGET_PREV_BOMB,
VIEW_CHASE,
VIEW_OTHER_SHIP,
VIEW_TOPDOWN,
SHOW_GOALS,
ADD_REMOVE_ESCORT,
ESCORT_CLEAR,
TARGET_NEXT_ESCORT_SHIP,
TARGET_CLOSEST_REPAIR_SHIP,
MULTI_MESSAGE_ALL,
MULTI_MESSAGE_FRIENDLY,
MULTI_MESSAGE_HOSTILE,
MULTI_MESSAGE_TARGET,
MULTI_OBSERVER_ZOOM_TO,
TIME_SPEED_UP,
TIME_SLOW_DOWN
};
int Critical_key_set[] = {
CYCLE_NEXT_PRIMARY,
CYCLE_PREV_PRIMARY,
CYCLE_SECONDARY,
CYCLE_NUM_MISSLES,
INCREASE_WEAPON,
DECREASE_WEAPON,
INCREASE_SHIELD,
DECREASE_SHIELD,
INCREASE_ENGINE,
DECREASE_ENGINE,
ETS_EQUALIZE,
SHIELD_EQUALIZE,
SHIELD_XFER_TOP,
SHIELD_XFER_BOTTOM,
SHIELD_XFER_LEFT,
SHIELD_XFER_RIGHT,
XFER_SHIELD,
XFER_LASER,
TOGGLE_AUTO_SHIELD_EQUALIZE,
};
int Non_critical_key_set[] = {
MATCH_TARGET_SPEED,
TOGGLE_AUTO_MATCH_TARGET_SPEED,
TARGET_NEXT,
TARGET_PREV,
TARGET_NEXT_CLOSEST_HOSTILE,
TARGET_PREV_CLOSEST_HOSTILE,
TOGGLE_AUTO_TARGETING,
TARGET_NEXT_CLOSEST_FRIENDLY,
TARGET_PREV_CLOSEST_FRIENDLY,
TARGET_SHIP_IN_RETICLE,
TARGET_LAST_TRANMISSION_SENDER,
TARGET_CLOSEST_REPAIR_SHIP,
TARGET_CLOSEST_SHIP_ATTACKING_TARGET,
STOP_TARGETING_SHIP,
TARGET_CLOSEST_SHIP_ATTACKING_SELF,
TARGET_TARGETS_TARGET,
TARGET_SUBOBJECT_IN_RETICLE,
TARGET_PREV_SUBOBJECT,
TARGET_NEXT_SUBOBJECT,
STOP_TARGETING_SUBSYSTEM,
TARGET_NEXT_BOMB,
TARGET_PREV_BOMB,
TARGET_NEXT_UNINSPECTED_CARGO,
TARGET_PREV_UNINSPECTED_CARGO,
TARGET_NEWEST_SHIP,
TARGET_NEXT_LIVE_TURRET,
TARGET_PREV_LIVE_TURRET,
ATTACK_MESSAGE,
DISARM_MESSAGE,
DISABLE_MESSAGE,
ATTACK_SUBSYSTEM_MESSAGE,
CAPTURE_MESSAGE,
ENGAGE_MESSAGE,
FORM_MESSAGE,
PROTECT_MESSAGE,
COVER_MESSAGE,
WARP_MESSAGE,
IGNORE_MESSAGE,
REARM_MESSAGE,
VIEW_CHASE,
VIEW_EXTERNAL,
VIEW_EXTERNAL_TOGGLE_CAMERA_LOCK,
VIEW_OTHER_SHIP,
VIEW_TOPDOWN,
VIEW_TRACK_TARGET,
RADAR_RANGE_CYCLE,
SQUADMSG_MENU,
SHOW_GOALS,
END_MISSION,
ADD_REMOVE_ESCORT,
ESCORT_CLEAR,
TARGET_NEXT_ESCORT_SHIP,
MULTI_MESSAGE_ALL,
MULTI_MESSAGE_FRIENDLY,
MULTI_MESSAGE_HOSTILE,
MULTI_MESSAGE_TARGET,
MULTI_OBSERVER_ZOOM_TO,
TOGGLE_HUD_CONTRAST,
MULTI_TOGGLE_NETINFO,
MULTI_SELF_DESTRUCT,
TOGGLE_HUD,
HUD_TARGETBOX_TOGGLE_WIREFRAME,
AUTO_PILOT_TOGGLE,
NAV_CYCLE,
TOGGLE_GLIDING,
CYCLE_PRIMARY_WEAPON_SEQUENCE,
};
int Ignored_keys[CCFG_MAX];
// set sizes of the key sets automatically
int Normal_key_set_size = sizeof(Normal_key_set) / sizeof(int);
int Dead_key_set_size = sizeof(Dead_key_set) / sizeof(int);
int Critical_key_set_size = sizeof(Critical_key_set) / sizeof(int);
int Non_critical_key_set_size = sizeof(Non_critical_key_set) / sizeof(int);
// --------------------------------------------------------------
// routine to process keys used only for debugging
// --------------------------------------------------------------
void debug_cycle_player_ship(int delta)
{
if ( Player_obj == NULL )
return;
int si_index = Ships[Player_obj->instance].ship_info_index;
int sanity = 0;
ship_info *sip;
while ( TRUE ) {
si_index += delta;
if ( si_index >= static_cast<int>(Ship_info.size()) ){
si_index = 0;
}
if ( si_index < 0 ){
si_index = static_cast<int>(Ship_info.size() - 1);
}
sip = &Ship_info[si_index];
if ( sip->flags[Ship::Info_Flags::Player_ship] ){
break;
}
// just in case
sanity++;
if ( sanity >= static_cast<int>(Ship_info.size()) ){
break;
}
}
change_ship_type(Player_obj->instance, si_index);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Player ship changed to %s", 0), Ship_info[si_index].name);
}
/**
* Cycle targeted ship to next ship in that species
* @param delta Increment
*/
void debug_cycle_targeted_ship(int delta)
{
object *objp;
ship_info *sip;
int si_index, species;
char name[NAME_LENGTH];
if ( Player_ai->target_objnum == -1 )
return;
objp = &Objects[Player_ai->target_objnum];
if ( objp->type != OBJ_SHIP )
return;
si_index = Ships[objp->instance].ship_info_index;
Assert(si_index != -1 );
species = Ship_info[si_index].species;
int sanity = 0;
while ( TRUE ) {
si_index += delta;
if ( si_index >= static_cast<int>(Ship_info.size()) )
si_index = 0;
if ( si_index < 0 )
si_index = static_cast<int>(Ship_info.size() - 1);
sip = &Ship_info[si_index];
// if it has test in the name, jump over it
strcpy_s(name, sip->name);
strlwr(name);
if ( strstr(name,NOX("test")) != NULL )
continue;
if (sip->species == species && (sip->is_fighter_bomber() || sip->flags[Ship::Info_Flags::Transport]))
break;
// just in case
sanity++;
if ( sanity >= static_cast<int>(Ship_info.size()) )
break;
}
change_ship_type(objp->instance, si_index);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Changed player target to %s", 1), Ship_info[si_index].name);
}
void debug_max_secondary_weapons(object *objp)
{
int index;
ship *shipp = &Ships[objp->instance];
ship_info *sip = &Ship_info[shipp->ship_info_index];
ship_weapon *swp = &shipp->weapons;
for ( index = 0; index < MAX_SHIP_SECONDARY_BANKS; index++ )
{
swp->secondary_bank_ammo[index] = sip->secondary_bank_ammo_capacity[index];
}
}
void debug_max_primary_weapons(object *objp) // Goober5000
{
Assert(objp); // Goober5000
int index;
ship *shipp = &Ships[objp->instance];
ship_info *sip = &Ship_info[shipp->ship_info_index];
ship_weapon *swp = &shipp->weapons;
weapon_info *wip;
for ( index = 0; index < MAX_SHIP_PRIMARY_BANKS; index++ )
{
wip = &Weapon_info[swp->primary_bank_weapons[index]];
if (wip->wi_flags[Weapon::Info_Flags::Ballistic])
{
float capacity, size;
capacity = (float) sip->primary_bank_ammo_capacity[index];
size = (float) wip->cargo_size;
swp->primary_bank_ammo[index] = fl2i((capacity / size)+0.5f);
}
}
}
void debug_change_song(int delta)
{
char buf[256];
if ( event_music_next_soundtrack(delta) != -1 ) {
event_music_get_soundtrack_name(buf);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Soundtrack changed to: %s", 2), buf);
} else {
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Event music is not playing", 3));
}
}
extern void hud_target_asteroid();
extern int Framerate_delay;
extern void snd_stop_any_sound();
extern vec3d Eye_position;
extern matrix Eye_matrix;
extern void g3_set_view_matrix(const vec3d *view_pos, const matrix *view_matrix, float zoom);
extern int Show_cpu;
int get_prev_weapon_looped(int current_weapon, int subtype)
{
int i, new_index;
for (i = 1; i < Num_weapon_types; i++)
{
new_index = (Num_weapon_types + current_weapon - i) % Num_weapon_types;
if(Weapon_info[new_index].subtype == subtype)
{
return new_index;
}
}
return current_weapon;
}
int get_next_weapon_looped(int current_weapon, int subtype)
{
int i, new_index;
for (i = 1; i < Num_weapon_types; i++)
{
new_index = (current_weapon + i) % Num_weapon_types;
if(Weapon_info[new_index].subtype == subtype)
{
return new_index;
}
}
return current_weapon;
}
void process_debug_keys(int k)
{
// Kazan -- NO CHEATS IN MULTI
if (Game_mode & GM_MULTIPLAYER)
{
Cheats_enabled = 0;
return;
}
switch (k) {
case KEY_DEBUGGED + KEY_Q:
case KEY_DEBUGGED1 + KEY_Q:
Snapshot_all_events = true;
break;
case KEY_DEBUGGED + KEY_H:
hud_target_toggle_hidden_from_sensors();
break;
case KEY_DEBUGGED + KEY_F:
extern int wacky_scheme;
if(wacky_scheme == 3){
wacky_scheme = 0;
} else {
wacky_scheme++;
}
break;
case KEY_DEBUGGED + KEY_ALTED + KEY_F:
Framerate_delay += 10;
HUD_printf(XSTR( "Framerate delay increased to %i milliseconds per frame.", 4), Framerate_delay);
break;
case KEY_DEBUGGED + KEY_ALTED + KEY_SHIFTED + KEY_F:
Framerate_delay -= 10;
if (Framerate_delay < 0)
Framerate_delay = 0;
HUD_printf(XSTR( "Framerate delay decreased to %i milliseconds per frame.", 5), Framerate_delay);
break;
case KEY_DEBUGGED + KEY_X:
case KEY_DEBUGGED1 + KEY_X:
HUD_printf("Cloaking has been disabled, thank you for playing fs2_open, %s", Player->callsign);
break;
case KEY_DEBUGGED + KEY_C:
case KEY_DEBUGGED1 + KEY_C:
if(Player_obj->flags[Object::Object_Flags::Collides]){
obj_set_flags(Player_obj, Player_obj->flags - Object::Object_Flags::Collides);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, "Player no longer collides");
} else {
obj_set_flags(Player_obj, Player_obj->flags + Object::Object_Flags::Collides);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, "Player collides");
}
break;
case KEY_DEBUGGED + KEY_SHIFTED + KEY_C:
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_C:
Countermeasures_enabled = !Countermeasures_enabled;
HUD_printf(XSTR( "Countermeasure firing: %s", 6), Countermeasures_enabled ? XSTR( "ENABLED", 7) : XSTR( "DISABLED", 8));
break;
// Goober5000: this should only be compiled in debug builds, since it crashes release
#ifndef NDEBUG
case KEY_DEBUGGED + KEY_E:
gameseq_post_event(GS_EVENT_EVENT_DEBUG);
break;
#endif
// Goober5000: handle time dilation in cheat section
case KEY_DEBUGGED + KEY_SHIFTED + KEY_COMMA:
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_COMMA:
if ( Game_mode & GM_NORMAL ) {
if ( Game_time_compression > (F1_0/MAX_TIME_DIVIDER) ) {
change_time_compression(0.5);
} else {
gamesnd_play_error_beep();
}
} else {
gamesnd_play_error_beep();
}
break;
// Goober5000: handle as normal here
case KEY_DEBUGGED + KEY_SHIFTED + KEY_PERIOD:
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_PERIOD:
if ( Game_mode & GM_NORMAL ) {
if ( Game_time_compression < (F1_0*MAX_TIME_MULTIPLIER) ) {
change_time_compression(2);
} else {
gamesnd_play_error_beep();
}
} else {
gamesnd_play_error_beep();
}
break;
// Kill! the currently targeted ship.
case KEY_DEBUGGED + KEY_K:
case KEY_DEBUGGED1 + KEY_K:
if (Player_ai->target_objnum != -1) {
object *objp = &Objects[Player_ai->target_objnum];
switch (objp->type) {
case OBJ_SHIP:
// remove guardian flag -- kazan
Ships[objp->instance].ship_guardian_threshold = 0;
ship_apply_local_damage( objp, Player_obj, &objp->pos, 100000.0f, MISS_SHIELDS, CREATE_SPARKS);
ship_apply_local_damage( objp, Player_obj, &objp->pos, 1.0f, MISS_SHIELDS, CREATE_SPARKS);
break;
case OBJ_WEAPON:
Weapons[objp->instance].lifeleft = 0.01f;
break;
}
}
break;
// play the next mission message
case KEY_DEBUGGED + KEY_V:
extern int Message_debug_index;
extern int Num_messages_playing;
// stop any other messages
if(Num_messages_playing){
message_kill_all(1);
}
// next message
if(Message_debug_index >= Num_messages - 1){
Message_debug_index = Num_builtin_messages;
} else {
Message_debug_index++;
}
// play the message
message_send_unique_to_player( Messages[Message_debug_index].name, Message_waves[Messages[Message_debug_index].wave_info.index].name, MESSAGE_SOURCE_SPECIAL, MESSAGE_PRIORITY_HIGH, 0, 0 );
if (Messages[Message_debug_index].avi_info.index == -1) {
HUD_printf("No anim set for message \"%s\"; None will play!", Messages[Message_debug_index].name);
}
break;
// play the previous mission message
case KEY_DEBUGGED + KEY_SHIFTED + KEY_V:
extern int Message_debug_index;
extern int Num_messages_playing;
// stop any other messages
if(Num_messages_playing){
message_kill_all(1);
}
// go maybe go down one
if(Message_debug_index == Num_builtin_messages - 1){
Message_debug_index = Num_builtin_messages;
} else if(Message_debug_index > Num_builtin_messages){
Message_debug_index--;
}
// play the message
message_send_unique_to_player( Messages[Message_debug_index].name, Message_waves[Messages[Message_debug_index].wave_info.index].name, MESSAGE_SOURCE_SPECIAL, MESSAGE_PRIORITY_HIGH, 0, 0 );
if (Messages[Message_debug_index].avi_info.index == -1) {
HUD_printf("No avi associated with this message; None will play!");
}
break;
// reset to the beginning of mission messages
case KEY_DEBUGGED + KEY_ALTED + KEY_V:
extern int Message_debug_index;
Message_debug_index = Num_builtin_messages - 1;
HUD_printf("Resetting to first mission message");
break;
// Kill! the currently targeted ship.
case KEY_DEBUGGED + KEY_ALTED + KEY_SHIFTED + KEY_K:
case KEY_DEBUGGED1 + KEY_ALTED + KEY_SHIFTED + KEY_K:
if (Player_ai->target_objnum != -1) {
object *objp = &Objects[Player_ai->target_objnum];
if (objp->type == OBJ_SHIP) {
ship_apply_local_damage( objp, Player_obj, &objp->pos, Ships[objp->instance].ship_max_hull_strength * 0.1f + 10.0f, MISS_SHIELDS, CREATE_SPARKS);
}
}
break;
// Kill the currently targeted subsystem.
case KEY_DEBUGGED + KEY_SHIFTED + KEY_K:
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_K:
if ((Player_ai->target_objnum != -1) && (Player_ai->targeted_subsys != NULL)) {
object *objp = &Objects[Player_ai->target_objnum];
if ( objp->type == OBJ_SHIP ) {
ship *sp = &Ships[objp->instance];
vec3d g_subobj_pos;
get_subsystem_world_pos(objp, Player_ai->targeted_subsys, &g_subobj_pos);
do_subobj_hit_stuff(objp, Player_obj, &g_subobj_pos, Player_ai->targeted_subsys->system_info->subobj_num, (float) -Player_ai->targeted_subsys->system_info->type, NULL); //100.0f);
if ( sp->subsys_info[SUBSYSTEM_ENGINE].aggregate_current_hits <= 0.0f ) {
mission_log_add_entry(LOG_SHIP_DISABLED, sp->ship_name, NULL );
sp->flags.set(Ship::Ship_Flags::Disabled); // add the disabled flag
}
if ( sp->subsys_info[SUBSYSTEM_TURRET].aggregate_current_hits <= 0.0f ) {
mission_log_add_entry(LOG_SHIP_DISARMED, sp->ship_name, NULL );
}
}
}
break;
case KEY_DEBUGGED + KEY_ALTED + KEY_K:
case KEY_DEBUGGED1 + KEY_ALTED + KEY_K:
{
float shield, integrity;
vec3d pos, randvec;
vm_vec_rand_vec_quick(&randvec);
vm_vec_scale_add(&pos, &Player_obj->pos, &randvec, Player_obj->radius);
ship_apply_local_damage(Player_obj, Player_obj, &pos, 25.0f, MISS_SHIELDS, CREATE_SPARKS);
hud_get_target_strength(Player_obj, &shield, &integrity);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "You knocked yourself down to %7.3f percent hull.\n", 9), 100.0f * integrity);
break;
}
// Whack down the player's shield and hull by a little more than 50%
// Select next object to be viewed by AI.
case KEY_DEBUGGED + KEY_I:
case KEY_DEBUGGED1 + KEY_I:
Player_obj->flags.toggle(Object::Object_Flags::Invulnerable);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "You are %s", 10), Player_obj->flags[Object::Object_Flags::Invulnerable] ? XSTR( "now INVULNERABLE!", 11) : XSTR( "no longer invulnerable...", 12));
break;
case KEY_DEBUGGED + KEY_SHIFTED + KEY_I:
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_I:
if (Player_ai->target_objnum != -1) {
object *objp = &Objects[Player_ai->target_objnum];
objp->flags.toggle(Object::Object_Flags::Invulnerable);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Player's target [%s] is %s", 13), Ships[objp->instance].ship_name, objp->flags[Object::Object_Flags::Invulnerable] ? XSTR( "now INVULNERABLE!", 11) : XSTR( "no longer invulnerable...", 12));
}
break;
case KEY_DEBUGGED + KEY_N:
AI_watch_object++;
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Spewing debug info about object #%d", 14), AI_watch_object);
break;
case KEY_DEBUGGED + KEY_O:
case KEY_DEBUGGED1 + KEY_O:
toggle_player_object();
break;
case KEY_DEBUGGED + KEY_SHIFTED + KEY_O:
extern int Debug_octant;
if(Debug_octant == 7){
Debug_octant = -1;
} else {
Debug_octant++;
}
nprintf(("General", "Debug_octant == %d\n", Debug_octant));
break;
case KEY_DEBUGGED + KEY_P:
supernova_start(20);
break;
case KEY_DEBUGGED + KEY_W:
case KEY_DEBUGGED1 + KEY_W:
case KEY_DEBUGGED + KEY_SHIFTED + KEY_W:
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_W:
// temp code for testing purposes, toggles weapon energy cheat
Weapon_energy_cheat = !Weapon_energy_cheat;
if (Weapon_energy_cheat) {
if (k & KEY_SHIFTED)
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Weapon energy and missile count will always be at full ALL SHIPS!", 15));
else
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Weapon energy and missile count will always be at full for player", 16));
debug_max_secondary_weapons(Player_obj);
debug_max_primary_weapons(Player_obj);
if (k & KEY_SHIFTED) {
object *objp;
for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) )
if (objp->type == OBJ_SHIP) {
debug_max_secondary_weapons(objp);
debug_max_primary_weapons(objp);
}
}
} else
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Normal weapon energy system / missile count restored", 17));
break;
case KEY_DEBUGGED + KEY_G:
case KEY_DEBUGGED1 + KEY_G:
mission_goal_mark_all_true( PRIMARY_GOAL );
break;
case KEY_DEBUGGED + KEY_G + KEY_SHIFTED:
case KEY_DEBUGGED1 + KEY_G + KEY_SHIFTED:
mission_goal_mark_all_true( SECONDARY_GOAL );
break;
case KEY_DEBUGGED + KEY_G + KEY_ALTED:
case KEY_DEBUGGED1 + KEY_G + KEY_ALTED:
mission_goal_mark_all_true( BONUS_GOAL );
break;
case KEY_DEBUGGED + KEY_9: {
case KEY_DEBUGGED1 + KEY_9:
ship* shipp;
shipp = &Ships[Player_obj->instance];
int *weap = &shipp->weapons.secondary_bank_weapons[shipp->weapons.current_secondary_bank];
*weap = get_next_weapon_looped(*weap, WP_MISSILE);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Secondary Weapon forced to %s", 18), Weapon_info[*weap].name);
break;
}
case KEY_DEBUGGED + KEY_SHIFTED + KEY_9: {
case KEY_DEBUGGED1 + KEY_SHIFTED + KEY_9:
ship* shipp;
shipp = &Ships[Player_obj->instance];
int *weap = &shipp->weapons.secondary_bank_weapons[shipp->weapons.current_secondary_bank];
*weap = get_prev_weapon_looped(*weap, WP_MISSILE);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Secondary Weapon forced to %s", 18), Weapon_info[*weap].name);
break;
}