Creating a shop
What is a shop?
A shop is a data type like so;
struct Shop {
vec2i dimensions;
int tagRefernce;
Peon[] employees;
int[string] jobReferences;
lua_State* L;
}
How do I create a new shop?
Well you'll need to place a shop file into 'res/shops'.
For example;
res/shops/new_shop.lua
Inside new_shop.lua you'll need to have the following function.
function shopload()
-- Shop config goes here
end
If this file isn't found then the ShopLoader will skip over it and disregard the contents of the file.
Loading your new shop
inside the loadshop function we first need a name for the type of shop we are going to be making. In this instance I'll be making a simple grocery store.
To set the name of the shop we need to change the tag variable, like so;
function shopload()
shop.tag = "Grocerys"
end
Now we need to give our shop some jobs so that Peons will have things to do in them.
To do this, we need to add a function to the jobs table. I want to make a "restock" job so i'll call it that.
function shopload()
shop.tag = "Grocerys"
shop.jobs["restock"] = _restock
end
function _restock()
-- Job generation code goes here
end
Nice and easy right.
The _restock function is a job generator function, this is the function that we will call every time that particular job is given to a Peon.
Changing the shop values
In the function shopload we have access to the shop variable, we can modify the following variables.
| Variable | Data Type | Description |
|---|---|---|
| tag | string | Used to show in the GUI what the peon is currently doing |
| jobs | table[string] | Used to store job generation functions (see below) |
| icon | string | Path to shop icon, strings beginning with '//' will refers to the same directory as the shops root directory for sand-boxing reasons. |
| desc | string | Flavour text to be shown in then game GUI when hovering over shop build icon. |
| name | string | Name to be show in the game GUI when hovering over shop build icon |
| equipment | table[string] = Shop Equipment | |
| items | table[string] = Shop Items | |
Changing job values
| Variable | Data Type | Description |
|---|---|---|
| updateTime | number (float) | How often should the update function be called. Default is 1.0f, or once a second |
| jobTime | number(float) | How much longer the job has till it's completed. Jobs can keep updating this value, allowing jobs to last until a certain criteria has been met. |
| onUpdate | function(job) | The function to call when we update the job. THIS WILL ONLY BE CALLED WHEN AT TARGET LOCATION |
| onComplete | function(job) | The function to call once the job has been competed. |
| valid | bool | If true job will be valid and added to the job stack, if false job will be discarded. |
| targetLocation | table | t[0] is world X position and t[1] is world Y position that the job will take place at. |
Example Code For a Shop
-- Main function of any shop file
function shopload()
shop.tag = "Core.Grocerys" -- A unique name to refer to this shop internally
shop.jobs["restock"] = _restock -- Add a job via this jobs table
-- path to shop icon to be used in game GUI
-- '//' refers to the full path of your shop.lua file
shop.icon = "//grocerys.png"
shop.desc = "A place to buy local produce" -- Flavour text shown in tooltip
shop.name = "Grocerys" -- Name of your shop as it appeares in game
-- Minimum size of the shop needs to be not including walls
shop.minrect = {3, 3}
end