This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
forked from markol/machines
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fstpersn.cpp
2559 lines (2228 loc) · 87.8 KB
/
fstpersn.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
/*
* F S T P E R S N . C P P
* (c) Charybdis Limited, 1998. All Rights Reserved
*/
// Definitions of non-inline non-template methods and global functions
#include "machgui/fstpersn.hpp"
#include "mathex/point2d.hpp"
#include "mathex/transf3d.hpp"
#include "mathex/eulerang.hpp"
#include "mathex/random.hpp"
#include "world4d/scenemgr.hpp"
#include "world4d/domain.hpp"
#include "world4d/envirnmt.hpp"
#include "world4d/soundman.hpp"
#include "world4d/entity.hpp"
#include "world4d/manager.hpp"
#include "envirnmt/planet.hpp"
#include "render/device.hpp"
#include "render/camera.hpp"
#include "gui/painter.hpp"
#include "gui/event.hpp"
#include "gui/image.hpp"
#include "device/keyboard.hpp"
#include "device/keytrans.hpp"
#include "machlog/actor.hpp"
#include "machlog/aggressr.hpp"
#include "machlog/camera.hpp"
#include "machlog/canattac.hpp"
#include "machlog/machine.hpp"
#include "machlog/p1mchndl.hpp"
#include "machlog/MachLog1stPersonActiveSquad.hpp"
#include "machlog/plandoms.hpp"
#include "machlog/planet.hpp"
#include "machlog/weapon.hpp"
#include "machlog/cntrl_pc.hpp"
#include "machlog/races.hpp"
#include "machlog/network.hpp"
#include "machlog/vmman.hpp"
#include "machgui/ingame.hpp"
#include "machgui/cameras.hpp"
#include "machgui/animatio.hpp"
#include "machgui/radar.hpp"
#include "machgui/chatmsgd.hpp"
#include "machgui/chatmsgs.hpp"
#include "machgui/database.hpp"
#include "machgui/dbscenar.hpp"
#include "machgui/MachGuiFPCommand.hpp"
#include "machphys/objdata.hpp"
#include "machphys/snddata.hpp"
#include "machphys/machine.hpp"
#include "system/pathname.hpp"
#include "system/registry.hpp"
#include "device/time.hpp"
#include "machgui/internal/mgsndman.hpp"
#include "sim/manager.hpp"
#define WEAPON_DROPDOWN_TIME 0.7
#define WEAPON_DROPDOWN_DELAYTIME 0.4
#define WEAPON_DROPDOWN_FRAMES 10
#define STARTUP_SEQUENCE_TIME 0.5
#define STARTUP_SEQUENCE_FRAMES 10
class MachGuiPausedImage : public GuiDisplayable
{
public:
MachGuiPausedImage(GuiDisplayable* pParent, MachInGameScreen* pInGameScreen)
: GuiDisplayable(pParent, Gui::Box(0, 0, 0, 0), GuiDisplayable::LAYER5)
, pInGameScreen_(pInGameScreen)
{
}
void doDisplay() override
{
// Display "Paused" in centre of screen if game is paused
if (SimManager::instance().isSuspended())
{
// Get screen dimensions
RenDevice& device = *W4dManager::instance().sceneManager()->pDevice();
const int w = device.windowWidth();
const int h = device.windowHeight();
GuiBitmap pausedBmp;
switch (pInGameScreen_->actualGameState())
{
case MachInGameScreen::WON:
if (MachGuiDatabase::instance().currentScenario().isTrainingScenario())
{
pausedBmp = Gui::bitmap("gui/misc/complete.bmp");
}
else
{
pausedBmp = Gui::bitmap("gui/misc/victory.bmp");
}
break;
case MachInGameScreen::LOST:
if (MachGuiDatabase::instance().currentScenario().isTrainingScenario())
{
pausedBmp = Gui::bitmap("gui/misc/failed.bmp");
}
else
{
pausedBmp = Gui::bitmap("gui/misc/defeat.bmp");
}
break;
default:
pausedBmp = Gui::bitmap("gui/misc/paused.bmp");
break;
}
pausedBmp.enableColourKeying();
int xPos = (w / 2) - (pausedBmp.width() / 2);
int yPos = (h / 2) - (pausedBmp.height() / 2);
GuiPainter::instance().blit(pausedBmp, Gui::Coord(xPos, yPos));
}
else if (pInGameScreen_->isNetworkStuffed())
{
// Get screen dimensions
RenDevice& device = *W4dManager::instance().sceneManager()->pDevice();
const int w = device.windowWidth();
const int h = device.windowHeight();
int borderHeight = h * 0.05;
// Display "Network Busy" message ( top right )
GuiBitmap pausedBmp = Gui::bitmap("gui/misc/netbusy.bmp");
pausedBmp.enableColourKeying();
int xPos = w - pausedBmp.width();
GuiPainter::instance().blit(pausedBmp, Gui::Coord(xPos, borderHeight + 2));
}
}
private:
MachInGameScreen* pInGameScreen_;
};
class MachGuiFirstPersonImpl
{
public:
MachGuiFirstPersonImpl();
bool switchToMenus_ = false;
bool switchToInGame_ = false;
MachActor* pActor_ = nullptr;
MachInGameScreen* pInGameScreen_ = nullptr;
bool inFirstPerson_ = false;
W4dSceneManager* pSceneManager_ = nullptr;
int borderHeight_;
int lastBorderHeight_;
DevKeyToCommandTranslator* pKeyTranslator_;
DevKeyToCommandTranslator::CommandList commandList_;
MachLog1stPersonHandler* pLogHandler_ = nullptr; // Handles 1st person commands - makes things happen in game
MexPoint3d targetPoint_; // The point currently to be aimed at (global coords)
MachGuiAnimation* pAttackCursor_ = nullptr; // Attack cross-hair
MachGuiAnimation* pNormalCursor_ = nullptr; // Nothing to target cursor
MachGuiAnimation* pMissCursor_ = nullptr; // Targeted on actor but weapons cannot tilt
MachGuiAnimation* pStartCursor_ = nullptr; // When machine is first embodied, cursor expands.
bool switchBackToGroundCamera_; // Camera to switch back to when leaving 1st person
MachActor* pTargetActor_ = nullptr;
GuiBitmap compassBmp_;
GuiBitmap healthBmp_;
GuiBitmap armourBmp_;
MachGuiRadar* pRadar_ = nullptr;
int borderDrawCount_;
GuiBitmap leftWeaponBmp_;
GuiBitmap rightWeaponBmp_;
GuiBitmap topWeaponBmp_;
GuiBitmap weaponChargeBmp_;
GuiBitmap weaponBackgroundBmp_;
int weaponSelectIndex_;
bool justEnteredFirstPerson_;
GuiBitmap weaponStartupFrames_[10];
double leftWeaponChangeEndTime_;
double rightWeaponChangeEndTime_;
double topWeaponChangeEndTime_;
int leftWeaponPos_;
int rightWeaponPos_;
int topWeaponPos_;
bool resolutionChanged_;
bool isDead_;
PhysAbsoluteTime timeOfDeath_;
MachGuiInGameChatMessagesDisplay* pChatMessageDisplay_ = nullptr;
bool rightMouseButtonHeadTurningUsed_ = false;
double lastRightClickTime_ = 0.0; // Used for checking for right mouse button double click
double timeWeaponsFired_;
MachGuiPausedImage* pPausedImage_ = nullptr;
bool reverseUpDownKeys_;
bool reverseUpDownMouse_;
MexBasicRandom hitInterferenceRandom_;
bool machineNVGOn_= false;
double startupTimer_;
bool finishedStartupSequence_ = false;
bool isHitInterferenceOn_;
double hitInterferenceEndTime_;
int frameNumber_;
// FP Command
MachGuiFPCommand* pCommandWidget_ = nullptr;
int64_t commandSquadIndex_;
double timeSquadIndexChanged_ = 0.0;
};
MachGuiFirstPersonImpl::MachGuiFirstPersonImpl()
: switchBackToGroundCamera_(true)
, compassBmp_(Gui::bitmap("gui/fstpersn/cursor/compass.bmp"))
, healthBmp_(Gui::bitmap("gui/fstpersn/cursor/health.bmp"))
, armourBmp_(Gui::bitmap("gui/fstpersn/cursor/armour.bmp"))
, weaponChargeBmp_(Gui::bitmap("gui/fstpersn/weapon/chrgey.bmp"))
, weaponBackgroundBmp_(Gui::bitmap("gui/fstpersn/weapon/weapon.bmp"))
, resolutionChanged_(true)
, reverseUpDownKeys_(SysRegistry::instance().queryIntegerValue("Options\\Reverse UpDown Keys", "on"))
, reverseUpDownMouse_(SysRegistry::instance().queryIntegerValue("Options\\Reverse BackForward Mouse", "on"))
, hitInterferenceRandom_(MexBasicRandom::constructSeededFromTime())
, commandSquadIndex_(-1L)
{
compassBmp_.enableColourKeying();
weaponChargeBmp_.enableColourKeying();
weaponBackgroundBmp_.enableColourKeying();
}
MachGuiFirstPerson::MachGuiFirstPerson(W4dSceneManager* pSceneManager, W4dRoot*, MachInGameScreen* pInGameScreen)
: GuiRoot(Gui::Box(0, 0, 10000, 10000))
{
// Create implementation
pImpl_ = _NEW(MachGuiFirstPersonImpl());
// De-pImpl_ variables used within this function.
CB_DEPIMPL(MachInGameScreen*, pInGameScreen_);
CB_DEPIMPL(W4dSceneManager*, pSceneManager_);
CB_DEPIMPL(DevKeyToCommandTranslator*, pKeyTranslator_);
CB_DEPIMPL(DevKeyToCommandTranslator::CommandList, commandList_);
CB_DEPIMPL(MachGuiPausedImage*, pPausedImage_);
commandList_.reserve(NUM_COMMANDS + 1);
pInGameScreen_ = pInGameScreen;
pSceneManager_ = pSceneManager;
// Setup keyboard translator
pKeyTranslator_ = _NEW(DevKeyToCommandTranslator());
// Keyboard shoot handler
pKeyTranslator_->addTranslation(DevKeyToCommand(DevKey::SPACE, FIRE));
// Keboard centre head handlers
pKeyTranslator_->addTranslation(DevKeyToCommand(DevKey::PAD_5, CENTREHEAD));
// Keboard weapon select handlers
pKeyTranslator_->addTranslation(DevKeyToCommand(DevKey::TAB, WEAPONSELECT));
// Keboard move foward/backward handlers
pKeyTranslator_->addTranslation(
DevKeyToCommand(DevKey::UP_ARROW, FOWARD, DevKeyToCommand::CTRLKEY_EITHER, DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::DOWN_ARROW,
BACKWARD,
DevKeyToCommand::CTRLKEY_EITHER,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::UP_ARROW_PAD,
FOWARD,
DevKeyToCommand::CTRLKEY_EITHER,
DevKeyToCommand::SHIFTKEY_RELEASED));
// Removed by NA 3/2/99 so that switch to zenith works. obviously you can no longer reverse the machine using the
// pad down arrow key.
// pKeyTranslator_->addTranslation( DevKeyToCommand( DevKey::DOWN_ARROW_PAD, BACKWARD,
// DevKeyToCommand::CTRLKEY_EITHER, DevKeyToCommand::SHIFTKEY_RELEASED ) );
// Keyboard head up/down handlers
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::UP_ARROW,
LOOKDOWNFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::DOWN_ARROW,
LOOKUPFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::UP_ARROW,
LOOKDOWN,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::DOWN_ARROW,
LOOKUP,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_PRESSED));
// Keyboard turn left/right handlers
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW,
TURNLEFT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW,
TURNRIGHT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW,
TURNLEFTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW,
TURNRIGHTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW_PAD,
TURNLEFT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW_PAD,
TURNRIGHT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW_PAD,
TURNLEFTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW_PAD,
TURNRIGHTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
// Keyboard turn head left/right handlers
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW,
TURNHEADLEFT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW,
TURNHEADRIGHT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW,
TURNHEADLEFTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW,
TURNHEADRIGHTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW_PAD,
TURNHEADLEFT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW_PAD,
TURNHEADRIGHT,
DevKeyToCommand::CTRLKEY_PRESSED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::LEFT_ARROW_PAD,
TURNHEADLEFTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_PRESSED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::RIGHT_ARROW_PAD,
TURNHEADRIGHTFAST,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_PRESSED));
// Keyboard commands for first person command
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::HOME,
COMMAND_SELECT_NEXT,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::END,
COMMAND_SELECT_PREV,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::KEY_DELETE,
COMMAND_ORDER_ATTACK,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::PAGE_DOWN,
COMMAND_ORDER_MOVE,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->addTranslation(DevKeyToCommand(
DevKey::INSERT,
COMMAND_ORDER_FOLLOW,
DevKeyToCommand::CTRLKEY_RELEASED,
DevKeyToCommand::SHIFTKEY_RELEASED));
pKeyTranslator_->initEventQueue();
// Setup command list that stores foward, backward, etc motion status.
for (size_t i = 0; i < NUM_COMMANDS; ++i)
{
commandList_.push_back(DevKeyToCommandTranslator::Command());
}
pPausedImage_ = _NEW(MachGuiPausedImage(this, pInGameScreen_));
TEST_INVARIANT;
}
MachGuiFirstPerson::~MachGuiFirstPerson()
{
TEST_INVARIANT;
// De-pImpl_ variables used within this function.
CB_DEPIMPL(DevKeyToCommandTranslator*, pKeyTranslator_);
CB_DEPIMPL(MachLog1stPersonHandler*, pLogHandler_);
CB_DEPIMPL(MachGuiPausedImage*, pPausedImage_);
CB_DEPIMPL(MachGuiFPCommand*, pCommandWidget_);
if (pCommandWidget_ != nullptr)
{
delete pCommandWidget_;
}
_DELETE(pKeyTranslator_);
_DELETE(pLogHandler_);
_DELETE(pPausedImage_);
_DELETE(pImpl_);
}
void MachGuiFirstPerson::CLASS_INVARIANT
{
INVARIANT(this != nullptr);
}
std::ostream& operator<<(std::ostream& o, const MachGuiFirstPerson& t)
{
o << "MachGuiFirstPerson " << (void*)&t << " start" << std::endl;
o << "MachGuiFirstPerson " << (void*)&t << " end" << std::endl;
return o;
}
// virtual
void MachGuiFirstPerson::doDisplay()
{
// De-pImpl_ variables used within this function.
CB_DEPIMPL(W4dSceneManager*, pSceneManager_);
CB_DEPIMPL(int, lastBorderHeight_);
CB_DEPIMPL(int, borderDrawCount_);
CB_DEPIMPL(bool, justEnteredFirstPerson_);
CB_DEPIMPL(MachGuiAnimation*, pStartCursor_);
CB_DEPIMPL(MachLog1stPersonHandler*, pLogHandler_);
CB_DEPIMPL(bool, finishedStartupSequence_);
CB_DEPIMPL(int, frameNumber_);
if (borderDrawCount_ or not finishedStartupSequence_)
{
// Get screen dimensions
RenDevice& device = *pSceneManager_->pDevice();
const int w = device.windowWidth();
const int h = device.windowHeight();
// Borders at top and bottom of screen.
GuiPainter::instance().filledRectangle(Gui::Box(0, h - lastBorderHeight_, w, h), Gui::BLACK());
GuiPainter::instance().filledRectangle(Gui::Box(0, 0, w, lastBorderHeight_), Gui::BLACK());
if (borderDrawCount_)
{
--borderDrawCount_;
}
}
displayCompass();
displayHealthArmour();
displayWeapons();
if (justEnteredFirstPerson_ == true)
{
MachGuiSoundManager::instance().playSound("gui/sounds/radaron.wav");
// If there are any weapons then play the weapon selection sound.
if (pLogHandler_ and pLogHandler_->nWeapons())
MachGuiSoundManager::instance().playSound("gui/sounds/weapchng.wav");
justEnteredFirstPerson_ = false;
}
++frameNumber_;
}
// virtual
void MachGuiFirstPerson::update()
{
// De-pImpl_ variables used within this function.
CB_DEPIMPL(MachLog1stPersonHandler*, pLogHandler_);
CB_DEPIMPL(DevKeyToCommandTranslator::CommandList, commandList_);
CB_DEPIMPL(DevKeyToCommandTranslator*, pKeyTranslator_);
CB_DEPIMPL(MachGuiAnimation*, pAttackCursor_);
CB_DEPIMPL(MachGuiAnimation*, pNormalCursor_);
CB_DEPIMPL(MachGuiAnimation*, pMissCursor_);
CB_DEPIMPL(MachGuiAnimation*, pStartCursor_);
CB_DEPIMPL(MexPoint3d, targetPoint_);
CB_DEPIMPL(MachActor*, pTargetActor_);
CB_DEPIMPL(MachActor*, pActor_);
CB_DEPIMPL(W4dSceneManager*, pSceneManager_);
CB_DEPIMPL(MachInGameScreen*, pInGameScreen_);
CB_DEPIMPL(bool, justEnteredFirstPerson_);
CB_DEPIMPL(bool, isDead_);
CB_DEPIMPL(PhysAbsoluteTime, timeOfDeath_);
CB_DEPIMPL(bool, rightMouseButtonHeadTurningUsed_);
CB_DEPIMPL(double, timeWeaponsFired_);
CB_DEPIMPL(bool, reverseUpDownKeys_);
CB_DEPIMPL(bool, reverseUpDownMouse_);
CB_DEPIMPL(MexBasicRandom, hitInterferenceRandom_);
CB_DEPIMPL(bool, machineNVGOn_);
CB_DEPIMPL(double, hitInterferenceEndTime_);
CB_DEPIMPL(double, startupTimer_);
CB_DEPIMPL(bool, finishedStartupSequence_)
CB_DEPIMPL(bool, isHitInterferenceOn_);
CB_DEPIMPL(int, frameNumber_);
CB_DEPIMPL(int64_t, commandSquadIndex_);
CB_DEPIMPL(MachGuiFPCommand*, pCommandWidget_);
CB_DEPIMPL(double, timeSquadIndexChanged_);
double now = DevTime::instance().time();
if (justEnteredFirstPerson_ == true)
{
// Controls when weapon not recharged sound is played.
timeWeaponsFired_ = now;
// Keeps the squad changing from going too fast
timeSquadIndexChanged_ = now;
}
// Check to see if we should automatically leave 1st person
if (not isDead_)
{
MachPhys::Race playerRace = MachLogRaces::instance().pcController().race();
// If the actor has been deleted or has changed race then exit the actor
if (not pActor_ or pActor_->isDead() or pActor_->race() != playerRace)
{
isDead_ = true;
timeOfDeath_ = Phys::time();
}
}
if (isDead_)
{
pInGameScreen_->sceneManager().pDevice()->interferenceOn(std::min((Phys::time() - timeOfDeath_) + 0.1, 1.0));
if (Phys::time() - timeOfDeath_ > 0.5)
{
switchToInGame();
}
return;
}
// Reset startup cursor animation
if (justEnteredFirstPerson_ == true)
pStartCursor_->jumpToCell(0);
pKeyTranslator_->resetCommands(&commandList_);
// Check have a handler
if (pLogHandler_)
{
MachLog1stPersonHandler& logHandler = *pLogHandler_;
if (commandSquadIndex_ == -1L and logHandler.getActiveSquadron().hasActiveSquadron())
{
commandSquadIndex_ = logHandler.getActiveSquadron().getActiveSquadronId() - 1;
}
if (pActor_
and not(
pActor_->objectType() == MachLog::AGGRESSOR and pActor_->asAggressor().subType() == MachPhys::NINJA
and pActor_->busy())) // prevents major movement when gorilla is doing its ground punch
{
if (commandList_[FOWARD].on())
{
logHandler.moveForwards();
}
if (commandList_[BACKWARD].on())
{
logHandler.moveBackwards();
}
if (commandList_[TURNLEFT].on())
{
logHandler.turnAtFastRate(false);
logHandler.turnLeft();
}
if (commandList_[TURNRIGHT].on())
{
logHandler.turnAtFastRate(false);
logHandler.turnRight();
}
if (commandList_[TURNLEFTFAST].on())
{
logHandler.turnAtFastRate(true);
logHandler.turnLeft();
}
if (commandList_[TURNRIGHTFAST].on())
{
logHandler.turnAtFastRate(true);
logHandler.turnRight();
}
}
// Cycle squadrons for Command
if (commandList_[COMMAND_SELECT_NEXT].on())
{
// prevent super-fast cycling
if (now - timeSquadIndexChanged_ >= 0.15)
{
// start over if need be
if (++commandSquadIndex_ > 9)
{
commandSquadIndex_ = 0;
}
const_cast<MachLog1stPersonActiveSquadron&>(logHandler.getActiveSquadron())
.setActiveSquadron(commandSquadIndex_);
pCommandWidget_->updateSquadIcon();
pCommandWidget_->updateSquadNumber();
// If commandSquadIndex didn't point to an empty squad, update time variable.
timeSquadIndexChanged_
= ((logHandler.getActiveSquadron().getActiveSquadronId() - 1 ^ commandSquadIndex_) == 0)
? now
: timeSquadIndexChanged_;
}
}
if (commandList_[COMMAND_SELECT_PREV].on())
{
// prevent super-fast cycling
if (now - timeSquadIndexChanged_ >= 0.15)
{
// roll back over to end
if (--commandSquadIndex_ < 0)
{
commandSquadIndex_ = 9;
}
const_cast<MachLog1stPersonActiveSquadron&>(logHandler.getActiveSquadron())
.setActiveSquadron(commandSquadIndex_);
pCommandWidget_->updateSquadIcon();
pCommandWidget_->updateSquadNumber();
// If commandSquadIndex didn't point to an empty squad, update time variable.
timeSquadIndexChanged_
= ((logHandler.getActiveSquadron().getActiveSquadronId() - 1 ^ commandSquadIndex_) == 0)
? now
: timeSquadIndexChanged_;
}
}
// The command icons should not light up if there's nobody selected. This value will be used more further
// down...
bool canIssueCommands = logHandler.getActiveSquadron().hasActiveSquadron();
if (not canIssueCommands)
{
pCommandWidget_->setAttackIconState(MachGuiFPCommand::CommandIconState::INVALID);
pCommandWidget_->setFollowIconState(MachGuiFPCommand::CommandIconState::INVALID);
pCommandWidget_->setMoveIconState(MachGuiFPCommand::CommandIconState::INVALID);
}
// Turn head...
if (commandList_[TURNHEADLEFT].on() and logHandler.canTurnHead())
{
logHandler.turnHeadBy(-MexDegrees(1.0));
}
if (commandList_[TURNHEADRIGHT].on() and logHandler.canTurnHead())
{
logHandler.turnHeadBy(MexDegrees(1.0));
}
if (commandList_[TURNHEADLEFTFAST].on() and logHandler.canTurnHead())
{
logHandler.turnHeadBy(-MexDegrees(10.0));
}
if (commandList_[TURNHEADRIGHTFAST].on() and logHandler.canTurnHead())
{
logHandler.turnHeadBy(MexDegrees(10.0));
}
// Look up/down...
if (commandList_[LOOKUP].on())
{
if (reverseUpDownKeys_)
logHandler.lookDown(MexDegrees(0.5));
else
logHandler.lookDown(-MexDegrees(0.5));
}
if (commandList_[LOOKDOWN].on())
{
if (reverseUpDownKeys_)
logHandler.lookDown(-MexDegrees(0.5));
else
logHandler.lookDown(MexDegrees(0.5));
}
if (commandList_[LOOKUPFAST].on())
{
if (reverseUpDownKeys_)
logHandler.lookDown(MexDegrees(5.0));
else
logHandler.lookDown(-MexDegrees(5.0));
}
if (commandList_[LOOKDOWNFAST].on())
{
if (reverseUpDownKeys_)
logHandler.lookDown(-MexDegrees(5.0));
else
logHandler.lookDown(MexDegrees(5.0));
}
// Centre head...
if (commandList_[CENTREHEAD].on()
or (rightMouseButtonHeadTurningUsed_ and not DevMouse::instance().rightButton()))
{
rightMouseButtonHeadTurningUsed_ = false;
if (logHandler.canTurnHead())
{
logHandler.turnHeadTo(MexRadians(0));
}
logHandler.lookAhead();
}
// Turn machine head or whole body...
// Get screen size.
RenDevice& device = *pSceneManager_->pDevice();
const double halfScreenWidth = (double)device.windowWidth() / 2.0;
const double halfScreenHeight = (double)device.windowHeight() / 2.0;
// Get new mouse position
DevMouse::Position mousePos = DevMouse::instance().position();
double deltaX = (double)mousePos.first - halfScreenWidth;
double deltaY = (double)mousePos.second - halfScreenHeight;
double origDeltaX = deltaX;
// If head can turn independant of body then do so ( as long as Shift is pressed or Right mouse button pressed
// )...
if (logHandler.canTurnHead() and (DevKeyboard::instance().shiftPressed() or DevMouse::instance().rightButton()))
{
if (DevMouse::instance().rightButton())
rightMouseButtonHeadTurningUsed_ = true;
// in fast mode movement is progressivly faster based on distance mouse has moved
// half screen width = 10 deg rotation ( in slow mode )
if (DevKeyboard::instance().ctrlPressed())
{
deltaX = (deltaX / halfScreenWidth) * (Mathex::PI / 18.0);
}
else
{
// Move ten times faster when mouse has moved a long way ( 60 pixels )
if (not(deltaX < 60.0 and deltaX > -60.0))
{
deltaX *= 7.0;
}
deltaX = (deltaX / halfScreenHeight) * (Mathex::PI / 7.0);
}
if (deltaX != 0.0)
logHandler.turnHeadBy(deltaX);
}
else // Move whole body
{
// Work out if body should be turning at fast rate
bool turnFast = false;
if (not DevKeyboard::instance().ctrlPressed() and ((deltaX < -10.0 or deltaX > 10.0) or deltaX == 0.0))
{
turnFast = true;
}
logHandler.turnAtFastRate(turnFast);
if (deltaX < 0)
{
logHandler.turnLeft();
}
else if (deltaX > 0)
{
logHandler.turnRight();
}
}
// Look up/down. All machines can do this.
// in fast mode movement is progressivly faster based on distance mouse has moved
// half screen height = 10 deg rotation ( in slow mode )
if (DevKeyboard::instance().ctrlPressed())
{
deltaY = (deltaY / halfScreenHeight) * (Mathex::PI / 18.0);
}
else
{
if (abs(origDeltaX) < abs(deltaY * 3.0))
{
// Move two times faster when mouse has moved a long way ( 50 pixels )
if (not(deltaY < 50.0 and deltaY > -50.0))
{
deltaY *= 4.0;
}
deltaY = (deltaY / halfScreenHeight) * (Mathex::PI / 12.0);
}
else
{
deltaY = 0.0;
}
}
if (deltaY != 0.0)
{
if (reverseUpDownMouse_)
logHandler.lookDown(-deltaY);
else
logHandler.lookDown(deltaY);
}
// Reset mouse position to centre of screen
DevMouse::instance().changePosition(halfScreenWidth, halfScreenHeight);
// Update the handler
logHandler.update();
// Check the current aim
MachLog1stPersonTargetInfo targetingInfo;
logHandler.acquireTargetingInfo(targetingInfo);
// This guy is used for the health indicator stuff elsewhere in this file. Will either be someone you can shoot
// at or NULL
pTargetActor_ = targetingInfo.shootingTarget;
bool viableTarget = targetingInfo.strikeType == MachPhys::ON_OBJECT;
bool viableShootingTarget = (targetingInfo.shootingTarget != nullptr) and viableTarget;
bool viableCommandTarget = (targetingInfo.getCommandTarget() != nullptr) and viableTarget;
bool viableMoveToTarget
= logHandler.isPointingTowardsGround() and logHandler.isViableMoveToTarget(targetingInfo);
bool moveIndicatorPresent = logHandler.isMoveIndicatorPresent();
// Don't allow the target of ore holos or debris!
if (viableShootingTarget)
{
if (targetingInfo.shootingTarget->objectIsOreHolograph() or targetingInfo.shootingTarget->objectIsDebris())
{
viableTarget = false;
}
}
else if (viableCommandTarget)
{
if (targetingInfo.getCommandTarget()->objectIsOreHolograph()
or targetingInfo.getCommandTarget()->objectIsDebris())
{
viableTarget = false;
}
}
// FOR SHOOTING: Are we targeting a machine?
if (viableShootingTarget and viableTarget)
{
// Enemy machine?
if (targetingInfo.shootingTarget->race() != pActor_->race())
{
bool anglesValid = logHandler.targetAnglesValid();
// Display attack cursor or miss cursor
if (not pAttackCursor_->isVisible() and anglesValid)
{
// Attack cursor has just come on line. play sound
MachGuiSoundManager::instance().playSound("gui/sounds/attackon.wav");
}
pAttackCursor_->isVisible(anglesValid);
pMissCursor_->isVisible(not anglesValid);
}
else
{
if (not pMissCursor_->isVisible())
{
// Attack cursor has just come on line. play sound
MachGuiSoundManager::instance().playSound("gui/sounds/friendon.wav");
}
// Display miss cursor ( friendly machine )
pAttackCursor_->isVisible(false);
pMissCursor_->isVisible(true);
}
}
else
{
// Hide attack cursors
pAttackCursor_->isVisible(false);
pMissCursor_->isVisible(false);
}
// FOR COMMAND: Are we targeting a machine?
if (canIssueCommands and viableCommandTarget and viableTarget)
{
// Enemy machine?
if (targetingInfo.getCommandTarget()->race() != pActor_->race())
{
// Light up Attack Icon
pCommandWidget_->setAttackIconState(MachGuiFPCommand::CommandIconState::VALID);
// Dim the Follow Icon
pCommandWidget_->setFollowIconState(MachGuiFPCommand::CommandIconState::INVALID);
}
else
{
// He's a friend bruv!
// Don't light up Attack Icon
pCommandWidget_->setAttackIconState(MachGuiFPCommand::CommandIconState::INVALID);
// Light up Follow Icon (FOLLOW FRIENDLY)
pCommandWidget_->setFollowIconState(MachGuiFPCommand::CommandIconState::VALID);
}
}
else
{
if (canIssueCommands)
{
// Don't light up attack icon
pCommandWidget_->setAttackIconState(MachGuiFPCommand::CommandIconState::INVALID);
// Light up Follow Icon (FOLLOW SELF)
pCommandWidget_->setFollowIconState(MachGuiFPCommand::CommandIconState::VALID);
// Only light up Move Icon when pointing at navigable ground AND when the indicator disappears
if (viableMoveToTarget and not moveIndicatorPresent)
{
pCommandWidget_->setMoveIconState(MachGuiFPCommand::CommandIconState::VALID);
}
else
{
pCommandWidget_->setMoveIconState(MachGuiFPCommand::CommandIconState::INVALID);
}
}
}
// Display normal or startup cursor - This is the CROSSHAIRS btw
if (pStartCursor_->cellIndex() == pStartCursor_->numCells() - 1)
{
pNormalCursor_->isVisible(not viableTarget or not viableShootingTarget);
pStartCursor_->isVisible(false);
}
else
{
pNormalCursor_->isVisible(false);
pStartCursor_->isVisible(not viableTarget);
// End startup cursor animation if there is a valid target
if (viableTarget)
{
pStartCursor_->jumpToCell(pStartCursor_->numCells() - 1);
}
}
// Fire enabled weapons if requested
if (commandList_[FIRE].on() or DevMouse::instance().leftButton())
{
bool canFire = false;
// Check that at least one weapon can fire
for (uint weaponIndex = 0; weaponIndex < logHandler.nWeapons() and not canFire; ++weaponIndex)
{
if (not targetingInfo.shootingTarget and logHandler.weaponCanOnlyFireAtActor(weaponIndex))
{
// canFire remains as false
}
else
{
if (logHandler.weapon(weaponIndex).percentageRecharge() >= 100
and logHandler.isWeaponEnabled(weaponIndex))
{
// We've found a weapon that can fire
canFire = true;
}
}
}
if (not canFire)
{
// timeWeaponsFired_ stops sound from being triggered over and over
if (now - timeWeaponsFired_ > 0.8)
{
MachGuiSoundManager::instance().playSound("gui/sounds/nowefire.wav");
timeWeaponsFired_ = now;
}
}