Allow checking if give_item() will succeed
This commit is contained in:
@@ -447,33 +447,42 @@ bool cPlayer::give_item(cItem item, int flags) {
|
|||||||
bool do_print = flags & GIVE_DO_PRINT;
|
bool do_print = flags & GIVE_DO_PRINT;
|
||||||
bool allow_overload = flags & GIVE_ALLOW_OVERLOAD;
|
bool allow_overload = flags & GIVE_ALLOW_OVERLOAD;
|
||||||
int equip_type = flags & GIVE_EQUIP_FORCE;
|
int equip_type = flags & GIVE_EQUIP_FORCE;
|
||||||
|
bool check_only = flags & GIVE_CHECK_ONLY;
|
||||||
|
|
||||||
|
// If you passed both GIVE_DO_PRINT and GIVE_CHECK_ONLY for some reason,
|
||||||
|
// the buffer would lie to you and sounds would play.
|
||||||
|
if(check_only) do_print = false;
|
||||||
|
|
||||||
if(item.variety == eItemType::NO_ITEM)
|
if(item.variety == eItemType::NO_ITEM)
|
||||||
return true;
|
return true;
|
||||||
if(item.variety == eItemType::GOLD) {
|
if(item.variety == eItemType::GOLD) {
|
||||||
if(!party) return false;
|
if(!party) return false;
|
||||||
party->gold += item.item_level;
|
if(!check_only)
|
||||||
|
party->gold += item.item_level;
|
||||||
if(do_print && print_result)
|
if(do_print && print_result)
|
||||||
print_result("You get some gold.");
|
print_result("You get some gold.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(item.variety == eItemType::FOOD) {
|
if(item.variety == eItemType::FOOD) {
|
||||||
if(!party) return false;
|
if(!party) return false;
|
||||||
party->food += item.item_level;
|
if(!check_only)
|
||||||
|
party->food += item.item_level;
|
||||||
if(do_print && print_result)
|
if(do_print && print_result)
|
||||||
print_result("You get some food.");
|
print_result("You get some food.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(item.variety == eItemType::SPECIAL) {
|
if(item.variety == eItemType::SPECIAL) {
|
||||||
if(!party) return false;
|
if(!party) return false;
|
||||||
party->spec_items.insert(item.item_level);
|
if(!check_only)
|
||||||
|
party->spec_items.insert(item.item_level);
|
||||||
if(do_print && print_result)
|
if(do_print && print_result)
|
||||||
print_result("You get a special item.");
|
print_result("You get a special item.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(item.variety == eItemType::QUEST) {
|
if(item.variety == eItemType::QUEST) {
|
||||||
if(!party) return false;
|
if(!party) return false;
|
||||||
party->active_quests[item.item_level] = cJob(party->calc_day());
|
if(!check_only)
|
||||||
|
party->active_quests[item.item_level] = cJob(party->calc_day());
|
||||||
if(do_print && print_result)
|
if(do_print && print_result)
|
||||||
print_result("You get a quest.");
|
print_result("You get a quest.");
|
||||||
return true;
|
return true;
|
||||||
@@ -489,6 +498,8 @@ bool cPlayer::give_item(cItem item, int flags) {
|
|||||||
if(!free_space || main_status != eMainStatus::ALIVE)
|
if(!free_space || main_status != eMainStatus::ALIVE)
|
||||||
return false;
|
return false;
|
||||||
else {
|
else {
|
||||||
|
if(check_only) return true;
|
||||||
|
|
||||||
item.property = false;
|
item.property = false;
|
||||||
item.contained = false;
|
item.contained = false;
|
||||||
item.held = false;
|
item.held = false;
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ enum {
|
|||||||
// These three are mutually exclusive:
|
// These three are mutually exclusive:
|
||||||
GIVE_EQUIP_SOFT = 4,
|
GIVE_EQUIP_SOFT = 4,
|
||||||
GIVE_EQUIP_TRY = 8,
|
GIVE_EQUIP_TRY = 8,
|
||||||
GIVE_EQUIP_FORCE = 12,
|
GIVE_EQUIP_FORCE = GIVE_EQUIP_SOFT | GIVE_EQUIP_TRY,
|
||||||
|
// Do a dry run to see if the PC can receive it.
|
||||||
|
GIVE_CHECK_ONLY = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
class cParty;
|
class cParty;
|
||||||
|
|||||||
Reference in New Issue
Block a user