@@ -1983,7 +1983,7 @@ void parse_ship_particle_effect(ship_info* sip, particle_effect* pe, char *id_st
19831983 }
19841984}
19851985
1986- void parse_allowed_weapons(ship_info *sip, bool is_primary, bool is_dogfight)
1986+ void parse_allowed_weapons(ship_info *sip, const bool is_primary, const bool is_dogfight, const bool first_time )
19871987{
19881988 int i, num_allowed;
19891989 int allowed_weapons[MAX_WEAPON_TYPES];
@@ -2000,6 +2000,17 @@ void parse_allowed_weapons(ship_info *sip, bool is_primary, bool is_dogfight)
20002000 // Set the weapons filter used in weapons loadout (for primary weapons)
20012001 if (optional_string(allowed_banks_str))
20022002 {
2003+ // MageKing17 - We need to make modular tables replace bank restrictions by default, instead of adding to them.
2004+ if (!first_time && !(optional_string("+noreplace"))) { // Only makes sense for modular tables.
2005+ // clear allowed weapons so the modular table can define new ones
2006+ for (bank = 0; bank < max_banks; bank++) {
2007+ for (i = 0; i < Num_weapon_types; i++) {
2008+ sip->allowed_bank_restricted_weapons[offset+bank][i] &= ~weapon_type;
2009+ }
2010+ sip->restricted_loadout_flag[offset+bank] &= ~weapon_type;
2011+ }
2012+ }
2013+
20032014 bank = -1;
20042015
20052016 while (check_for_string("("))
@@ -3019,8 +3030,8 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t
30193030 }
30203031
30213032 // Set the weapons filter used in weapons loadout (for primary weapons)
3022- parse_allowed_weapons(sip, true, false);
3023- parse_allowed_weapons(sip, true, true);
3033+ parse_allowed_weapons(sip, true, false, first_time );
3034+ parse_allowed_weapons(sip, true, true, first_time );
30243035
30253036 // Get primary bank weapons
30263037 parse_weapon_bank(sip, true, &sip->num_primary_banks, sip->primary_bank_weapons, sip->primary_bank_ammo_capacity);
@@ -3032,8 +3043,8 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t
30323043 }
30333044
30343045 // Set the weapons filter used in weapons loadout (for secondary weapons)
3035- parse_allowed_weapons(sip, false, false);
3036- parse_allowed_weapons(sip, false, true);
3046+ parse_allowed_weapons(sip, false, false, first_time );
3047+ parse_allowed_weapons(sip, false, true, first_time );
30373048
30383049 // Get secondary bank weapons
30393050 parse_weapon_bank(sip, false, &sip->num_secondary_banks, sip->secondary_bank_weapons, sip->secondary_bank_ammo_capacity);
@@ -3295,10 +3306,12 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t
32953306 Error(LOCATION, "%s '%s' has too many primary banks (%d). Maximum for ships is currently %d.\n", info_type_name, sip->name, sip->num_primary_banks, MAX_SHIP_PRIMARY_BANKS);
32963307 }
32973308
3309+ memset(sip->allowed_weapons, 0, sizeof(int) * MAX_WEAPON_TYPES);
3310+
32983311 // copy to regular allowed_weapons array
3299- for (i= 0; i< MAX_SHIP_WEAPONS; i++)
3312+ for (i = 0; i < MAX_SHIP_WEAPONS; i++)
33003313 {
3301- for (j= 0; j<MAX_WEAPON_TYPES ; j++)
3314+ for (j = 0; j < Num_weapon_types ; j++)
33023315 {
33033316 if (sip->allowed_bank_restricted_weapons[i][j] & REGULAR_WEAPON)
33043317 sip->allowed_weapons[j] |= REGULAR_WEAPON;
@@ -3308,10 +3321,12 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t
33083321 }
33093322 }
33103323
3324+ sip->flags &= ~SIF_BALLISTIC_PRIMARIES;
3325+
33113326 //Set ship ballistic flag if necessary
3312- for (i= 0; i< MAX_SHIP_PRIMARY_BANKS; i++)
3327+ for (i = 0; i < MAX_SHIP_PRIMARY_BANKS; i++)
33133328 {
3314- for (j= 0; j<MAX_WEAPON_TYPES ; j++)
3329+ for (j = 0; j < Num_weapon_types ; j++)
33153330 {
33163331 if(sip->allowed_bank_restricted_weapons[i][j] && (Weapon_info[j].wi_flags2 & WIF2_BALLISTIC))
33173332 {
0 commit comments