Skip to content

Commit

Permalink
Implements "Give Credits To House" trigger action.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Jun 13, 2021
1 parent 1efffb6 commit 66fe847
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/extensions/taction/tactionext_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/extensions/taction/tactionext_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
17 changes: 17 additions & 0 deletions src/extensions/taction/tactionext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<invalid>";
}
Expand All @@ -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 "<invalid>";
}
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions src/vinifera_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 66fe847

Please sign in to comment.