Resource Generating Buildings

Article written by TriRem
Published on 03-18-2017; updated on 03-19-2017
Tags: Advanced Genie Editor, Building Modding, Data Modding

One of the major introductions of the African Kingdoms expansion is the Feitoria, a buildings that generates resources over time. This new ability was introduced only in the HD edition of the game but it is possible to mimic this ability fairly well in the CD version.

To sum up quickly it consists of creating a building with annex units that decay into themselves, giving the player a resource every time they decay.

Resource generating buildings

Contents

  • Resource Trickles
  • The main building
  • Ending loop
  • Head unit

Preparation

As usual, backup your files ! This is very important in case something goes wrong.

You will need Advanced Genie Editor 3 and a basic knowledge of this program, this guide should be enough.

Let's pretend for this test that I want a bank that generates one gold every two seconds.

Resource Trickles

First find the archer dead unit (ID 3) and duplicate it, rename it "Gold trickle", remove the graphics, set its Dead unit ID to itself. Now scroll down to resource storage, set the Corpse decay time amount to 2, in the boxes right nex to it add a new resource :
Type : 3 - Gold storage
Amount : 1
Enable Mode : 1

Add New Resource Storage

What we have created is a unit that decay in two seconds (ingame time) and gives 1 gold every time it is created. Since it dies into itself, we have a loop of one gold being created every two seconds.

To use it find the Outpost (ID 598) and make a duplicate unit (Copy, Add, Paste). Rename this new unit “Gold spawner”. (Also, change Language DLL Name and Creation boxes to -1.) In the duplicate unit, erase all the graphics (Construction, Snow, Standing, Dying, and all the Damage Graphics) and change the HP to -1. Now, change the Line of Sight to 0. Scroll down to the “Hide in Editor” box and check it. Next, go to the “Foundation Terrain” box and change it to -1 (None). Go down to the Collision Size, Clearance Size, and Selection Shape Size and change them all to 0. Now, change the “Selection Mask” to 2 (Which removes any outline on the building or any outlines on units behind it.) Change the “Train Location” to -1 and “Train Time” to 0. Finally, Scroll down to the sounds section and remove them all (It should only have Construction and Selection Sound.) We have now effectively made it impossible to tell this unit exists ingame. Set the "Gold trickle" unit as Dead unit.

This is a building that will immediatly die into our gold generator, initializing the loop.

You can do this process again for stone, food and wood if you want, each resource needing a trickle unit and a spawner.

The main building

We'll follow by creating the Bank building, by copying the barracks for example. Copy and paste the building, change its name to "Bank" and the graphics to your liking, it could use the Trade workshop graphics for example.

Scroll down until you find "Annex Units" boxes. In the first one put the ID of the "Gold spawner", you can fill the other three boxes with the other spawners for stone, food and wood.

Add Annex Units

Make sure your unit has box "hide in editor" unchecked, save your file and run the game. You can now place the Bank in the Editor and if you test it you will get one gold every two seconds, as expected.

We are done now then, right ? Not quite yet, if you try to delete your building you will notice that the resource loop doesn't stop. Now comes the really smart part.

Ending loop

The trick to end the loop was found by Vardamir, all credits go to him for this part.

We have a loop of dead units looping that we want to stop when the building is destroyed. One way to remove dead units is to place foundations over them.

Duplicate the barracks, rename this new unit “Bank_Dead”. (Also, change Language Dll Name and Creation boxes to -1.) In the duplicate unit, remove all the graphics except the dying Graphics and change the HP to 0. Now, change the Line of Sight to 0, scroll down to the “Hide in Editor” box and check it. Next, go to the “Foundation Terrain” box and change it to -1.

In the "Bank" unit remove the Dying Graphics, and change the Dead Unit to "Bank_Dead".

What happens is when the Bank is destroyed, it dies into a 0 HP building, which will place foundations for itself and die instantly into normal rubbles. When placing the foundations the loop of Resource trickles in ended by removing those units.

Now you can save and try it, the Bank stops working when destroyed.

You can just make the Bank unit buildable by a villager and we're done, follow this guide to do so, and when you try it ingame... it crashes every time you try to build it. We're not entirely done yet, there is one last thing to do.

Head Unit

As often when messing with Annex Units, we need a Head unit, a placeholder unit that we can build and then gets immediately replaced by the unit we want once built.

Duplicate the Barracks in the same way you did it for the Bank, give it the same name and graphics. Scroll down to the “Built : Vanishes” box and check it, as well as the "Hide in Editor" one.

Scroll until the "Stack unit" box and put the ID of the "Bank" (the one we created earlier). Make this unit buildable like any regular building.

Set Stack Unit

Then go to the "Bank" we first created, make it unbuildable by setting the train location to -1 and in the "Head Unit" box put the ID of the placeholder building we just created.

Make Bank Unbuildable

What happens when you try to build a Bank, the placeholder building is built and then removed when built to be replaced by the real Bank, the one with the Resource generation.

Conclusion

You now have a fully functioning buildable resource generating building, with one limitation however : if the bank is converted the resource generation will stay for the original player, and the building will be useless for the player that converted it.

I hope this article helped you, if there is any point that seems unclear to you feel free to ask me for more explanations.


Do you want to comment on this article? Thank the author? Tribute resources for its improvement? Raze it to the ground?

Come by and visit its thread in the University Forum!