Skip to content

Commit c33db75

Browse files
committed
Generalize mission save from original FRED
1 parent 300cd8a commit c33db75

File tree

15 files changed

+937
-677
lines changed

15 files changed

+937
-677
lines changed

code/missioneditor/common.cpp

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// methods and members common to any mission editor FSO may have
22
#include "common.h"
3+
#include "mission/missionparse.h"
4+
#include "iff_defs/iff_defs.h"
5+
#include "ship/ship.h"
36

47
// to keep track of data
58
char Voice_abbrev_briefing[NAME_LENGTH];
@@ -20,4 +23,93 @@ SCP_string Voice_script_instructions_string = "$name - name of the message\r\n"
2023
"$persona - persona of the sender\r\n"
2124
"$sender - name of the sender\r\n"
2225
"$note - message notes\r\n\r\n"
23-
"Note that $persona and $sender will only appear for the Message section.";
26+
"Note that $persona and $sender will only appear for the Message section.";
27+
28+
void time_to_mission_info_string(const std::tm* src, char* dest, size_t dest_max_len)
29+
{
30+
std::strftime(dest, dest_max_len, "%x at %X", src);
31+
}
32+
33+
void stuff_special_arrival_anchor_name(char* buf, int iff_index, int restrict_to_players, bool retail_format)
34+
{
35+
const char* iff_name = Iff_info[iff_index].iff_name;
36+
37+
// stupid retail hack
38+
if (retail_format && !stricmp(iff_name, "hostile") && !restrict_to_players)
39+
iff_name = "enemy";
40+
41+
if (restrict_to_players)
42+
sprintf(buf, "<any %s player>", iff_name);
43+
else
44+
sprintf(buf, "<any %s>", iff_name);
45+
46+
strlwr(buf);
47+
}
48+
49+
void stuff_special_arrival_anchor_name(char* buf, int anchor_num, bool retail_format)
50+
{
51+
// filter out iff
52+
int iff_index = anchor_num;
53+
iff_index &= ~SPECIAL_ARRIVAL_ANCHOR_FLAG;
54+
iff_index &= ~SPECIAL_ARRIVAL_ANCHOR_PLAYER_FLAG;
55+
56+
// filter players
57+
int restrict_to_players = (anchor_num & SPECIAL_ARRIVAL_ANCHOR_PLAYER_FLAG);
58+
59+
// get name
60+
stuff_special_arrival_anchor_name(buf, iff_index, restrict_to_players, retail_format);
61+
}
62+
63+
void generate_weaponry_usage_list_team(int team, int* arr)
64+
{
65+
int i;
66+
67+
for (i = 0; i < MAX_WEAPON_TYPES; i++) {
68+
arr[i] = 0;
69+
}
70+
71+
if (The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) {
72+
Assert(team >= 0 && team < MAX_TVT_TEAMS);
73+
74+
for (i = 0; i < MAX_TVT_WINGS_PER_TEAM; i++) {
75+
generate_weaponry_usage_list_wing(TVT_wings[(team * MAX_TVT_WINGS_PER_TEAM) + i], arr);
76+
}
77+
} else {
78+
for (i = 0; i < MAX_STARTING_WINGS; i++) {
79+
generate_weaponry_usage_list_wing(Starting_wings[i], arr);
80+
}
81+
}
82+
}
83+
84+
void generate_weaponry_usage_list_wing(int wing_num, int* arr)
85+
{
86+
int i, j;
87+
ship_weapon* swp;
88+
89+
if (wing_num < 0) {
90+
return;
91+
}
92+
93+
i = Wings[wing_num].wave_count;
94+
while (i--) {
95+
swp = &Ships[Wings[wing_num].ship_index[i]].weapons;
96+
j = swp->num_primary_banks;
97+
while (j--) {
98+
if (swp->primary_bank_weapons[j] >= 0 &&
99+
swp->primary_bank_weapons[j] < static_cast<int>(Weapon_info.size())) {
100+
arr[swp->primary_bank_weapons[j]]++;
101+
}
102+
}
103+
104+
j = swp->num_secondary_banks;
105+
while (j--) {
106+
if (swp->secondary_bank_weapons[j] >= 0 &&
107+
swp->secondary_bank_weapons[j] < static_cast<int>(Weapon_info.size())) {
108+
arr[swp->secondary_bank_weapons[j]] +=
109+
(int)floor((swp->secondary_bank_ammo[j] * swp->secondary_bank_capacity[j] / 100.0f /
110+
Weapon_info[swp->secondary_bank_weapons[j]].cargo_size) +
111+
0.5f);
112+
}
113+
}
114+
}
115+
}

code/missioneditor/common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ extern bool Voice_group_messages;
2424

2525
extern SCP_string Voice_script_default_string;
2626
extern SCP_string Voice_script_instructions_string;
27+
28+
void time_to_mission_info_string(const std::tm* src, char* dest, size_t dest_max_len);
29+
30+
void stuff_special_arrival_anchor_name(char* buf, int iff_index, int restrict_to_players, bool retail_format);
31+
32+
void stuff_special_arrival_anchor_name(char* buf, int anchor_num, bool retail_format);
33+
34+
void generate_weaponry_usage_list_team(int team, int* arr);
35+
36+
void generate_weaponry_usage_list_wing(int wing_num, int* arr);

0 commit comments

Comments
 (0)