diff --git a/src/extensions/taction/tactionext_functions.cpp b/src/extensions/taction/tactionext_functions.cpp index 7ad494341..008855ee2 100644 --- a/src/extensions/taction/tactionext_functions.cpp +++ b/src/extensions/taction/tactionext_functions.cpp @@ -67,3 +67,39 @@ bool TAction_Give_Credits(TActionClass *taction, HouseClass *house, ObjectClass return true; } + + +/** + * #issue-158 + * + * Give credits to the specified house. + * + * @author: CCHyper + */ +bool TAction_Give_Credits_To_House(TActionClass *taction, HouseClass *house, ObjectClass *object, TriggerClass *trigger, Cell *cell) +{ + if (!taction || !house) { + return false; + } + + int amount = taction->Data.Value; + + /** + * We use "Bounds.X" as the second argument, its where the house index is stored. + */ + HouseClass *hptr = HouseClass::As_Pointer(HousesType(taction->Bounds.X)); + + /** + * If positive, grant the cash bonus. + * If negative, take money from the house. + */ + if (amount != 0) { + if (amount < 0) { + hptr->Spend_Money(std::abs(amount)); + } else { + hptr->Refund_Money(amount); + } + } + + return true; +} diff --git a/src/extensions/taction/tactionext_functions.h b/src/extensions/taction/tactionext_functions.h index 4b7cd21e6..2a4dacbdc 100644 --- a/src/extensions/taction/tactionext_functions.h +++ b/src/extensions/taction/tactionext_functions.h @@ -38,3 +38,4 @@ class TriggerClass; bool TAction_Give_Credits(TActionClass *taction, HouseClass *house, ObjectClass *object, TriggerClass *trigger, Cell *cell); +bool TAction_Give_Credits_To_House(TActionClass *taction, HouseClass *house, ObjectClass *object, TriggerClass *trigger, Cell *cell); diff --git a/src/extensions/taction/tactionext_hooks.cpp b/src/extensions/taction/tactionext_hooks.cpp index bbc04b6e4..1cb570351 100644 --- a/src/extensions/taction/tactionext_hooks.cpp +++ b/src/extensions/taction/tactionext_hooks.cpp @@ -59,6 +59,9 @@ static const char *TActionClass_New_Action_Name(int action) case TACTION_CREDITS: return "Give credits..."; + case TACTION_CREDITS_HOUSE: + return "Give credits to house..."; + default: return ""; } @@ -81,6 +84,9 @@ static const char *TActionClass_New_Action_Description(int action) case TACTION_CREDITS: return "Gives credits to the owner of the trigger."; + case TACTION_CREDITS_HOUSE: + return "Gives credits to the specified house."; + default: return ""; } @@ -151,6 +157,17 @@ DECLARE_PATCH(_TAction_Operator_Extend_Switch_Patch) success = TAction_Give_Credits(this_ptr, house, object, trigger, cell); break; + /** + * #issue-158 + * + * Gives credits to the specified house. + * + * @author: CCHyper + */ + case TACTION_CREDITS_HOUSE: + success = TAction_Give_Credits_To_House(this_ptr, house, object, trigger, cell); + break; + /** * Unexpected TActionType. */ diff --git a/src/vinifera_defines.h b/src/vinifera_defines.h index aa9a32082..3f1e39023 100644 --- a/src/vinifera_defines.h +++ b/src/vinifera_defines.h @@ -43,6 +43,7 @@ typedef enum NewTActionType */ TACTION_CREDITS, // Gives credits to the owner of the trigger. + TACTION_CREDITS_HOUSE, // Gives credits to the specified house. /** * The new total TActionType count.