Motivation
Many other real time strategy games use additional resource types. For example, Warcraft II had the additional resource type Oil and games like Age of Empires have even more different resource types. There is already several systems to support custom resources in Warcraft III. However, I wanted a very specific kind of system for my own map which uses units instead of destructibles as mines and emulates the behavior of Warcraft II for Oil which includes the harvest bonus after building an Oil Refinery. Other systems do not necessarily show the amount of harvested resources on workers or the amount on mines. This system provides all of these features.
Usage
Use the folder "Resources" from the triggers of the example map in your own map.
Libraries for the multiboard, GUI, costs, warnings and chat commands can simply be disabled.
They are all optional if you use this system.
Use the following code to register a custom resource:
JASS:
globals
Resource Oil
endglobals
...
set Oil = AddResource("Oil")
call SetResourceGoldExchangeRate(Oil, 2.0)
call SetResourceIcon(Oil, "ReplaceableTextures\\CommandButtons\\BTNOil.blp")
call SetResourceIconAtt(Oil, "ReplaceableTextures\\ATTOil.blp")
call SetResourceColorRed(Oil, 50)
call SetResourceColorGreen(Oil, 50)
call SetResourceColorBlue(Oil, 50)
The name is used in GUIs/multiboards.
The gold exchange rate is used when selling/buying Oil for example with chat commands.
The icons are used in GUIs/multiboards.
The colors are used for the floating texts which appear when you harvest the resource.
Use the following code to add warnings for a resource:
JASS:
call SetNotEnoughResourcesSoundForAllPlayers(Oil, gg_snd_GruntNoOil1)
call SetResourceLowValue(Oil, 1500)
call SetLowResourcesSoundForAllPlayers(Oil, gg_snd_GruntOilPlatformLow1)
call SetLowResourcesMessageForAllPlayers(Oil, "Our Oil Platform is running low.")
call SetCollapsedResourcesSoundForAllPlayers(Oil, gg_snd_GruntOilPlatformCollapsed1)
call SetCollapsedResourcesMessageForAllPlayers(Oil, "Our Oil Platform has collapsed.")
The sounds are played for the player and all of the allies with shared unit control when you have not enough of the resource or your mines are running low or collapsed.
The low value determines when a mine is running low.
You can also set this per player for example when players have different races.
Use functions like SetNotEnoughResourcesSound and SetLowResourcesSound without the ForAllPlayers suffix to specify it per player.
Use the following code to register costs:
JASS:
call SetCosts('obot', Oil, 700)
call SetCosts('bspd', Oil, 200)
call SetResearchCostsForLevel('R000', 0, Oil, 1000)
call SetResearchCostsForLevel('R000', 1, Oil, 3000)
call SetAbilityCosts('A009', Oil, 150)
SetCosts can be used for units and items.
You can use SetResearchCosts without specifying the level instead of SetResearchCostsForLevel if your research has only one level.
SetAbilityCosts uses level 1 by default. You can use SetAbilityCostsForLevel if you want to specify the ability level.
Use the following code to add a worker:
JASS:
call AddWorker(worker)
call AddResourceToWorker(worker, Oil, 'A000', "harvest", 'A001', "roar", 'A004', "robogoblin", 100, 100, "gold")
AddResourceToWorker can be used to register any resources to the worker (multiple if you want to).
A000 is the harvest ability and "harvest" is the harvest order.
A001 is the return resources ability (without target) and "roar" is the return resources order (without target).
A004 is the hidden return resources ability (with target) and "robogoblin" is the hidden resources ability (with target).
"gold" is the animation property for the worker while carrying Oil.
The first 100 is the maximum amount of Oil which can be carried by the worker.
The second 100 is the amount of Oil which the worker gets from one gathering "hit".
The harvest and return abilities can be based on the Channel ability. Just look at the object data of the example map.
Use the following code to add a mine:
JASS:
call AddMineEx(mine, Oil, 20000)
It adds a mine only for Oil with 20 000 Oil in it.
You can add mines which allow to have exactly 1 worker inside (like Warcraft III gold mines) with this code:
JASS:
call SetMineTakeWorkerInside(mine, true)
call SetMineMaxWorkers(mine, 1)
It is recommended to give workers some harvest duration inside mines:
JASS:
call SetUnitHarvestDuration(worker, Oil, 2.0)
You can add return buildings with the following code:
JASS:
call AddReturnBuilding(whichUnit)
call AddUnitReturnResource(whichUnit, Oil)
You can add multiple return resources.
A shorter way to add a return building for only one resource is:
JASS:
call AddReturnBuildingEx(whichUnit, Oil)
Loaded mines can be added like this:
JASS:
call AddLoadedMine(mine, Oil, 50000, 10)
call AddLoadedMineWorkerUnitTypeId(mine, 'o006')
call AddLoadedMineWorkerUnitTypeId(mine, 'o007')
This will add a loaded mine with 50 000 Oil in it. For each worker inside you will get 10 Oil every 3 seconds. The interval is global for all loaded mines and can be modified in the library ResourcesLoadedMines.
Only the added worker unit types are allowed to be loaded into the mine.
Use Warcraft's cargo/load/unload abilities for the loaded mine building.
Example map
The example map has two Orc players: Yourself and your allied blue player with shared unit control
It contains the custom resources Oil, Rock and Wheat.
It uses Oil Platforms like in Warcraft II where Oil Tankers disappear inside the Oil Platforms to harvest (like Warcraft III gold mines).
Custom resources costs are written down in tooltips.
Return buildings like Oil Refineries give a harvesting bonus to the player.
Wheat has the same upkeep levels as gold.
Oil and Rock have no upkeep levels.
You have shared unit control with blue and see/hear all of the messages related to custom resources.
Use the chat command "-hr" to list all available chat commands.
You can use chat commands like "-ask 5000 oil blue" to receive 500 Oil from blue or "-give 5000 oil blue" to give blue 5000 Oil.
Asking works with all allied Computer players.
The building Trading Post allows buying/selling custom resources instead of using chat commands.
Rock Mine Shafts can be built on top of Rock Mines and be used as loaded mines similar to the Entangled Mines of Night Elf.
Features
- Add almost any number of custom resources. The limit is only given by JASS and vJass limits and by the number of columns in multiboards/your map.
- Taxes per player like for gold in Warcraft III.
- Automatic orders after constructing return buildings like lumber mills to return carried resources and find a new mine.
- Rally point support: Automatic ordering to mines targeted by rally points.
- Disabled unit pathing for harvesting workers like in Warcraft III to avoid blocking each other.
- Mines disappearing workers inside and a maximum number of workers inside.
- Player resources multiboard.
- Team resources multiboard.
- Shared unit control support: Error messages and sounds are seen and heard by all allies with shared unit control.
- Custom UI showing the resources of mines and carried by workers including player bonuses. It shows up to two different carried resources per worker (space limitations of the UI).
- Harvesting bonuses per players like it is provided in Warcraft II for Oil and lumber.
- Register costs for building, unit, item, ability and research types per player.
- Warning sounds and messages for missing resources, low and empty mines.
- Chat commands to buy, sell, exchanging resources. All chat commands can be listed with the chat command "-hr".
- Loaded mines support similar to Night Elf and Undead races with Warcraft's cargo abilities.
Future Work
- Wisp like worker support occupying the mine which can currently be done with a loaded mine and a cargo size of 1.
- Destructible mines like trees.
- Refactoring: For example, instead of using all the hashtable keys I could introduce the structs Mine and Worker and move the fields there.
- Professional announcer voice for the example map.