Skip to content

Commit aab84f6

Browse files
committed
tvt and mission versioning
1 parent a0fcf28 commit aab84f6

17 files changed

Lines changed: 311 additions & 111 deletions

code/mission/missionparse.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,9 +1248,9 @@ void parse_player_info2(mission *pm)
12481248
ptr->weaponry_count[num_choices] = wc.count;
12491249
if (pm->support_ships.rearm_pool_from_loadout) {
12501250
if (Weapon_info[wc.index].disallow_rearm) {
1251-
pm->support_ships.rearm_weapon_pool[wc.index] = 0;
1252-
} else if (wc.count > 0 && pm->support_ships.rearm_weapon_pool[wc.index] >= 0) {
1253-
pm->support_ships.rearm_weapon_pool[wc.index] += wc.count;
1251+
pm->support_ships.rearm_weapon_pool[nt][wc.index] = 0;
1252+
} else if (wc.count > 0 && pm->support_ships.rearm_weapon_pool[nt][wc.index] >= 0) {
1253+
pm->support_ships.rearm_weapon_pool[nt][wc.index] += wc.count;
12541254
}
12551255
}
12561256

@@ -1292,11 +1292,11 @@ void parse_player_info2(mission *pm)
12921292
}
12931293

12941294
if (Weapon_info[wc.index].disallow_rearm) {
1295-
pm->support_ships.rearm_weapon_pool[wc.index] = 0;
1295+
pm->support_ships.rearm_weapon_pool[nt][wc.index] = 0;
12961296
} else if (wc.count < 0) {
1297-
pm->support_ships.rearm_weapon_pool[wc.index] = -1;
1298-
} else if (wc.count > 0 && pm->support_ships.rearm_weapon_pool[wc.index] >= 0) {
1299-
pm->support_ships.rearm_weapon_pool[wc.index] += wc.count;
1297+
pm->support_ships.rearm_weapon_pool[nt][wc.index] = -1;
1298+
} else if (wc.count > 0 && pm->support_ships.rearm_weapon_pool[nt][wc.index] >= 0) {
1299+
pm->support_ships.rearm_weapon_pool[nt][wc.index] += wc.count;
13001300
}
13011301
}
13021302
}
@@ -7110,7 +7110,7 @@ void mission::Reset()
71107110
support_ships.max_support_ships = -1; // infinite
71117111
support_ships.max_concurrent_ships = 1;
71127112
support_ships.ship_class = -1;
7113-
memset(&support_ships.rearm_weapon_pool, -1, sizeof(int) * MAX_WEAPON_TYPES);
7113+
memset(&support_ships.rearm_weapon_pool, -1, sizeof(support_ships.rearm_weapon_pool));
71147114
support_ships.disallow_rearm = false;
71157115
support_ships.allow_rearm_weapon_precedence = false;
71167116
support_ships.rearm_pool_from_loadout = false;
@@ -9485,5 +9485,24 @@ bool check_for_24_3_data()
94859485

94869486
bool check_for_25_1_data()
94879487
{
9488-
return (count_items_with_value(Props) > 0);
9488+
if ((count_items_with_value(Props) > 0)) {
9489+
return true;
9490+
}
9491+
9492+
if (The_mission.flags[Mission::Mission_Flags::Limited_support_rearm_pool]) {
9493+
return true;
9494+
}
9495+
9496+
if (The_mission.support_ships.disallow_rearm || The_mission.support_ships.allow_rearm_weapon_precedence ||
9497+
The_mission.support_ships.rearm_pool_from_loadout) {
9498+
return true;
9499+
}
9500+
9501+
for (int team = 0; team < Num_teams; ++team) {
9502+
for (int weapon = 0; weapon < MAX_WEAPON_TYPES; ++weapon) {
9503+
if (The_mission.support_ships.rearm_weapon_pool[team][weapon] != -1) {
9504+
return true;
9505+
}
9506+
}
9507+
}
94899508
}

code/mission/missionparse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ typedef struct support_ship_info {
117117
bool disallow_rearm; // if true, support ships can only repair and will not rearm weapons
118118
bool allow_rearm_weapon_precedence; // if true, support ships may swap to precedence weapons when rearm pool is empty
119119
bool rearm_pool_from_loadout; // initialize rearm pool from mission loadout after filling starting loadout ships
120-
int rearm_weapon_pool[MAX_WEAPON_TYPES]; // mission stockpile used to limit support ship rearming
120+
int rearm_weapon_pool[MAX_TVT_TEAMS][MAX_WEAPON_TYPES]; // mission stockpile used to limit support ship rearming
121121
} support_ship_info;
122122

123123
// movie type defines

