diff options
Diffstat (limited to 'src/map/trade.cpp')
-rw-r--r-- | src/map/trade.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/map/trade.cpp b/src/map/trade.cpp index c52377d..c03609c 100644 --- a/src/map/trade.cpp +++ b/src/map/trade.cpp @@ -25,7 +25,9 @@ #include "../io/cxxstdio.hpp" #include "battle.hpp" +#include "battle_conf.hpp" #include "clif.hpp" +#include "globals.hpp" #include "itemdb.hpp" #include "map.hpp" #include "npc.hpp" @@ -37,6 +39,8 @@ namespace tmwa { +namespace map +{ /*========================================== * 取引要請を相手に送る *------------------------------------------ @@ -129,7 +133,6 @@ void trade_tradeack(dumb_ptr<map_session_data> sd, int type) void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount) { dumb_ptr<map_session_data> target_sd; - struct item_data *id; int trade_i; int trade_weight = 0; int free_ = 0; @@ -156,7 +159,7 @@ void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount) for (IOff0 i : IOff0::iter()) { if (!target_sd->status.inventory[i].nameid - && target_sd->inventory_data[i] == nullptr) + && target_sd->inventory_data[i].is_none()) free_++; } for (trade_i = 0; trade_i < TRADE_MAX; trade_i++) @@ -164,26 +167,31 @@ void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount) if (sd->deal_item_amount[trade_i] == 0) { // calculate trade weight + // note: 'abort' branch is protected by 'amount' check above trade_weight += - sd->inventory_data[index.unshift()]->weight * amount; + TRY_UNWRAP(sd->inventory_data[index.unshift()], abort())->weight * amount; // determine if item is a stackable already in receivers inventory, and up free count for (IOff0 i : IOff0::iter()) { - if (target_sd->status.inventory[i].nameid == - sd->status.inventory[index.unshift()].nameid - && target_sd->inventory_data[i] != nullptr) + if (target_sd->status.inventory[i].nameid != + sd->status.inventory[index.unshift()].nameid) + continue; + + OMATCH_BEGIN_SOME (id, target_sd->inventory_data[i]) { - id = target_sd->inventory_data[i]; if (id->type != ItemType::WEAPON && id->type != ItemType::ARMOR && id->type != ItemType::_7 && id->type != ItemType::_8) { free_++; - break; + goto break_outer1; } } + OMATCH_END (); + break_outer1: + break; } if (target_sd->weight + trade_weight > @@ -218,28 +226,32 @@ void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount) else { // calculate weight for stored deal + // note: 'abort' branch is protected by 'amount' check above trade_weight += - sd->inventory_data[sd->deal_item_index[trade_i].unshift() - ]->weight * + TRY_UNWRAP(sd->inventory_data[sd->deal_item_index[trade_i].unshift() + ], abort())->weight * sd->deal_item_amount[trade_i]; // count free stackables in stored deal for (IOff0 i : IOff0::iter()) { - if (target_sd->status.inventory[i].nameid == + if (target_sd->status.inventory[i].nameid != sd->status. - inventory[sd->deal_item_index[trade_i].unshift()].nameid - && target_sd->inventory_data[i] != nullptr) + inventory[sd->deal_item_index[trade_i].unshift()].nameid) + continue; + OMATCH_BEGIN_SOME (id, target_sd->inventory_data[i]) { - id = target_sd->inventory_data[i]; if (id->type != ItemType::WEAPON && id->type != ItemType::ARMOR && id->type != ItemType::_7 && id->type != ItemType::_8) { free_++; - break; + goto break_outer2; } } + OMATCH_END (); + break_outer2: + break; } } // used a slot, but might be cancelled out by stackable checks above @@ -465,4 +477,5 @@ void trade_verifyzeny(dumb_ptr<map_session_data> sd) } } } +} // namespace map } // namespace tmwa |