[Solved] Tax Reform Upgrade

Level 3
Joined
Apr 20, 2021
Messages
19
I made a trigger that makes it so that for every House that you build, you earn 100 gold every 30 seconds.

  • Red House
    • Events
      • Unit - A unit owned by Player 1 (Red) Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to House
    • Actions
      • Set Red_Income = (Red_Income + Red_Tax_Constant)

  • Red Income
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Player - Add Red_Income to Player 1 (Red) Current gold

I also made a trigger that makes it so that for every House destroyed, it deducts your income by 100 gold. This makes it impossible to get any income when you have no Houses built nor do you suffer any sort of loss because of an income deficit. This system works flawlessly.

  • Red House Destroyed
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to House
    • Actions
      • Set Red_Income = (Red_Income - Red_Tax_Constant)

But I want to create an upgrade that gives you an additional 50 gold income for every House that you currently own and plan to build (from an initial 100 gold to 150 gold per house). Cue the Tax Reform upgrade which is supposed to do just that. But sadly I do not know how to implement this. The current attempt makes it so that once you researched Tax Reform, the formula of the income changes - adding a new Tax Reform value (which is 50).

  • Red Tax Reforms
    • Events
      • Unit - A unit owned by Player 1 (Red) Finishes research
    • Conditions
      • (Researched tech-type) Equal to Tax Reforms [Level - 1]
    • Actions
      • Set Red_Income = ((Red_Income + Tax_Reforms) + Red_Tax_Constant)

This is flawed due to the fact that destroying all of your Houses somehow gives you an income of 100 gold still. Can anyone help me come out with a solution?
 

Ralle

Owner
Level 68
Joined
Oct 6, 2004
Messages
9,545
1. You need to learn about arrays. Arrays can make it so you have a "Player House Dies" instead of one per player. You can basically say:
  • Set Income[Player Number of Owner of Triggering Unit] = Income[Player Number of Owner of Triggering Unit] + Constant
Which will cut down on the triggers.

2. You have to check whether the player has finished research. One way would be to create a boolean for (has researched tax reform or not) so if that value is true, it deducts 150 instead of just 100.
 
Level 18
Joined
Feb 23, 2014
Messages
1,185
If I understood correctly, the upgrade permanently increases the amount of gold you get per House, right? For instance, if you have 5 Houses - you should get 5x100 gold every 30 seconds if the upgrade isn't researched and 5x150 gold every 30 seconds after it's researched?

If that's the case then:
  • Red_Tax_Constant, i.e. the value that is added/removed from your income when a House is built/destroyed should change from 100 to 150.
  • Current income should be adjusted to reflect the increased value of a single House.
Your triggers achieve neither of these two goals and instead add a flat 150 gold to the player's income for some reason. I don't understand why, so maybe I just didn't get what you're trying to do, but if I'm right - the Actions part of your research trigger should look like this:

  • Actions
    • Set Red_Income = (Red_Income + ((Red_Income / Red_Tax_Constant) * Tax_Reforms))
    • Set Red_Tax_Constant = (Red_Tax_Constant + Tax_Reforms)

---

That said, I'd like to suggest a different approach - instead of calculating the income, count the amount of active Houses. Do the same thing you've been doing, but use an integer variable and add 1 each time a House is constructed and deduct 1 each time a House is destroyed.

I called this variable "Red_Count" - as it stores the amount of Houses a player has, all you have to do to get the income is multiply it by the income rate:
  • Player - Add (Red_Count x Red_Tax_Constant) to Player 1 (Red) Current gold

The action above accounts only for the basic income (i.e. without checking for the upgrade) - to account for the upgrade, do this:
  • Player - Add (Red_Count x (Red_Tax_Constant + (Tax_Reforms x (Current research level of <your upgrade> for Player 1 (Red))))) to Player 1 (Red) Current gold

Let's use numbers - a player has build 6 Houses and 1 House was destroyed. Base income rate is 100 and it's meant to be increased by 50 when the upgrade is researched. In such case Red_Count will be equal to 5, Red_Tax_Constant equal to 100 and Tax_Reforms equal to 50. As a result:
  • If the upgrade wasn't researched, the research level is 0 and so we get: 5 x (100 + (50 x 0)) = 5 x 100 = 500 gold.
  • If the upgrade was researched, the research level is 1 and we so we get: 5 x (100 + (50 x 1)) = 5 x (100 + 50) = 5 x 150 = 750 gold.
  • If you don't have any Houses, the equation will always result in 0 as both 0 x 100 and 0 x 150 is equal to 0.