code/missioneditor/missionsave.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,14 +4402,12 @@ int Fred_mission_save::save_players()
44024402
}
44034403

44044404
fout(" (\n");
4405-
if (i == 0) {
4406-
for (j = 0; j < weapon_info_size(); j++) {
4407-
if (!Weapon_info[j].wi_flags[Weapon::Info_Flags::Player_allowed]) {
4408-
continue;
4409-
}
4410-
if (The_mission.support_ships.rearm_weapon_pool[j] != 0) {
4411-
fout("\t\"%s\"\t%d\n", Weapon_info[j].name, The_mission.support_ships.rearm_weapon_pool[j]);
4412-
}
4405+
for (j = 0; j < weapon_info_size(); j++) {
4406+
if (!Weapon_info[j].wi_flags[Weapon::Info_Flags::Player_allowed]) {
4407+
continue;
4408+
}
4409+
if (The_mission.support_ships.rearm_weapon_pool[i][j] != 0) {
4410+
fout("\t\"%s\"\t%d\n", Weapon_info[j].name, The_mission.support_ships.rearm_weapon_pool[i][j]);
44134411
}
44144412
}
44154413
fout(")");

code/scripting/api/libs/mission.cpp

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "scripting/api/objs/ship.h"
6666
#include "scripting/api/objs/shipclass.h"
6767
#include "scripting/api/objs/sound.h"
68+
#include "scripting/api/objs/support_rearm_pool.h"
6869
#include "scripting/api/objs/team.h"
6970
#include "scripting/api/objs/vecmath.h"
7071
#include "scripting/api/objs/volumetric.h"
@@ -262,67 +263,40 @@ ADE_FUNC(runSEXP, l_Mission, "string", "Runs the defined SEXP script within a `w
262263
return ADE_RETURN_FALSE;
263264
}
264265

265-
//****SUBLIBRARY: Mission/SupportRearmPool
266-
ADE_LIB_DERIV(l_Mission_SupportRearmPool, "SupportRearmPool", nullptr,
267-
"Array of mission support rearm pool values. Index is weapon class index.", l_Mission);
266+
//****SUBLIBRARY: Mission/SupportRearmPools
267+
ADE_LIB_DERIV(l_Mission_SupportRearmPools,
268+
"SupportRearmPools",
269+
nullptr,
270+
"Per-team mission support rearm pools (team indexed).",
271+
l_Mission);
268272

269-
ADE_INDEXER(l_Mission_SupportRearmPool,
270-
"number/weaponclass IndexOrClass, number amount",
271-
"Gets/sets support rearm pool value for a weapon class.\n"
272-
"Values: -1 = unlimited, 0 = unavailable, >0 = limited amount.\n"
273-
"If a weapon has $Disallow Support Rearm, this always returns 0 and ignores writes.",
274-
"number",
275-
"Current pool value for the weapon class.")
273+
ADE_INDEXER(l_Mission_SupportRearmPools,
274+
"number TeamIndex",
275+
"Gets support rearm pool handle for a specific team.",
276+
"support_rearm_pool_team",
277+
"Support rearm pool team handle, or invalid handle if index is out of range.")
276278
{
277279
int idx = -1;
278-
int amount;
279-
if (lua_isnumber(L, 2)) {
280-
if (!ade_get_args(L, "*i|i", &idx, &amount)) {
281-
return ADE_RETURN_NIL;
282-
}
283-
284-
if (idx < 1 || idx > weapon_info_size()) {
285-
return ADE_RETURN_NIL;
286-
}
287-
288-
idx--; // Lua to C++ index
289-
} else {
290-
if (!ade_get_args(L, "*o|i", l_Weaponclass.Get(&idx), &amount)) {
291-
return ADE_RETURN_NIL;
292-
}
293-
294-
if (idx < 0 || idx >= weapon_info_size()) {
295-
return ADE_RETURN_NIL;
296-
}
280+
if (!ade_get_args(L, "*i", &idx)) {
281+
return ade_set_error(L, "o", l_SupportRearmPoolTeam.Set(-1));
297282
}
298283

299-
if (ADE_SETTING_VAR) {
300-
if (!Weapon_info[idx].disallow_rearm) {
301-
if (amount < 0) {
302-
The_mission.support_ships.rearm_weapon_pool[idx] = -1;
303-
} else {
304-
The_mission.support_ships.rearm_weapon_pool[idx] = amount;
305-
}
306-
} else {
307-
The_mission.support_ships.rearm_weapon_pool[idx] = 0;
308-
}
309-
}
310-
311-
if (Weapon_info[idx].disallow_rearm) {
312-
return ade_set_args(L, "i", 0);
284+
idx--; // Lua to C++ index
285+
if (idx < 0 || idx >= Num_teams || idx >= MAX_TVT_TEAMS) {
286+
return ade_set_error(L, "o", l_SupportRearmPoolTeam.Set(-1));
313287
}
314288

315-
return ade_set_args(L, "i", The_mission.support_ships.rearm_weapon_pool[idx]);
289+
return ade_set_args(L, "o", l_SupportRearmPoolTeam.Set(idx));
316290
}
317291

318292
ADE_FUNC(__len,
319-
l_Mission_SupportRearmPool,
293+
l_Mission_SupportRearmPools,
320294
nullptr,
321-
"The number of weapon classes in the support rearm pool array",
295+
"The number of support rearm pool teams.",
322296
"number",
323-
"The number of weapon classes.")
297+
"The number of TVT/loadout teams with support rearm pools.")
324298
{
325-
return ade_set_args(L, "i", weapon_info_size());
299+
return ade_set_args(L, "i", MIN(Num_teams, MAX_TVT_TEAMS));
326300
}
327301

328302
//****SUBLIBRARY: Mission/Asteroids
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
//
3+
4+
#include "support_rearm_pool.h"
5+
6+
#include "mission/missionparse.h"
7+
#include "scripting/api/objs/weaponclass.h"
8+
#include "weapon/weapon.h"
9+
10+
namespace scripting::api {
11+
12+
//****HANDLE: support_rearm_pool_team
13+
ADE_OBJ(l_SupportRearmPoolTeam, int, "support_rearm_pool_team", "Support rearm pool team handle");
14+
15+
ADE_INDEXER(l_SupportRearmPoolTeam,
16+
"number/weaponclass IndexOrClass, number amount",
17+
"Gets/sets support rearm pool value for a weapon class on this team.\n"
18+
"Values: -1 = unlimited, 0 = unavailable, >0 = limited amount.\n"
19+
"If a weapon has $Disallow Support Rearm, this always returns 0 and ignores writes.",
20+
"number",
21+
"Current pool value for the weapon class.")
22+
{
23+
int team_idx = -1;
24+
int idx = -1;
25+
int amount;
26+
if (lua_isnumber(L, 2)) {
27+
if (!ade_get_args(L, "oi|i", l_SupportRearmPoolTeam.Get(&team_idx), &idx, &amount)) {
28+
return ADE_RETURN_NIL;
29+
}
30+
31+
if (idx < 1 || idx > weapon_info_size()) {
32+
return ADE_RETURN_NIL;
33+
}
34+
35+
idx--; // Lua to C++ index
36+
} else {
37+
if (!ade_get_args(L, "oo|i", l_SupportRearmPoolTeam.Get(&team_idx), l_Weaponclass.Get(&idx), &amount)) {
38+
return ADE_RETURN_NIL;
39+
}
40+
41+
if (idx < 0 || idx >= weapon_info_size()) {
42+
return ADE_RETURN_NIL;
43+
}
44+
}
45+
46+
if (team_idx < 0 || team_idx >= Num_teams || team_idx >= MAX_TVT_TEAMS) {
47+
return ADE_RETURN_NIL;
48+
}
49+
50+
if (ADE_SETTING_VAR) {
51+
if (!Weapon_info[idx].disallow_rearm) {
52+
if (amount < 0) {
53+
The_mission.support_ships.rearm_weapon_pool[team_idx][idx] = -1;
54+
} else {
55+
The_mission.support_ships.rearm_weapon_pool[team_idx][idx] = amount;
56+
}
57+
} else {
58+
The_mission.support_ships.rearm_weapon_pool[team_idx][idx] = 0;
59+
}
60+
}
61+
62+
if (Weapon_info[idx].disallow_rearm) {
63+
return ade_set_args(L, "i", 0);
64+
}
65+
66+
return ade_set_args(L, "i", The_mission.support_ships.rearm_weapon_pool[team_idx][idx]);
67+
}
68+
69+
ADE_FUNC(__len,
70+
l_SupportRearmPoolTeam,
71+
nullptr,
72+
"The number of weapon classes in this support rearm pool.",
73+
"number",
74+
"The number of weapon classes.")
75+
{
76+
return ade_set_args(L, "i", weapon_info_size());
77+
}
78+
79+
} // namespace scripting::api
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "globalincs/pstypes.h"
4+
5+
#include "scripting/ade.h"
6+
#include "scripting/ade_api.h"
7+
8+
namespace scripting::api {
9+
10+
DECLARE_ADE_OBJ(l_SupportRearmPoolTeam, int);
11+
12+
} // namespace scripting::api

0 commit comments

Comments
 (0)