forked from scp-fs2open/fs2open.github.com
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmissiongoals.cpp
More file actions
1576 lines (1307 loc) · 48.2 KB
/
Copy pathmissiongoals.cpp
File metadata and controls
1576 lines (1307 loc) · 48.2 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 "debugconsole/console.h"
#include "freespace.h"
#include "gamesequence/gamesequence.h"
#include "gamesnd/eventmusic.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/alphacolors.h"
#include "hud/hud.h"
#include "hud/hudmessage.h"
#include "io/key.h"
#include "io/timer.h"
#include "localization/localize.h"
#include "mission/missiongoals.h"
#include "mission/missionlog.h"
#include "missionui/missionscreencommon.h"
#include "mod_table/mod_table.h"
#include "network/multi.h"
#include "network/multi_sexp.h"
#include "network/multi_team.h"
#include "network/multimsgs.h"
#include "network/stand_gui.h"
#include "parse/parselo.h"
#include "parse/sexp.h"
#include "playerman/player.h"
#include "scripting/global_hooks.h"
#include "tracing/tracing.h"
#include "ui/ui.h"
// timestamp stuff for evaluating mission goals
#define GOAL_TIMESTAMP 0 // make immediately eval
#define GOAL_TIMESTAMP_TRAINING 500 // every half second
#define MAX_GOALS_PER_LIST 15
#define MAX_GOAL_LINES 200
// indicies for coordinates
#define GOAL_SCREEN_X_COORD 0
#define GOAL_SCREEN_Y_COORD 1
#define GOAL_SCREEN_W_COORD 2
#define GOAL_SCREEN_H_COORD 3
/*
#define GOAL_SCREEN_TEXT_X 81
#define GOAL_SCREEN_TEXT_Y 95
#define GOAL_SCREEN_TEXT_W 385
#define GOAL_SCREEN_TEXT_H 299
#define GOAL_SCREEN_ICON_X 45
*/
static int Goal_screen_text_coords[GR_NUM_RESOLUTIONS][4] = {
{
81,95,385,299 // GR_640
},
{
130,152,385,299 // GR_1024
}
};
static int Goal_screen_icon_xcoord[GR_NUM_RESOLUTIONS] = {
45, // GR_640
72 // GR_1024
};
// german version gets slightly diff coords
static int Objective_key_text_coords_gr[GR_NUM_RESOLUTIONS][3][2] = {
{
// GR_640
{175, 344},
{316, 344},
{432, 344}
},
{
// GR_1024
{310, 546},
{536, 546},
{688, 546}
}
};
static int Objective_key_icon_coords_gr[GR_NUM_RESOLUTIONS][3][2] = {
{
// GR_640
{150, 339},
{290, 339},
{406, 339}
},
{
// GR_1024
{272, 542},
{498, 542},
{650, 542}
}
};
static int Objective_key_text_coords[GR_NUM_RESOLUTIONS][3][2] = {
{
// GR_640
{195, 344},
{306, 344},
{432, 344}
},
{
// GR_1024
{310, 546},
{486, 546},
{688, 546}
}
};
static int Objective_key_icon_coords[GR_NUM_RESOLUTIONS][3][2] = {
{
// GR_640
{170, 339},
{280, 339},
{406, 339}
},
{
// GR_1024
{272, 542},
{448, 542},
{650, 542}
}
};
#define NUM_GOAL_SCREEN_BUTTONS 3 // total number of buttons
#define GOAL_SCREEN_BUTTON_SCROLL_UP 0
#define GOAL_SCREEN_BUTTON_SCROLL_DOWN 1
#define GOAL_SCREEN_BUTTON_RETURN 2
struct goal_list {
int count;
mission_goal *list[MAX_GOALS_PER_LIST];
int line_offsets[MAX_GOALS_PER_LIST];
int line_spans[MAX_GOALS_PER_LIST];
goal_list() : count(0) {}
void add(mission_goal *m);
void set();
void icons_display(int y);
};
struct goal_buttons {
const char *filename;
int x, y;
int hotspot;
UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
goal_buttons(const char *name, int x1, int y1, int h) : filename(name), x(x1), y(y1), hotspot(h) {}
};
struct goal_text {
int m_num_lines;
int m_line_sizes[MAX_GOAL_LINES];
const char *m_lines[MAX_GOAL_LINES];
void init();
int add(const char *text = NULL);
void display(int n, int y);
};
int Event_index = -1; // used by sexp code to tell what event it came from
bool Log_event = false;
bool Snapshot_all_events = false;
TIMESTAMP Mission_goal_timestamp;
SCP_vector<mission_event> Mission_events;
SCP_vector<mission_goal> Mission_goals; // structure for the goals of this mission
static goal_text Goal_text;
#define DIRECTIVE_SOUND_DELAY 500 // time directive success sound effect is delayed
#define DIRECTIVE_SPECIAL_DELAY 7000 // mark special directives as true after 7 seconds
static TIMESTAMP Mission_directive_sound_timestamp; // timestamp to control when directive succcess sound gets played
static TIMESTAMP Mission_directive_special_timestamp; // used to specially mark a directive as true even though it's not
const char *Goal_type_text(int n)
{
switch (n) {
case 0:
return XSTR( "Primary", 396);
case 1:
return XSTR( "Secondary", 397);
case 2:
return XSTR( "Bonus", 398);
}
return NULL;
}
static int Goal_screen_text_x;
static int Goal_screen_text_y;
static int Goal_screen_text_w;
static int Goal_screen_text_h;
static int Goal_screen_icon_x;
static goal_list Primary_goal_list;
static goal_list Secondary_goal_list;
static goal_list Bonus_goal_list;
static int Scroll_offset;
static int Goals_screen_bg_bitmap;
static int Goal_complete_bitmap;
static int Goal_incomplete_bitmap;
static int Goal_failed_bitmap;
static UI_WINDOW Goals_screen_ui_window;
goal_buttons Goal_buttons[NUM_GOAL_SCREEN_BUTTONS] = {
//XSTR:OFF
goal_buttons("MOB_00", 475, 288, 0),
goal_buttons("MOB_01", 475, 336, 1),
goal_buttons("MOB_02", 553, 409, 2),
//XSTR:ON
};
void goal_screen_button_pressed(int num);
void goal_screen_scroll_up();
void goal_screen_scroll_down();
//
/// goal_list structure functions
//
void goal_list::add(mission_goal *m)
{
Assert(count < MAX_GOALS_PER_LIST);
list[count++] = m;
}
void goal_list::set()
{
int i;
for (i=0; i<count; i++) {
line_offsets[i] = Goal_text.m_num_lines;
line_spans[i] = Goal_text.add(list[i]->message.c_str());
if (i < count - 1)
Goal_text.add();
}
}
void goal_list::icons_display(int yoff)
{
int i, y, ys, bmp, font_height;
font_height = gr_get_font_height();
for (i=0; i<count; i++) {
y = line_offsets[i] - yoff;
bmp = -1; // initialize for safety.
switch (list[i]->satisfied) {
case GOAL_COMPLETE:
bmp = Goal_complete_bitmap;
break;
case GOAL_INCOMPLETE:
bmp = Goal_incomplete_bitmap;
break;
case GOAL_FAILED:
bmp = Goal_failed_bitmap;
break;
}
if (bmp >= 0) {
bm_get_info(bmp, NULL, &ys, NULL);
y = Goal_screen_text_y // offset of text window on screen
+ y * font_height // relative line position offset
+ line_spans[i] * font_height / 2 // center of text offset
- ys / 2; // center of icon offest
if ((y >= Goal_screen_text_y - ys / 2) && (y + ys <= Goal_screen_text_y + Goal_screen_text_h + ys / 2)) {
gr_set_bitmap(bmp);
gr_bitmap(Goal_screen_icon_x, y, GR_RESIZE_MENU);
}
}
}
}
//
/// goal_text structure functions
//
// initializes the goal text struct (empties it out)
void goal_text::init()
{
m_num_lines = 0;
}
// Adds lines of goal text. If passed NULL (or nothing passed) a blank line is added. If
// the text is too long, it is automatically split into more than one line.
// Returns the number of lines added.
int goal_text::add(const char *text)
{
int max, count;
max = MAX_GOAL_LINES - m_num_lines;
if (max < 1) {
Error(LOCATION, "Goal text space exhausted");
return 0;
}
if (!text) {
m_lines[m_num_lines] = NULL;
m_line_sizes[m_num_lines++] = 0;
return 1;
}
count = split_str(text, Goal_screen_text_w - Goal_screen_text_coords[gr_screen.res][GOAL_SCREEN_X_COORD] + Goal_screen_icon_xcoord[gr_screen.res], m_line_sizes + m_num_lines, m_lines + m_num_lines, max, MAX_GOAL_TEXT);
m_num_lines += count;
return count;
}
// Display a line of goal text
// n = goal text line number
// y = y offset to draw relative to goal text area top
void goal_text::display(int n, int y)
{
int y1, w, h;
char buf[MAX_GOAL_TEXT];
if ((n < 0) || (n >= m_num_lines) || (m_line_sizes[n] < 1))
return; // out of range, don't draw anything
Assert(m_line_sizes[n] < MAX_GOAL_TEXT);
y += Goal_screen_text_y;
if (*m_lines[n] == '*') { // header line
gr_set_color_fast(&Color_text_heading);
strncpy(buf, m_lines[n] + 1, m_line_sizes[n] - 1);
buf[m_line_sizes[n] - 1] = 0;
gr_get_string_size(&w, &h, buf);
y1 = y + h / 2 - 1;
// custom_size me
gr_line(Goal_screen_icon_x, y1, Goal_screen_text_x - 2, y1, GR_RESIZE_MENU);
gr_line(Goal_screen_text_x + w + 1, y1, Goal_screen_icon_x + Goal_screen_text_w, y1, GR_RESIZE_MENU);
} else {
gr_set_color_fast(&Color_text_normal);
strncpy(buf, m_lines[n], m_line_sizes[n]);
buf[m_line_sizes[n]] = 0;
}
gr_printf_menu(Goal_screen_text_x, y, "%s", buf);
}
// Called as part of mission initialization.
void mission_goals_and_events_init()
{
Mission_goals.clear();
Mission_events.clear();
Mission_goal_timestamp = _timestamp(GOAL_TIMESTAMP);
Mission_directive_sound_timestamp = TIMESTAMP::invalid();
Mission_directive_special_timestamp = TIMESTAMP::invalid(); // need to make invalid right away
}
// called once right before entering the show goals screen to do initializations.
void mission_show_goals_init()
{
int i, type, team_num=0; // JAS: I set team_num to 0 because it was used without being initialized.
goal_buttons *b;
Scroll_offset = 0;
Primary_goal_list.count = 0;
Secondary_goal_list.count = 0;
Bonus_goal_list.count = 0;
Goal_screen_text_x = Goal_screen_text_coords[gr_screen.res][GOAL_SCREEN_X_COORD];
Goal_screen_text_y = Goal_screen_text_coords[gr_screen.res][GOAL_SCREEN_Y_COORD];
Goal_screen_text_w = Goal_screen_text_coords[gr_screen.res][GOAL_SCREEN_W_COORD];
Goal_screen_text_h = Goal_screen_text_coords[gr_screen.res][GOAL_SCREEN_H_COORD];
Goal_screen_icon_x = Goal_screen_icon_xcoord[gr_screen.res];
// fill up the lists so we can display the goals appropriately
for (i=0; i<(int)Mission_goals.size(); i++) {
if (Mission_goals[i].type & INVALID_GOAL){ // don't count invalid goals here
continue;
}
if ( (Game_mode & GM_MULTIPLAYER) && (The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) && (Mission_goals[i].team != team_num) ){
continue;
}
type = Mission_goals[i].type & GOAL_TYPE_MASK;
switch (type) {
case PRIMARY_GOAL:
Primary_goal_list.add(&Mission_goals[i]);
break;
case SECONDARY_GOAL:
Secondary_goal_list.add(&Mission_goals[i]);
break;
case BONUS_GOAL:
if (Mission_goals[i].satisfied == GOAL_COMPLETE){
Bonus_goal_list.add(&Mission_goals[i]);
}
break;
default:
Error(LOCATION, "Unknown goal priority encountered when displaying goals in mission\n");
break;
} // end switch
} // end for
Goal_text.init();
Goal_text.add(XSTR( "*Primary Objectives", 399));
Goal_text.add();
Primary_goal_list.set();
if (Secondary_goal_list.count) {
Goal_text.add();
Goal_text.add();
Goal_text.add(XSTR( "*Secondary Objectives", 400));
Goal_text.add();
Secondary_goal_list.set();
}
if (Bonus_goal_list.count) {
Goal_text.add();
Goal_text.add();
Goal_text.add(XSTR( "*Bonus Objectives", 401));
Goal_text.add();
Bonus_goal_list.set();
}
common_set_interface_palette("ObjectivesPalette"); // set the interface palette
Goals_screen_ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0);
Goals_screen_ui_window.set_mask_bmap("Objectives-m");
for (i=0; i<NUM_GOAL_SCREEN_BUTTONS; i++) {
b = &Goal_buttons[i];
b->button.create(&Goals_screen_ui_window, "", b->x, b->y, 60, 30, (i < 2), 1);
// set up callback for when a mouse first goes over a button
b->button.set_highlight_action(common_play_highlight_sound);
b->button.set_bmaps(b->filename);
b->button.link_hotspot(b->hotspot);
}
// set up hotkeys for buttons so we draw the correct animation frame when a key is pressed
Goal_buttons[GOAL_SCREEN_BUTTON_SCROLL_UP].button.set_hotkey(KEY_UP);
Goal_buttons[GOAL_SCREEN_BUTTON_SCROLL_DOWN].button.set_hotkey(KEY_DOWN);
Goals_screen_bg_bitmap = bm_load("ObjectivesBG");
Goal_complete_bitmap = bm_load("ObjComp");
Goal_incomplete_bitmap = bm_load("ObjIncomp");
Goal_failed_bitmap = bm_load("ObjFail");
if (Goals_screen_bg_bitmap < 0) {
Warning(LOCATION, "Could not load the background bitmap: ObjectivesBG.pcx");
}
}
// cleanup called when exiting the show goals screen
void mission_show_goals_close()
{
if (Goals_screen_bg_bitmap >= 0)
bm_release(Goals_screen_bg_bitmap);
if (Goal_complete_bitmap)
bm_release(Goal_complete_bitmap);
if (Goal_incomplete_bitmap)
bm_release(Goal_incomplete_bitmap);
if (Goal_failed_bitmap)
bm_release(Goal_failed_bitmap);
Goals_screen_ui_window.destroy();
common_free_interface_palette(); // restore game palette
game_flush();
}
// called once a frame during show goals state to process events and render the screen
void mission_show_goals_do_frame(float /*frametime*/)
{
int k, i, y, z;
int font_height = gr_get_font_height();
k = Goals_screen_ui_window.process();
switch (k) {
case KEY_ESC:
mission_goal_exit();
break;
case KEY_DOWN:
goal_screen_scroll_down();
break;
case KEY_UP:
goal_screen_scroll_up();
break;
default:
// do nothing
break;
} // end switch
for (i=0; i<NUM_GOAL_SCREEN_BUTTONS; i++){
if (Goal_buttons[i].button.pressed()){
goal_screen_button_pressed(i);
}
}
GR_MAYBE_CLEAR_RES(Goals_screen_bg_bitmap);
if (Goals_screen_bg_bitmap >= 0) {
gr_set_bitmap(Goals_screen_bg_bitmap);
gr_bitmap(0, 0, GR_RESIZE_MENU);
}
Goals_screen_ui_window.draw();
y = 0;
z = Scroll_offset;
while (y + font_height <= Goal_screen_text_h) {
Goal_text.display(z, y);
y += font_height;
z++;
}
Primary_goal_list.icons_display(Scroll_offset);
Secondary_goal_list.icons_display(Scroll_offset);
Bonus_goal_list.icons_display(Scroll_offset);
gr_flip();
}
// Mission Log Objectives subscreen init.
// Called once right before entering the Mission Log screen to do initializations.
int ML_objectives_init(int x, int y, int w, int h)
{
int i, type, team_num;
Primary_goal_list.count = 0;
Secondary_goal_list.count = 0;
Bonus_goal_list.count = 0;
Goal_screen_text_x = x - Goal_screen_icon_xcoord[gr_screen.res] + Goal_screen_text_coords[gr_screen.res][GOAL_SCREEN_X_COORD];
Goal_screen_text_y = y;
Goal_screen_text_w = w;
Goal_screen_text_h = h;
Goal_screen_icon_x = x;
team_num = 0; // this is the default team -- we will change it if in a multiplayer team v. team game
if ( (Game_mode & GM_MULTIPLAYER) && (The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) ){
team_num = Net_player->p_info.team;
}
// fill up the lists so we can display the goals appropriately
for (i=0; i<(int)Mission_goals.size(); i++) {
if (Mission_goals[i].type & INVALID_GOAL){ // don't count invalid goals here
continue;
}
if ( (Game_mode & GM_MULTIPLAYER) && (The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) && (Mission_goals[i].team != team_num) ){
continue;
}
type = Mission_goals[i].type & GOAL_TYPE_MASK;
switch (type) {
case PRIMARY_GOAL:
Primary_goal_list.add(&Mission_goals[i]);
break;
case SECONDARY_GOAL:
Secondary_goal_list.add(&Mission_goals[i]);
break;
case BONUS_GOAL:
if (Mission_goals[i].satisfied == GOAL_COMPLETE){
Bonus_goal_list.add(&Mission_goals[i]);
}
break;
default:
Error(LOCATION, "Unknown goal priority encountered when displaying goals in mission\n");
break;
} // end switch
} // end for
Goal_text.init();
Goal_text.add(XSTR( "*Primary Objectives", 399));
Goal_text.add();
Primary_goal_list.set();
if (Secondary_goal_list.count) {
Goal_text.add();
Goal_text.add();
Goal_text.add(XSTR( "*Secondary Objectives", 400));
Goal_text.add();
Secondary_goal_list.set();
}
if (Bonus_goal_list.count) {
Goal_text.add();
Goal_text.add();
Goal_text.add(XSTR( "*Bonus Objectives", 401));
Goal_text.add();
Bonus_goal_list.set();
}
Goal_complete_bitmap = bm_load("ObjComp");
Goal_incomplete_bitmap = bm_load("ObjIncomp");
Goal_failed_bitmap = bm_load("ObjFail");
return Goal_text.m_num_lines;
}
// cleanup called when exiting the show goals screen
void ML_objectives_close()
{
if (Goal_complete_bitmap >= 0) {
bm_release(Goal_complete_bitmap);
}
if (Goal_incomplete_bitmap >= 0) {
bm_release(Goal_incomplete_bitmap);
}
if (Goal_failed_bitmap >= 0) {
bm_release(Goal_failed_bitmap);
}
}
void ML_objectives_do_frame(int scroll_offset)
{
int y, z;
int font_height = gr_get_font_height();
y = 0;
z = scroll_offset;
while (y + font_height <= Goal_screen_text_h) {
Goal_text.display(z, y);
y += font_height;
z++;
}
Primary_goal_list.icons_display(scroll_offset);
Secondary_goal_list.icons_display(scroll_offset);
Bonus_goal_list.icons_display(scroll_offset);
}
void ML_render_objectives_key()
{
// display icon key at the bottom
if (Lcl_gr) {
gr_set_bitmap(Goal_complete_bitmap);
gr_bitmap(Objective_key_icon_coords_gr[gr_screen.res][0][0], Objective_key_icon_coords_gr[gr_screen.res][0][1], GR_RESIZE_MENU);
gr_set_bitmap(Goal_incomplete_bitmap);
gr_bitmap(Objective_key_icon_coords_gr[gr_screen.res][1][0], Objective_key_icon_coords_gr[gr_screen.res][1][1], GR_RESIZE_MENU);
gr_set_bitmap(Goal_failed_bitmap);
gr_bitmap(Objective_key_icon_coords_gr[gr_screen.res][2][0], Objective_key_icon_coords_gr[gr_screen.res][2][1], GR_RESIZE_MENU);
gr_string(Objective_key_text_coords_gr[gr_screen.res][0][0], Objective_key_text_coords_gr[gr_screen.res][0][1] , XSTR("Complete", 1437), GR_RESIZE_MENU);
gr_string(Objective_key_text_coords_gr[gr_screen.res][1][0], Objective_key_text_coords_gr[gr_screen.res][1][1] , XSTR("Incomplete", 1438), GR_RESIZE_MENU);
gr_string(Objective_key_text_coords_gr[gr_screen.res][2][0], Objective_key_text_coords_gr[gr_screen.res][2][1] , XSTR("Failed", 1439), GR_RESIZE_MENU);
} else {
gr_set_bitmap(Goal_complete_bitmap);
gr_bitmap(Objective_key_icon_coords[gr_screen.res][0][0], Objective_key_icon_coords[gr_screen.res][0][1], GR_RESIZE_MENU);
gr_set_bitmap(Goal_incomplete_bitmap);
gr_bitmap(Objective_key_icon_coords[gr_screen.res][1][0], Objective_key_icon_coords[gr_screen.res][1][1], GR_RESIZE_MENU);
gr_set_bitmap(Goal_failed_bitmap);
gr_bitmap(Objective_key_icon_coords[gr_screen.res][2][0], Objective_key_icon_coords[gr_screen.res][2][1], GR_RESIZE_MENU);
gr_string(Objective_key_text_coords[gr_screen.res][0][0], Objective_key_text_coords[gr_screen.res][0][1] , XSTR("Complete", 1437), GR_RESIZE_MENU);
gr_string(Objective_key_text_coords[gr_screen.res][1][0], Objective_key_text_coords[gr_screen.res][1][1] , XSTR("Incomplete", 1438), GR_RESIZE_MENU);
gr_string(Objective_key_text_coords[gr_screen.res][2][0], Objective_key_text_coords[gr_screen.res][2][1] , XSTR("Failed", 1439), GR_RESIZE_MENU);
}
}
// maybe distribute the event/goal score between the players on that team
void multi_player_maybe_add_score (int score, int team)
{
int players_in_team = 0;
int idx;
// if i'm not the server of a multiplayer game, bail here
if(!MULTIPLAYER_MASTER){
return;
}
if (!(The_mission.ai_profile->flags[AI::Profile_Flags::Allow_multi_event_scoring])) {
return;
}
// first count the number of players in this team
for (idx=0; idx<MAX_PLAYERS; idx++) {
if (MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].p_info.team == team)) {
players_in_team++;
}
}
if (!players_in_team) {
return;
}
for (idx=0; idx<MAX_PLAYERS; idx++) {
if (MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].p_info.team == team)) {
Net_players[idx].m_player->stats.m_score += (int)(score * scoring_get_scale_factor() / players_in_team );
}
}
}
/**
* Hook for temporarily displaying objective completion/failure
*/
void mission_goal_status_change( int goal_num, int new_status)
{
int type;
Assert(goal_num < (int)Mission_goals.size());
Assert((new_status == GOAL_FAILED) || (new_status == GOAL_COMPLETE));
// if in a multiplayer game, send a status change to clients
if ( MULTIPLAYER_MASTER ){
send_mission_goal_info_packet( goal_num, new_status, -1 );
}
type = Mission_goals[goal_num].type & GOAL_TYPE_MASK;
bool isOverride = false;
if (scripting::hooks::OnMissionGoalStatusChanged->isActive()) {
auto paramList = scripting::hook_param_list(scripting::hook_param("Name", 's', Mission_goals[goal_num].name),
scripting::hook_param("Description", 's', Mission_goals[goal_num].message),
scripting::hook_param("Type", 'i', type + 1),
scripting::hook_param("State", 'b', new_status == GOAL_COMPLETE));
if (scripting::hooks::OnMissionGoalStatusChanged->isOverride(paramList)) {
isOverride = true; // Override here only prevents displaying the goals and playing the music. Everything
// else still runs.
}
scripting::hooks::OnMissionGoalStatusChanged->run(std::move(paramList));
}
Mission_goals[goal_num].satisfied = new_status;
if ( new_status == GOAL_FAILED ) {
// don't display bonus goal failure
if (type != BONUS_GOAL ) {
// only do HUD and music if goals are my teams goals.
if ( (Game_mode & GM_NORMAL) || ((Net_player != NULL) && (Net_player->p_info.team == Mission_goals[goal_num].team)) ) {
if (!isOverride) {
hud_add_objective_messsage(type, new_status);
if (!(Mission_goals[goal_num].flags & MGF_NO_MUSIC)) { // maybe play event music
event_music_primary_goal_failed();
}
}
}
}
mission_log_add_entry( LOG_GOAL_FAILED, Mission_goals[goal_num].name.c_str(), nullptr, goal_num );
} else if ( new_status == GOAL_COMPLETE ) {
if ( (Game_mode & GM_NORMAL) || ((Net_player != NULL) && (Net_player->p_info.team == Mission_goals[goal_num].team))) {
if (!isOverride) {
hud_add_objective_messsage(type, new_status);
// cue for Event Music
if (!(Mission_goals[goal_num].flags & MGF_NO_MUSIC)) {
event_music_primary_goals_met();
}
}
mission_log_add_entry( LOG_GOAL_SATISFIED, Mission_goals[goal_num].name.c_str(), nullptr, goal_num );
}
if(Game_mode & GM_MULTIPLAYER){
multi_team_maybe_add_score(Mission_goals[goal_num].score, Mission_goals[goal_num].team);
multi_player_maybe_add_score(Mission_goals[goal_num].score, Mission_goals[goal_num].team);
} else {
// deal with the score
Player->stats.m_score += (int)(Mission_goals[goal_num].score * scoring_get_scale_factor());
}
}
}
// return value:
// UNBORN = event has yet to be available (not yet evaluatable)
// CURRENT = current (evaluatable), but not yet true
// SATISFIED = event has occured (true)
// FAILED = event failed, can't possibly become true anymore
EventStatus mission_get_event_status(int event)
{
// check for directive special events first. We will always return from this part of the if statement
if ( Mission_events[event].flags & MEF_DIRECTIVE_SPECIAL ) {
Assertion(Mission_events[event].flags & MEF_CURRENT, "An event should have MEF_CURRENT set if it also has MEF_DIRECTIVE_SPECIAL set");
// if this event is temporarily true, return as such
if ( Mission_events[event].flags & MEF_DIRECTIVE_TEMP_TRUE ){
return EventStatus::SATISFIED;
}
// if the timestamp has elapsed, we can "mark" this directive as true although it's really not.
if ( timestamp_elapsed(Mission_directive_special_timestamp) ) {
Mission_events[event].satisfied_time = _timestamp();
Mission_events[event].flags |= MEF_DIRECTIVE_TEMP_TRUE;
}
return EventStatus::CURRENT;
} else if (Mission_events[event].flags & MEF_CURRENT) {
if (!Mission_events[event].born_on_date.isValid()) {
Mission_events[event].born_on_date = _timestamp();
}
if (Mission_events[event].result) {
return EventStatus::SATISFIED;
}
if (Mission_events[event].flags & MEF_EVENT_IS_DONE) {
return EventStatus::FAILED;
}
return EventStatus::CURRENT;
}
return EventStatus::UNBORN;
}
void mission_event_set_directive_special(int event)
{
// bogus
if((event < 0) || (event >= (int)Mission_events.size())){
return;
}
Assertion(Mission_events[event].flags & MEF_CURRENT, "An event should have MEF_CURRENT set before it has MEF_DIRECTIVE_SPECIAL set");
Mission_events[event].flags |= MEF_DIRECTIVE_SPECIAL;
// start from a known state
Mission_events[event].flags &= ~MEF_DIRECTIVE_TEMP_TRUE;
Mission_directive_special_timestamp = _timestamp(DIRECTIVE_SPECIAL_DELAY);
}
void mission_event_unset_directive_special(int event)
{
// bogus
if((event < 0) || (event >= (int)Mission_events.size())){
return;
}
Mission_events[event].flags &= ~(MEF_DIRECTIVE_SPECIAL);
// this event may be marked temporarily true -- if so, then unmark this value!!!
if ( Mission_events[event].flags & MEF_DIRECTIVE_TEMP_TRUE ){
Mission_events[event].flags &= ~MEF_DIRECTIVE_TEMP_TRUE;
}
Mission_events[event].satisfied_time = TIMESTAMP::invalid();
Mission_directive_special_timestamp = TIMESTAMP::invalid();
}
void mission_event_set_completion_sound_timestamp()
{
Mission_directive_sound_timestamp = _timestamp(DIRECTIVE_SOUND_DELAY);
}
// function which evaluates and processes the given event
void mission_process_event( int event )
{
int store_flags = Mission_events[event].flags;
int store_result = Mission_events[event].result;
int store_count = Mission_events[event].count;
int result, sindex;
bool bump_timestamp = false;
Log_event = false;
Directive_count = 0;
Event_index = event;
sindex = Mission_events[event].formula;
result = Mission_events[event].result;
// In retail, known-false or no-longer-repeating events would set the formula to -1, so sindex would be -1 for those events.
// However, the formula would be checked before this function is called, so that situation shouldn't happen here. Furthermore,
// we now use a flag rather than setting the formula. We should check all that now.
Assertion((sindex >= 0) && !(Mission_events[event].flags & MEF_EVENT_IS_DONE), "mission_process_event was called for an event that should not be processed!");
// if chained, insure that previous event is true and next event is false
if (Mission_events[event].chain_delay >= 0) { // this indicates it's chained
int offset;
if (Mission_events[event].flags & MEF_USE_MSECS) {
offset = Mission_events[event].chain_delay;
} else {
offset = Mission_events[event].chain_delay * MILLISECONDS_PER_SECOND;
}
// What everyone expected the chaining behavior to be, as specified in Karajorma's original fix to Mantis #82
if (Alternate_chaining_behavior) {
if (event > 0){
if (!Mission_events[event - 1].result || !timestamp_elapsed(timestamp_delta(Mission_events[event - 1].satisfied_time, offset))) {
sindex = -1; // bypass evaluation
}
}
}
// Volition's original chaining behavior as used in retail and demonstrated in e.g. btm-01.fsm (or btm-01.fs2 in the Port)
else {
if (event > 0){
// This flag is needed because of a remarkable coincidence of mistakes that all counteracted each other perfectly to produce an important feature.
// It appears that originally mission_event.timestamp was in fix units, like satisfied_time and born_on_date. At some point this was changed to
// a timestamp, but not every assignment was changed. And since a fix is an int under the hood, there were no type conflicts. Surprisingly there
// were no logic errors either; the fix/Missiontime assignments happened after the timestamps were needed, and the only places where the timestamp
// field was treated as a fix (here and in sexp_event_delay_status) happened after the event had been resolved and the Missiontime assignments had
// occurred. The mission_event.timestamp field spent half its life as one unit and half as another, successfully.
//
// The following chaining behavior check typically occurred during the fix/Missiontime part of the life cycle. However, for chained events that
// repeat, the event is granted a new timestamp and the chain check is performed on mixed units. Due to the way the condition was written, the
// much-too-small comparison evaluated to false successfully and allowed the event subsequent to the chained repeating event to become current.
// This is the behavior necessary to allow the "Match Speed 1 1/2" event in btm-01.fsm to activate, display the "Match Speed" directive, and
// continue with the mission. Without this behavior, the mission would break.
//
// Naturally, upgrading the timestamps caused all evaluations to use consistent units and broke the mission. Due to the long repeat interval, the
// timestamp was evaluated too late when the event was likely to have become false. The previous mixed-units comparison avoided the repeat interval
// precisely at the right time, and then became consistent units when the repeat interval no longer mattered. In order to restore the expected
// behavior while keeping all units consistent, it is necessary to set a flag when a timestamp includes an interval so that the interval can be
// deducted from the period of time that evaluation is bypassed.
//
// To say this another way, the timestamp field represents the time at which the event will be evaluated again, not the time at which the event
// was last evaluated. Subtracting the interval accounts for this difference.
//
if (Mission_events[event - 1].flags & MEF_TIMESTAMP_HAS_INTERVAL) {
if (Mission_events[event - 1].flags & MEF_USE_MSECS) {
offset -= Mission_events[event - 1].interval;
} else {
offset -= Mission_events[event - 1].interval * MILLISECONDS_PER_SECOND;
}
}
if (!Mission_events[event - 1].result) {
sindex = -1; // bypass evaluation
}
// For compatibility reasons, simulate the old buggy behavior if we don't explicitly activate the bugfix.
// That is, if the timestamp has been set with an interval, always evaluate the event.
else if (!Fixed_chaining_to_repeat && Mission_events[event - 1].flags & MEF_TIMESTAMP_HAS_INTERVAL) {
/* do not bypass */;
}
else if (!timestamp_elapsed(timestamp_delta(Mission_events[event - 1].timestamp, offset))) {
sindex = -1; // bypass evaluation
}
}
if ((event < (int)Mission_events.size() - 1) && Mission_events[event + 1].result && (Mission_events[event + 1].chain_delay >= 0)){
sindex = -1; // bypass evaluation
}
}
}
if (sindex >= 0) {
Assume_event_is_current = true;
if (Snapshot_all_events || Mission_events[event].mission_log_flags != 0) {
Log_event = true;
Current_event_log_buffer = &Mission_events[event].event_log_buffer;
Current_event_log_variable_buffer = &Mission_events[event].event_log_variable_buffer;
Current_event_log_container_buffer = &Mission_events[event].event_log_container_buffer;
Current_event_log_argument_buffer = &Mission_events[event].event_log_argument_buffer;
}
result = eval_sexp(sindex);
// if the directive count is a special value, deal with that first. Mark the event as a special
// event, and unmark it when the directive is true again.
if ( (Directive_count == DIRECTIVE_WING_ZERO) && !(Mission_events[event].flags & MEF_DIRECTIVE_SPECIAL) ) {
// only mark it special if it's actually current
if (Mission_events[event].flags & MEF_CURRENT) {
// make it special - which basically just means that its true until the next wave arrives
mission_event_set_directive_special(event);
}
Directive_count = 0;
} else if ( (Mission_events[event].flags & MEF_DIRECTIVE_SPECIAL) && Directive_count > 1 ) {
// make it non special
mission_event_unset_directive_special(event);
}
if (Mission_events[event].count || (Directive_count > 1) || (Always_show_directive_value_count && Directive_count != DIRECTIVE_WING_ZERO)) {
Mission_events[event].count = Directive_count;
}
if (Assume_event_is_current){
Mission_events[event].flags |= MEF_CURRENT;
}
if ((Mission_events[event].mission_log_flags != 0) || Snapshot_all_events){
maybe_write_to_event_log(result);