possibly because I might run out of space, here's clusterforget #2, objects.lua
which pretty much controls the properties of the tiles and stuff
--=Tiles=--
tiles = {}
types = {}
function addtile(x,y,props,elev)
ok = true
for i,v in pairs(tiles) do
if v.x == x and v.y == y then
ok = false
end
end
if ok then
local tile = {}
tile.name = props.name
tile.x = x
tile.y = y
tile.img = props.img
tile.life = props.life
tile.process = false
tile.build = nil
tile.menu = props.menu
tile.elev = elev
table.insert(tiles, tile)
end
end
function process(dt)
local check = 0
for i,tile in pairs(tiles) do
if tile.process == true then
if tile.life <= 0 then
tile.process = false
tile.build(tile)
g.controls = true
else
tile.life = tile.life - dt
end
check = check + 1
end
end
if check >= 1 then
g.controls = false
else
if not g.menu or g.help then
g.controls = true
end
end
end
function set_properties(tile,props)
tile.name = props.name
tile.img = props.img
tile.life = props.life
tile.process = false
tile.build = nil
tile.menu = props.menu
end
function invalid_option()
newmessage("Feature not yet implemented.")
end
function tile_count(name)
local count = 0
for i,tile in pairs(tiles) do
if tile.name == name then
count = count + 1
end
end
return count
end
function startgame()
addtile(0,0,grass.properties,1)
addtile(1,0,grass.properties,2)
addtile(2,0,grass.properties,3)
addtile(3,0,grass.properties,4)
addtile(4,0,grass.properties,5)
end
function define_tile(name,id,img,funct)
local tile = {}
tile.name = name
tile.img = img
tile.funct = funct
table.insert(types,id,tile)
end
define_tile("Grass",1,getImg("grass.png"),
function ()
print("FASFFFFF")
end
)
--
--Grass--
grass = {}
grass.img = getImg("grass.png")
function grass.village(tile)
if tile.process == false then
if g.wood >= 50 and g.ore >= 30 then
tile.build = grass.village2
tile.process = true
g.wood = g.wood-50
g.ore = g.ore-30
g.maxpop = g.maxpop+16
newmessage("-50 Wood\n-30 Ore\nConstructing Village...")
else
newmessage("50 wood and 30 ore is needed to build a village.")
end
end
end
function grass.village2(tile)
set_properties(tile,village.properties)
newmessage("Your village has been built!")
end
function grass.farm(tile)
if g.wood >= 20 then
tile.process = true
tile.build = grass.farm2
tile.life = 2
newmessage("Tilling land...")
else
newmessage("20 Wood is needed to make a crop field.")
end
end
function grass.farm2(tile)
g.wood = g.wood - 20
g.maxcrops = g.maxcrops + 16
newmessage("-20 Wood\nLand has been tilled.")
set_properties(tile,farmland.properties)
end
function grass.forest(tile)
if g.seeds >= 4 then
tile.build = grass.forest2
tile.process = true
g.seeds = g.seeds - 4
newmessage("-4 Seeds\nForest Growing...")
else
newmessage("Four seeds is needed to grow a forest.")
end
end
function grass.forest2(tile)
set_properties(tile,forest.properties)
end
function grass.hut(tile)
local pop_req = tile_count("Hut") + 4
if g.wood >= 35
and g.ore >= 20
and g.pop >= pop_req then
g.wood = g.wood - 35
g.ore = g.ore - 20
tile.process = true
tile.build = grass.hut2
newmessage("-35 Wood\n-20 Ore\nConstructing hut...")
else
newmessage("You need 35 wood, 20 ore, and "..pop_req.." people to create a hut.")
end
end
function grass.hut2(tile)
set_properties(tile,hut.properties)
newmessage("Hut has been built.")
end
function grass.rest(tile)
if g.wood >= 80
and g.ore >= 50 then
tile.process = true
tile.build = grass.rest2
newmessage("-80 Wood\n-30 Ore\nBuilding Restaurant...")
else
newmessage("You need 80 wood and 30 ore to build a restaurant.")
end
end
function grass.rest2(tile)
set_properties(tile,rest.properties)
newmessage("Your restaurant has been built. Now start cooking.")
end
grass.menu = {
{"Build Village",grass.village},
{"Make Farmland",grass.farm},
{"Grow Forest",grass.forest},
{"Build Hut",invalid_option},
{"Build Restaraunt",grass.rest}
}
grass.properties = {
name = "Grass",
img = grass.img,
life = 3,
menu = grass.menu}
--
--Forest--
forest = {}
forest.img = getImg("forest.png")
function forest.cut(tile)
if tile.process == false then
tile.process = true
tile.build = forest.explore
newmessage("Cutting down forest...")
end
end
function forest.explore(tile)
local coord = {
{x = 1, y = 0},
{x = -1, y = 0},
{x = 0, y = 1},
{x = 0, y = -1}
}
for i,c in pairs(coord) do
addtile((tile.x + c.x),(tile.y + c.y),forest.properties)
local randomtile = math.random(1,8)
if randomtile == 1 then
set_properties(tile,mine.properties)
elseif randomtile == 2 then
set_properties(tile,lake.properties)
else
set_properties(tile,grass.properties)
end
end
local num1 = math.random(3,6)
local num2 = math.random(3,6)
g.wood = g.wood + num1
g.seeds = g.seeds + num2
newmessage("+"..num1.." Wood\n+"..num2.." Seeds")
sort()
end
forest.menu = {
{"Cut Down Forest",forest.cut}}
forest.properties = {
name = "Forest",
img = forest.img,
life = 1,
menu = forest.menu}
--
--Mine--
mine = {}
mine.img = getImg("mine.png")
mine.time = 0
function update_minetime(dt)
for i,tile in pairs(tiles) do
if tile.minetime ~= nil then
tile.minetime = tile.minetime -dt
end
end
end
function mine.getore(tile)
if tile.minetime == nil then
tile.minetime = 0
end
if tile.minetime <= 0 then
tile.process = true
tile.build = mine.getore2
newmessage("Mining...")
else
newmessage("You must wait "..math.ceil(tile.minetime).." seconds for the ore to be restored.")
end
end
function mine.getore2(tile)
local num = math.random(5,20)
g.ore = g.ore + num
tile.minetime = 30
tile.life = 3
newmessage("+"..num.." Ore")
end
function mine.destroy(tile)
tile.process = true
tile.build = mine.destroy2
newmessage("Destroying mine...")
end
function mine.destroy2(tile)
set_properties(tile, grass.properties)
newmessage("Mine has been decimated")
end
mine.menu = {
{"Mine",mine.getore},
{"Destroy Mine",mine.destroy}
}
mine.properties = {
name = "Mine",
img = mine.img,
life = 3,
menu = mine.menu}
--
--Village--
village = {}
village.img = getImg("village.png")
village.time = 0
village.rand = math.random(60,120)
function update_pop(dt)
local t = village.time
local rand = village.rand
if t >= rand then
village.time = 0
village.rand = math.random(60,120)
if g.maxpop > 0 then
local diff = g.maxpop - g.pop
local num = math.random(g.pop+1, diff/2)
g.pop = g.pop + num
newmessage(num.." people moved into your civilization.")
end
else
village.time = t + dt
end
end
village.menu = {
{"Upgrade Village",invalid_option},
{"Destroy Village",invalid_option}
}
village.properties = {
name = "Village",
img = village.img,
life = 2,
menu = village.menu}
--
--Farmland--
farmland = {}
farmland.img = getImg("farmland.png")
farmland.menu = {
{"Plant Crops",invalid_option},
{"Remove Farm",invalid_option}
}
farmland.properties = {
name = "Farmland",
img = farmland.img,
life = 1,
menu = farmland.menu}
--
--Lake--
lake = {}
lake.img = getImg("lake.png")
function update_fishtime(dt)
for i,tile in pairs(tiles) do
if tile.fishtime ~= nil then
tile.fishtime = tile.fishtime - dt
end
end
end
function lake.fish(tile)
if tile.fishtime == nil then
tile.fishtime = 0
end
if tile.fishtime <= 0 then
tile.process = true
tile.build = lake.fish2
newmessage("Fishing...")
else
newmessage("You must wait "..math.ceil(tile.fishtime).." seconds for more fish to appear.")
end
end
function lake.fish2(tile)
local num = math.random(0,10)
g.fish = g.fish + num
tile.fishtime = 20
tile.life = 3
newmessage("+"..num.." Fish")
end
lake.menu = {
{"Fish",lake.fish}
}
lake.properties = {
name = "Lake",
img = lake.img,
life = 3,
menu = lake.menu
}
--
--Hut--
hut = {}
hut.img = getImg("hut.png")
hut.time = 0
function update_huts(dt)
if hut.time >= 60 then
local str = ""
for i,a in pairs(tiles) do
for i,b in pairs(tiles) do
if distance(a.x,a.y,b.x,b.y) <= 1 then
if a.prof == "miner"
and b.name == "Mine" then
local num = math.random(5,20)
g.ore = g.ore + num
str = str.."+"..num.." Ore\n"
elseif a.prof == "lumberjack" then
local num = math.random(3,6)
g.wood = g.wood + num
str = str.."+"..num.." Wood"
end
end
end
end
hut.time = 0
newmessage(str)
else
hut.time = hut.time + dt
end
end
function hut.miner(tile)
if tile.prof == nil then
tile.prof = "miner"
end
end
function hut.lumberjack(tile)
if tile.prof == nil then
tile.prof = "lumberjack"
end
end
hut.menu = {
{"Hire Miner",hut.miner},
{"Hire Lumberjack",hut.lumberjack}
}
hut.properties = {
name = "Hut",
img = hut.img,
life = 3,
menu = hut.menu
}
--
--Restaurant--
rest = {}
rest.img = getImg("restaurant.png")
function rest.food(tile)
if g.ore*4 >= g.fish + g.crops then
tile.process = true
tile.build = rest.food2
newmessage("Cooking food...")
else
newmessage("You need "..math.floor(((g.fish + g.crops)/4) - (g.ore)).." ore to cook your food.")
end
end
function rest.food2(tile)
local num1 = g.ore - math.floor((g.fish + g.crops)/4)
g.ore = g.ore - num1
local num2 = g.fish + g.crops
g.food = g.food + num2
newmessage("-"..num1.." Ore\n+"..num2.." Food")
g.fish = 0
g.crops = 0
end
function rest.destroy(tile)
end
rest.feed = 0
function feed_pop(dt)
if g.pop > 0 then
local feed = rest.feed
if feed >= 60 then
if g.food >= g.pop then
newmessage("Your population was successfully fed!")
else
local diff = g.pop - g.food
g.pop = g.pop - diff
newmessage(diff.." people died of hunger.")
end
if not tile_count("Warehouse") >= 1 then
g.food = 0
newmessage("Your food has been thrown away, maybe you should get a warehouse to store it.")
else
newmessage("Your warehouse has stored your unused food.")
end
rest.feed = 0
else
rest.feed = feed+dt
end
end
end
rest.menu = {
{"Make Food",rest.food},
{"Destroy Restraunt",rest.destroy}
}
rest.properties = {
name = "Restaurant",
img = rest.img,
life = 3,
menu = rest.menu
}
--
--RANDOM SPACE LOL