ok, I'm realy realy sure I fixed it
int wl_swap_slot_slot(int from_bank, int to_bank, int ship_slot, int *sound)
{
wss_unit *slot;
slot = &Wss_slots[ship_slot];
if ( slot->ship_class == -1 ) {
Int3(); // should not be possible
return 0;
}
// do nothing if swapping with self
if ( from_bank == to_bank ) {
*sound=SND_ICON_DROP_ON_WING;
return 0; // no update
}
// ensure that source bank exists and has something to pick from
if ( slot->wep[from_bank] == -1 || slot->wep_count[from_bank] <= 0 ) {
return 0;
}
// ensure that the dest bank exists
if ( slot->wep_count[to_bank] < 0 ) {
return 0;
}
int tobank = to_bank, frombank = from_bank;
if(IS_BANK_SECONDARY(tobank))tobank -= 3;
if(IS_BANK_SECONDARY(frombank))frombank -=3;
//ensure that the two banks are both compatable types-Bobboau
if(!weapon_allowed_for_game_type(Ship_info[slot->ship_class].allowed_weapons[slot->wep[from_bank]][tobank])){
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "A %s can not carry %s weaponry in bank %d", Ship_info[slot->ship_class].name, Weapon_info[slot->wep[from_bank]].name, tobank+1);
return 0;
}
if(!weapon_allowed_for_game_type(Ship_info[slot->ship_class].allowed_weapons[slot->wep[to_bank]][frombank])){
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "A %s can not carry %s weaponry in bank %d", Ship_info[slot->ship_class].name, Weapon_info[slot->wep[to_bank]].name, frombank+1);
return 0;
}
//Warning(LOCATION,"slot slot");
// ensure that the banks are both of the same class
if ( (IS_BANK_PRIMARY(from_bank) && IS_BANK_SECONDARY(to_bank)) || (IS_BANK_SECONDARY(from_bank) && IS_BANK_PRIMARY(to_bank)) ) {
// put from_bank back into list
Wl_pool[slot->wep[from_bank]] += slot->wep_count[from_bank];; // return to list
slot->wep[from_bank] = -1; // remove from slot
slot->wep_count[from_bank] = 0;
*sound=SND_ICON_DROP;
return 1;
}
// case 1: primaries (easy, even with ballistics, because ammo is always maximized)
if ( IS_BANK_PRIMARY(from_bank) && IS_BANK_PRIMARY(to_bank) )
{
wl_swap_weapons(ship_slot, from_bank, to_bank);
*sound=SND_ICON_DROP_ON_WING;
return 1;
}
// case 2: secondaries (harder)
if ( IS_BANK_SECONDARY(from_bank) && IS_BANK_SECONDARY(to_bank) )
{
// case 2a: secondaries are the same type
if ( slot->wep[from_bank] == slot->wep[to_bank] ) {
int dest_max, dest_can_fit, source_can_give;
dest_max = wl_calc_missile_fit(slot->wep[to_bank], Ship_info[slot->ship_class].secondary_bank_ammo_capacity[to_bank-3]);
dest_can_fit = dest_max - slot->wep_count[to_bank];
if ( dest_can_fit <= 0 ) {
// dest bank is already full.. nothing to do here
return 0;
}
// see how much source can give
source_can_give = min(dest_can_fit, slot->wep_count[from_bank]);
if ( source_can_give > 0 ) {
slot->wep_count[to_bank] += source_can_give; // add to dest
slot->wep_count[from_bank] -= source_can_give; // take from source
*sound=SND_ICON_DROP_ON_WING;
return 1;
} else {
return 0;
}
}
// case 2b: secondaries are different types
if ( slot->wep[from_bank] != slot->wep[to_bank] )
{
// swap 'em
wl_swap_weapons(ship_slot, from_bank, to_bank);
// put back some on list if required
wl_saturate_bank(ship_slot, from_bank);
wl_saturate_bank(ship_slot, to_bank);
*sound=SND_ICON_DROP_ON_WING;
return 1;
}
}
Int3(); // should never get here
return 0;
}
// exit: 0 -> no data changed
// 1 -> data changed
// sound => gets filled with sound id to play
int wl_dump_to_list(int from_bank, int to_list, int ship_slot, int *sound)
{
wss_unit *slot;
slot = &Wss_slots[ship_slot];
// ensure that source bank exists and has something to pick from
if ( slot->wep[from_bank] == -1 || slot->wep_count[from_bank] <= 0 ) {
return 0;
}
// put weapon bank to the list
Wl_pool[to_list] += slot->wep_count[from_bank]; // return to list
slot->wep[from_bank] = -1; // remove from slot
slot->wep_count[from_bank] = 0;
*sound=SND_ICON_DROP;
return 1;
}
// exit: 0 -> no data changed
// 1 -> data changed
// sound => gets filled with sound id to play
int wl_grab_from_list(int from_list, int to_bank, int ship_slot, int *sound)
{
wss_unit *slot;
slot = &Wss_slots[ship_slot];
int max_fit;
// ensure that the banks are both of the same class
if ( (IS_LIST_PRIMARY(from_list) && IS_BANK_SECONDARY(to_bank)) || (IS_LIST_SECONDARY(from_list) && IS_BANK_PRIMARY(to_bank)) )
{
// do nothing
*sound=SND_ICON_DROP;
return 0;
}
// ensure that dest bank exists
if ( slot->wep_count[to_bank] < 0 ) {
*sound=SND_ICON_DROP;
return 0;
}
// bank should be empty:
Assert(slot->wep_count[to_bank] == 0);
Assert(slot->wep[to_bank] < 0);
// ensure that pool has weapon
if ( Wl_pool[from_list] <= 0 ) {
return 0;
}
int tobank = to_bank;
if(IS_BANK_SECONDARY(tobank))tobank -= 3;
//ensure that this bank can have this weapon-Bobboau
if(!weapon_allowed_for_game_type(Ship_info[slot->ship_class].allowed_weapons[Carried_wl_icon.weapon_class][tobank])){
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "A %s can not carry %s weaponry in bank %d", Ship_info[slot->ship_class].name, Weapon_info[Carried_wl_icon.weapon_class].name, tobank+1);
return 0;
}
//Warning(LOCATION,"list");
// find how much dest bank can fit
if ( to_bank < MAX_WL_PRIMARY )
{
max_fit = 1;
}
else
{
max_fit = wl_calc_missile_fit(from_list, Ship_info[slot->ship_class].secondary_bank_ammo_capacity[to_bank-MAX_WL_PRIMARY]);
}
// take weapon from list
if ( Wl_pool[from_list] < max_fit ) {
max_fit = Wl_pool[from_list];
}
Wl_pool[from_list] -= max_fit;
// put on the slot
slot->wep[to_bank] = from_list;
slot->wep_count[to_bank] = max_fit;
*sound=SND_ICON_DROP_ON_WING;
return 1;
}
// exit: 0 -> no data changed
// 1 -> data changed
// sound => gets filled with sound id to play
int wl_swap_list_slot(int from_list, int to_bank, int ship_slot, int *sound)
{
wss_unit *slot;
slot = &Wss_slots[ship_slot];
int max_fit;
// ensure that the banks are both of the same class
if ( (IS_LIST_PRIMARY(from_list) && IS_BANK_SECONDARY(to_bank)) || (IS_LIST_SECONDARY(from_list) && IS_BANK_PRIMARY(to_bank)) ) {
// do nothing
*sound=SND_ICON_DROP;
return 0;
}
// ensure that dest bank exists
if ( slot->wep_count[to_bank] < 0 ) {
return 0;
}
// bank should have something in it
Assert(slot->wep_count[to_bank] > 0);
Assert(slot->wep[to_bank] >= 0);
// ensure that pool has weapon
if ( Wl_pool[from_list] <= 0 ) {
return 0;
}
//ensure that this bank can have this weapon-Bobboau
int tobank = to_bank;
if(IS_BANK_SECONDARY(tobank))tobank -= 3;
if(!weapon_allowed_for_game_type(Ship_info[slot->ship_class].allowed_weapons[Carried_wl_icon.weapon_class][tobank])){
popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, "A %s can not carry %s weaponry in bank %d", Ship_info[slot->ship_class].name, Weapon_info[Carried_wl_icon.weapon_class].name, tobank+1);
return 0;
}
//Warning(LOCATION,"list slot");
// dump slot weapon back into list
Wl_pool[slot->wep[to_bank]] += slot->wep_count[to_bank];
slot->wep_count[to_bank] = 0;
slot->wep[to_bank] = -1;
// put weapon on ship from list
// find how much dest bank can fit
if ( to_bank < MAX_WL_PRIMARY )
{
max_fit = 1;
}
else
{
max_fit = wl_calc_missile_fit(from_list, Ship_info[slot->ship_class].secondary_bank_ammo_capacity[to_bank-MAX_WL_PRIMARY]);
}
// take weapon from list
if ( Wl_pool[from_list] < max_fit ) {
max_fit = Wl_pool[from_list];
}
Wl_pool[from_list] -= max_fit;
// put on the slot
slot->wep[to_bank] = from_list;
slot->wep_count[to_bank] = max_fit;
*sound=SND_ICON_DROP_ON_WING;
return 1;
}
that is code from MissionUI/MissionWeaponChoice.cpp for four functions (one of wich (wl_dump_to_list) I did nothing to, but it was inbetween the others) this version of the code should work, I had forgoten that secondary banks are banknum - num_of_primary_banks
I'm not sure if I have other suprizes in my current code so I probly shouldn't commit it for fixing 3.5