If I understood your intentions correctly, then this action should do exactly what you want and without needing a separate trigger for the research.
 
Last edited:
Level 3
Joined
Apr 20, 2021
Messages
19
1. You need to learn about arrays. Arrays can make it so you have a "Player House Dies" instead of one per player. You can basically say:
  • Set Income[Player Number of Owner of Triggering Unit] = Income[Player Number of Owner of Triggering Unit] + Constant
Which will cut down on the triggers.

2. You have to check whether the player has finished research. One way would be to create a boolean for (has researched tax reform or not) so if that value is true, it deducts 150 instead of just 100.

I didn't know about this. I'll definitely be experimenting more with arrays, their function, and how to use the said function. Thank you for the help!

If I understood correctly, the upgrade permanently increases the amount of gold you get per House, right? For instance, if you have 5 Houses - you should get 5x100 gold every 30 seconds if the upgrade isn't researched and 5x150 gold every 30 seconds after it's researched?

If that's the case then:
  • Red_Tax_Constant, i.e. the value that is added/removed from your income when a House is built/destroyed should change from 100 to 150.
  • Current income should be adjusted to reflect the increased value of a single House.
Your triggers achieve neither of these two goals and instead add a flat 150 gold to the player's income for some reason. I don't understand why, so maybe I just didn't get what you're trying to do, but if I'm right - the Actions part of your research trigger should look like this:

  • Actions
    • Set Red_Income = (Red_Income + ((Red_Income / Red_Tax_Constant) * Tax_Reforms))
    • Set Red_Tax_Constant = (Red_Tax_Constant + Tax_Reforms)

---

That said, I'd like to suggest a different approach - instead of calculating the income, count the amount of active Houses. Do the same thing you've been doing, but use an integer variable and add 1 each time a House is constructed and deduct 1 each time a House is destroyed.

I called this variable "Red_Count" - as it stores the amount of Houses a player has, all you have to do to get the income is multiply it by the income rate:
  • Player - Add (Red_Count x Red_Tax_Constant) to Player 1 (Red) Current gold

The action above accounts only for the basic income (i.e. without checking for the upgrade) - to account for the upgrade, do this:
  • Player - Add (Red_Count x (Red_Tax_Constant + (Tax_Reforms x (Current research level of <your upgrade> for Player 1 (Red))))) to Player 1 (Red) Current gold

Let's use numbers - a player has build 6 Houses and 1 House was destroyed. Base income rate is 100 and it's meant to be increased by 50 when the upgrade is researched. In such case Red_Count will be equal to 5, Red_Tax_Constant equal to 100 and Tax_Reforms equal to 50. As a result:
  • If the upgrade wasn't researched, the research level is 0 and so we get: 5 x (100 + (50 x 0)) = 5 x 100 = 500 gold.
  • If the upgrade was researched, the research level is 1 and we so we get: 5 x (100 + (50 x 1)) = 5 x (100 + 50) = 5 x 150 = 750 gold.
  • If you don't have any Houses, the equation will always result in 0 as both 0 x 100 and 0 x 150 is equal to 0.
If I understood your intentions correctly, then this action should do exactly what you want and without needing a separate trigger for the research.

This has been an INCREDIBLE help! To keep improving my Trigger Editing skills, I promise to not only copy the trigger that you have given but rather study and hopefully improve upon it as well. Many thanks for pushing me on the right track!
 
Level 18
Joined
Feb 23, 2014
Messages
1,185
This has been an INCREDIBLE help! To keep improving my Trigger Editing skills, I promise to not only copy the trigger that you have given but rather study and hopefully improve upon it as well. Many thanks for pushing me on the right track!
Thank you for the kind words! I'm happy to help :) It's nice to see that you're interested in learning - that's a really good approach to have. If there's one tip I can give you - don't be afraid to experiment. Oh, and do check out arrays as @Ralle suggested - they're super helpful in a lot of cases.
 
Top