Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- LogBox, a Candy Box-inspired game creatified by NeonJ
- There are [10] game ticks per second!
- This is starting to shape up!
- Using Advanced Computers for mouse compatability and COLOUR
- ____________ |
- <\ /\ _________ /| Log | |\ T
- \_ O /\/\ /_________\ | Box | | \O/
- /> /\/\/\ | '' '' | |¯¯¯¯¯¯¯¯ | T
- / > || | [] '' | | [] ' ' ' | / \
- Ideas for the rightern GUI screen
- - Shop - Player can purchase items to use on his adventure and for his kingdom.
- - Quests - Player can bring his army on quests for glory and stuff. Mostly stuff.
- - Stocks - Shows the player's item stocks. Sorted by type. Undiscovered items are not displayed.
- - Message Log - Gives a log of the player's recent events.
- - World Map - Player can explore towns and a world map itself.
- -
- -
- -
- -
- -
- The World Map plan for the Rightern GUI (if it happens)
- - When the player starts, he will be visible on the map and can click around to walk.
- O /___\
- <|> |...| |
- / \ | ; |
- [_] - - - [_] - - - [_]
- - Destinations will become available as the player explores more of the map.
- - To leave the town, the player must amass an army, as there are battles ahead.
- - In the town: Town Hall [Management & Options]
- Lumber Mill [Wood Stocks]
- Mine [Stone and Metal Stocks]
- Farm [Plant Stocks]
- Ranch [Animal Stocks]
- Barracks [Army Stocks]
- Blacksmith [Tool Stocks]
- Market [Buy / Sell Items]
- Town Gate [Exit - Go on Quests!]
- - - Version History - -
- a0.0.1: Nothing works yet it's still just a shell shut up
- a0.0.2: Well, I finished the main doGameTick stuff, and there's now a lot of variables! All are used. Awesome.
- ]]
- -- Main Variables
- local main = {}
- local usr = {}
- local shop = {}
- local msg = {}
- main["running"] = true
- main["timer"] = os.startTimer(0)
- main["lastTick"] = main["timer"]
- -- Saved Variables
- usr["farm_tree"] = 128 -- Max is <building_treeFarm> * 128
- usr["farm_wheatSeed"] = 0 -- For food - High seed output, low food output, medium growth
- usr["farm_wheatCrop"] = 0 -- Crop versions can be harvested.
- usr["farm_potatoSeed"] = 0 -- For food - High food output, slow growth, high seed output
- usr["farm_potatoCrop"] = 0 -- Crop versions can be harvested.
- usr["farm_carrotSeed"] = 0 -- For food - Medium food output, medium growth, medium seed output
- usr["farm_carrotCrop"] = 0 -- Crop versions can be harvested.
- usr["farm_melonSeed"] = 0 -- For food - High seed output, low food output, fast growth
- usr["farm_melonCrop"] = 0 -- Crop versions can be harvested.
- usr["farm_chicken"] = 0 -- Provides feathers and food - Requires 1 wheatSeed (or melonSeed) per 10000 ticks per chicken.
- usr["farm_cow"] = 0 -- Provides leather and food - Requires 1 wheatCrop per 14000 ticks per cow.
- usr["farm_pig"] = 0 -- Just provides food, but high output - Requires 1 carrot per 8000 ticks per pig.
- usr["farm_sheep"] = 0 -- Provides cloth and food - Requires 1 wheatCrop per 16000 ticks per sheep.
- usr["building_treeFarm"] = 1 -- Each tree farm can hold 128 trees, and 16 workers.
- usr["building_stoneMine"] = 0 -- Each stone mine can hold 16 workers.
- usr["building_cropFarm"] = 0 -- Each crop farm can hold 128 crops in TOTAL, and 16 workers.
- usr["building_animalFarm"] = 0 -- Each animal farm can hold 128 "animal value". Cow is 8, Pig is 6 and Chicken is 4. Also holds 16 workers.
- usr["resource_food"] = 512 -- If you run out of food your workers will start to quit
- usr["resource_money"] = 512 -- Bit of starter money
- usr["resource_log"] = 0 -- Logs are originally used for money and basic crafting
- usr["resource_sapling"] = 0 -- Saplings are used to plant more trees
- usr["resource_stone"] = 0 -- Stone is a bit useless but it sells for a little bit, and is an infinite resource. Used for earlygame equipment.
- usr["resource_coal"] = 0 -- Used to create alloys
- usr["resource_copper"] = 0 -- Used to create bronze alloy. Also used for mechanisms
- usr["resource_tin"] = 0 -- Used to create bronze alloy
- usr["resource_bronze"] = 0 -- Alloy from coal, copper and tin
- usr["resource_iron"] = 0 -- Used to craft weapons and armour
- usr["resource_steel"] = 0 -- Alloy made from iron and coal. Stronger than iron. Used to craft weapons and armour
- usr["resource_mithril"] = 0 -- Found on adventured. Stronger than steel. Used to craft weapons and armour.
- usr["resource_gold"] = 0 -- Used for advanced creations, or sells for loads
- usr["resource_sapphire"] = 0 -- Sells for loads. May have other uses.
- usr["resource_emerald"] = 0 -- Sells for loads. May have other uses.
- usr["resource_ruby"] = 0 -- Sells for loads. May have other uses.
- usr["resource_mithril"] = 0 -- Raw mithril. Makes the best stuff.
- usr["resource_wheatSeed"] = 0 -- Plant more wheat! Used to feed chickens.
- usr["resource_wheatCrop"] = 0 -- Converted to 6 Food. Used to feed cows and sheep. (6 Food per 6000 ticks.)
- usr["resource_potato"] = 0 -- Converted to 4 Food, or plant more Potatoes. (4-12 Food per 8000 ticks)
- usr["resource_carrot"] = 0 -- Converted to 3 Food, or plant more Carrots. Used to feed pigs. (3-9 Food per 6000 ticks)
- usr["resource_melonCrop"] = 0 -- Converted to 1 Food or melonSeed. (3-6 Food per 4000 ticks)
- usr["resource_melonSeed"] = 0 -- Plant more melons! Used to feed chickens.
- usr["resource_leather"] = 0 -- Gathered from cows. Used for basic armour.
- usr["resource_feather"] = 0 -- Gathered from chickens. Used for crafting.
- usr["resource_wool"] = 0 -- Gathered from sheep. Used to make bandages for your army.
- usr["resource_meatCow"] = 0 -- Gathered from cows. Converts to 8 Food.
- usr["resource_meatPig"] = 0 -- Gathered from pigs. Converts to 8 Food.
- usr["resource_meatChicken"] = 0 -- Gathered from chickens. Converts to 6 Food.
- usr["resource_meatSheep"] = 0 -- Gathered from sheep. Converts to 6 Food.
- usr["resource_milk"] = 0 -- Gathered from cows. Used to make medicine.
- usr["tool_axeStone"] = 1 -- Woodcutting: 50% speed [2 Pt]
- usr["tool_axeBronze"] = 0 -- Woodcutting: 75% speed [3 Pt]
- usr["tool_axeIron"] = 0 -- Woodcutting: 100% speed [4 Pt]
- usr["tool_axeSteel"] = 0 -- Woodcutting: 125% speed [5 Pt]
- usr["tool_axeMithril"] = 0 -- Woodcutting: 150% speed [6 Pt]
- usr["tool_pickaxeStone"] = 0 -- Mining: 50% speed [2 Pt]
- usr["tool_pickaxeBronze"] = 0 -- Mining: 75% speed [3 Pt]
- usr["tool_pickaxeIron"] = 0 -- Mining: 100% speed [4 Pt]
- usr["tool_pickaxeSteel"] = 0 -- Mining: 125% speed [5 Pt]
- usr["tool_pickaxeMithril"] = 0 -- Mining: 150% speed [6 Pt]
- usr["tool_hoeStone"] = 0 -- Harvesting: 50% speed [2 Pt]
- usr["tool_hoeBronze"] = 0 -- Harvesting: 75% speed [3 Pt]
- usr["tool_hoeIron"] = 0 -- Harvesting: 100% speed [4 Pt]
- usr["tool_hoeSteel"] = 0 -- Harvesting: 125% speed [5 Pt]
- usr["tool_hoeMithril"] = 0 -- Harvesting: 150% speed [6 Pt]
- usr["tool_swordStone"] = 0 -- 2 DMG
- usr["tool_swordBronze"] = 0 -- 4 DMG
- usr["tool_swordIron"] = 0 -- 6 DMG
- usr["tool_swordSteel"] = 0 -- 8 DMG
- usr["tool_swordMithril"] = 0 -- 12 DMG
- -- Stone armour does not exist. -- 0 DEF
- usr["tool_armourBronze"] = 0 -- +4 DEF
- usr["tool_armourIron"] = 0 -- +8 DEF
- usr["tool_armourSteel"] = 0 -- +12 DEF
- usr["tool_armourMithril"] = 0 -- +20 DEF
- -- If a player has workers which have to use different kinds of tools, it'll be a mix of both
- -- ie: 5 stone axes, 10 iron axes, 12 workers
- -- Harvest Power will be 10x iron, 2x stone -> 10(4) + 2(2) = 44 Points of Harvest Power
- -- No work can be done if a tool is not supplied
- usr["worker_logger"] = 1 -- Logger chops 1 log per minute - more loggers mean faster resource gathering.
- usr["worker_farmer"] = 0 -- Plants and harvests crops and saplings - more farmers mean faster action completing.
- usr["worker_rancher"] = 0 -- Manages animals in a farm - more ranchers mean faster action completing.
- usr["worker_miner"] = 0 -- Mines resources. Random chance to produce high-quality iron. Stone is infinite. More miners mean faster resource gathering.
- usr["worker_army"] = 0 -- Goes on quests and finds treasure. The player leads them to battle. More soldiers mean more HP for your army.
- usr["worker_villager"] = 0 -- Regular villagers are without a job. I allow the player to reassign workers as they wish.
- usr["worker_total"] = 1 -- Total workers. Used to make hunger-based calculations easier.
- usr["hidden_logTick"] = 0 -- Every tick, this is increased by ["worker_logger"], as soon as it hits 6000 or more, a log is chopped
- usr["hidden_stoneTick"] = 0 -- Every tick, this is increased by ["worker_miner"], as soon as it hits 6000 or more, stone is mined
- usr["hidden_wheatTick"] = 0 -- Every tick, this is increased by ["farm_wheatSeed"], as soon as it hits 6000 or more, wheat can be harvested
- usr["hidden_melonTick"] = 0 -- Every tick, this is increased by ["farm_melonSeed"], as soon as it hits 4000 or more, melons can be harvested
- usr["hidden_potatoTick"] = 0 -- Every tick, this is increased by ["farm_potatoSeed"], as soon as it hits 8000 or more, potatoes can be harvested
- usr["hidden_carrotTick"] = 0 -- Every tick, this is increased by ["farm_carrotSeed"], as soon as it hits 6000 or more, carrots can be harvested
- usr["hidden_harvestTick"] = 0 -- Every tick, this is increased by ["worker_farmer"] when harvestables are available. After hitting 500, a random crop is harvested.
- usr["hidden_cowBreedTick"] = 0 -- Cooldown for cows to breed - No slaughtering until time is up
- usr["hidden_chickenBreedTick"] = 0 -- Cooldown for chickens to breed - No slaughtering until time is up
- usr["hidden_pigBreedTick"] = 0 -- Cooldown for pigs to breed - No slaughtering until time is up
- usr["hidden_sheepBreedTick"] = 0 -- Cooldown for sheep to breed
- usr["hidden_cowFeedTick"] = 0 -- Every tick, this is increased by ["farm_cow"], as soon as it hits ???? or more, a wheatCrop is consumed.
- usr["hidden_chickenFeedTick"] = 0 -- Every tick, this is increased by ["farm_chicken"], as soon as it hits ???? or more, a wheatSeed or melonSeed is consumed.
- usr["hidden_pigFeedTick"] = 0 -- Every tick, this is increased by ["farm_pig"], as soon as it hits ???? or more, a carrot is consumed.
- usr["hidden_sheepFeedTick"] = 0 -- Every tick, this is increased by ["farm_sheep"], as soon as it hits ???? or more, a wheatCrop is consumed.
- usr["hidden_sheepResourceTick"] = 0 -- Every tick, this is increased by ["farm_sheep"], as soon as it hits 8000 or more, a wool can be gathered.
- usr["hidden_cowResourceTick"] = 0 -- Every tick, this is increased by ["farm_cow"], as soon as it hits 16000 or more, a milk can be gathered.
- usr["hidden_rancherHarvestTick"] = 0 -- Every tick, this is increased by ["worker_rancher"], as soon as it hits 4000 or more, the rancher harvests something.
- usr["hidden_saplingTick"] = 0 -- Every tick, this is increased by (farmers / 30000), as soon as it hits 1 or more, a sapling is gathered
- usr["hidden_armyCooldown"] = 0 -- Cooldown for your army to recover from a quest. Less HP = More recovery time.
- usr["hidden_lastTree"] = 0 -- Increases by 1 every log. Has 1/4 chance to reset to 0 and -1 tree when value between 4-10. Instantly resets when it hits 10
- usr["hidden_eatTick"] = 0 -- Every tick, this is increased by (total workers / 1500), as soon as it hits 1 or more, food is depleted
- -- Config Variables
- usr["setting_gameSpeed"] = 1.0
- usr["setting_autoReplantWheat"] = 1 -- Automatically replant crops, but do not plant more than what was initially planted.
- usr["setting_autoReplantMelon"] = 1
- usr["setting_autoReplantPotato"] = 1
- usr["setting_autoReplantCarrot"] = 1
- usr["main_leftGUIID"] = "Forest" -- Which display is used on the left status screen.
- usr["main_rightGUIID"] = "Main" -- Which display is used on the right main screen.
- -- Message Logs
- usr["log_01"] = "The player starts his career."
- usr["log_02"] = ""
- usr["log_03"] = ""
- usr["log_04"] = ""
- usr["log_05"] = ""
- usr["log_06"] = ""
- usr["log_07"] = ""
- usr["log_08"] = ""
- usr["log_09"] = ""
- usr["log_10"] = ""
- usr["log_11"] = ""
- usr["log_12"] = ""
- usr["log_13"] = ""
- usr["log_14"] = ""
- usr["log_15"] = ""
- usr["log_16"] = ""
- -- Shop Variables (prices, basically) Buy price = 100%, sell price = 20% (So basically numbers have to be dividable by 5)
- shop["sell_multiplier"] = 0.2
- shop["resource_log"] = 20 --
- shop["resource_stone"] = 5 -- Sell stone for 1 coin each, basically.
- shop["resource_sapling"] = 20 -- Buy sapling for 20, sell logs for 4 each (5 for 20), should equal to an average profit.
- shop["resource_meatPig"] = 10 -- In case of emergencies, the player can buy food. Hopefully overpriced food.
- -- I need to try and find the balance between "don't make buying the player's main choice" and "don't make this a money farm by selling it" :T
- msg["quitVillager"] = "A villager has left"
- msg["quitLogger"] = "A woodcutter has left"
- msg["quitMiner"] = "A miner has left"
- msg["quitFarmer"] = "A farmer has left"
- msg["quitRancher"] = "A rancher has left"
- msg["quitArmy"] = "A swordsman has left"
- msg["slainVillager"] = "A villager was slain"
- msg["slainLogger"] = "A logger was slain"
- msg["slainMiner"] = "A miner was slain"
- msg["slainFarmer"] = "A farmer was slain"
- msg["slainRancher"] = "A rancher was slain"
- msg["slainArmy"] = "A swordsman was slain"
- msg["escapedAnimal"] = "Some animals have escaped"
- msg["deadCow"] = "A cow has died"
- msg["deadSheep"] = "A sheep has died"
- msg["deadChicken"] = "A chicken has died"
- msg["deadPig"] = "A pig has died"
- msg["reasonHunger"] = " due to lack of food."
- msg["reasonRaid"] = " due to a raid."
- msg["reasonFoodPoison"] = " due to food poisoning"
- msg["reasonNoRanchers"] = " due to overworked ranchers"
- if term.isColor() == false then
- print("Sorry, this program is only for use on Advanced Computers.")
- print("Please consider upgrading!")
- main["running"] = false
- end
- local function loadGame() -- TEXTY used as a base
- local path = addSlashIfNeeded(shell.resolve(""))
- if fs.exists(path.."LogBox.sav") then
- h = fs.open(path.."LogBox.sav", "r")
- while true do
- data = h.readLine()
- if data == nil then break end
- usr = textutils.unserialize(h.readAll())
- end
- h.close()
- -- Else, there is no save file.
- -- Perhaps I should make the floppy disks the save items?
- end
- end
- local function writeFormatText(message) -- This will print text of a specific format onto the screen, making it easier for me to do colour things and such.
- --[[
- SYNTAX IDEA II
- "Welcome to the $5$&5&GRAND THING OF AWESOME$af$&af&!"
- $af$ - Change background colour. "AF" will be combined into one colour.
- &af& - Change text colour. "AF" will be combined into one colour.
- Colour combinations support up to four colours currently.
- ]]--
- local stringLength = string.len(message)
- for i = 1, stringLength do
- local char = string.sub(message, i, i)
- if char == "&" then
- local foundOtherSymbol = 0
- local myColours = {}
- local myIncrease = 0
- myColours[1] = 0
- myColours[2] = 0
- myColours[3] = 0
- myColours[4] = 0
- while foundOtherSymbol == 0 do
- i = i + 1
- myIncrease = myIncrease + 1
- local char2 = string.sub(message, i, i)
- if char2 == "&" then
- foundOtherSymbol = 1
- elseif char2 == "0" then -- These are NOT the default colour codes, but CC's own colour codes!
- myColours[myIncrease] = colours.white
- elseif char2 == "1" then
- myColours[myIncrease] = colours.orange
- elseif char2 == "2" then
- myColours[myIncrease] = colours.magenta
- elseif char2 == "3" then
- myColours[myIncrease] = colours.lightBlue
- elseif char2 == "4" then
- myColours[myIncrease] = colours.yellow
- elseif char2 == "5" then
- myColours[myIncrease] = colours.lime
- elseif char2 == "6" then
- myColours[myIncrease] = colours.pink
- elseif char2 == "7" then
- myColours[myIncrease] = colours.grey
- elseif char2 == "8" then
- myColours[myIncrease] = colours.lightGrey
- elseif char2 == "9" then
- myColours[myIncrease] = colours.cyan
- elseif char2 == "a" then
- myColours[myIncrease] = colours.purple
- elseif char2 == "b" then
- myColours[myIncrease] = colours.blue
- elseif char2 == "c" then
- myColours[myIncrease] = colours.brown
- elseif char2 == "d" then
- myColours[myIncrease] = colours.green
- elseif char2 == "e" then
- myColours[myIncrease] = colours.red
- elseif char2 == "f" then
- myColours[myIncrease] = colours.black
- -- Else syntax be bork'd
- end
- end
- term.setFontColor(colours.combine(myColours[1] + myColours[2] + myColours[3] + myColours[4]) -- It only supports four
- elseif char == "$" then
- local foundOtherSymbol = 0
- local myColours = {}
- local myIncrease = 0
- myColours[1] = 0
- myColours[2] = 0
- myColours[3] = 0
- myColours[4] = 0
- while foundOtherSymbol == 0 do
- i = i + 1
- myIncrease = myIncrease + 1
- local char2 = string.sub(message, i, i)
- if char2 == "&" then
- foundOtherSymbol = 1
- elseif char2 == "0" then -- These are NOT the default colour codes, but CC's own colour codes!
- myColours[myIncrease] = colours.white
- elseif char2 == "1" then
- myColours[myIncrease] = colours.orange
- elseif char2 == "2" then
- myColours[myIncrease] = colours.magenta
- elseif char2 == "3" then
- myColours[myIncrease] = colours.lightBlue
- elseif char2 == "4" then
- myColours[myIncrease] = colours.yellow
- elseif char2 == "5" then
- myColours[myIncrease] = colours.lime
- elseif char2 == "6" then
- myColours[myIncrease] = colours.pink
- elseif char2 == "7" then
- myColours[myIncrease] = colours.grey
- elseif char2 == "8" then
- myColours[myIncrease] = colours.lightGrey
- elseif char2 == "9" then
- myColours[myIncrease] = colours.cyan
- elseif char2 == "a" then
- myColours[myIncrease] = colours.purple
- elseif char2 == "b" then
- myColours[myIncrease] = colours.blue
- elseif char2 == "c" then
- myColours[myIncrease] = colours.brown
- elseif char2 == "d" then
- myColours[myIncrease] = colours.green
- elseif char2 == "e" then
- myColours[myIncrease] = colours.red
- elseif char2 == "f" then
- myColours[myIncrease] = colours.black
- -- Else syntax be bork'd
- end
- end
- term.setBackgroundColor(colours.combine(myColours[1] + myColours[2] + myColours[3] + myColours[4]) -- It only supports four
- else
- write(char)
- end
- end
- end
- local function saveGame() -- TEXTY used as a base here too
- local path = addSlashIfNeeded(shell.resolve(""))
- h = fs.open(path.."LogBox.sav")
- h.writeLine(textutils.serialize(usr))
- h.close()
- end
- local function logAction(message) -- These support formatted text
- usr["log_16"] = usr["log_15"]
- usr["log_15"] = usr["log_14"]
- usr["log_14"] = usr["log_13"]
- usr["log_13"] = usr["log_12"]
- usr["log_12"] = usr["log_11"]
- usr["log_11"] = usr["log_10"]
- usr["log_10"] = usr["log_09"]
- usr["log_09"] = usr["log_08"]
- usr["log_08"] = usr["log_07"]
- usr["log_07"] = usr["log_06"]
- usr["log_06"] = usr["log_05"]
- usr["log_05"] = usr["log_04"]
- usr["log_04"] = usr["log_03"]
- usr["log_03"] = usr["log_02"]
- usr["log_02"] = usr["log_01"]
- usr["log_01"] = message
- end
- local function determinePower(worker, type) -- Plus side: This is all one function now
- local_workersLeft = usr["worker_" .. worker] -- Bad side: Now everything has a 2-3-4-5-6 power system.
- local toolPower = 0 -- Probably easy to fix, though.
- if usr["tool_" .. type .. "Mythril"] >= workersLeft then
- toolPower = toolPower + (6 * workersLeft)
- workersLeft = 0
- return choppingPower
- else
- toolPower = toolPower + (6 * usr["tool_" .. type .. "Mythril"])
- workersLeft = workersLeft - usr["tool_" .. type .. "Mythril"])
- end
- if usr["tool_" .. type .. "Steel"] >= workersLeft then
- toolPower = toolPower + (5 * workersLeft)
- workersLeft = 0
- return choppingPower
- else
- toolPower = toolPower + (5 * usr["tool_" .. type .. "Steel"])
- workersLeft = workersLeft - usr["tool_" .. type .. "Steel"])
- end
- if usr["tool_" .. type .. "Iron"] >= workersLeft then
- toolPower = toolPower + (4 * workersLeft)
- workersLeft = 0
- return choppingPower
- else
- toolPower = toolPower + (4 * usr["tool_" .. type .. "Iron"])
- workersLeft = workersLeft - usr["tool_" .. type .. "Iron"])
- end
- if usr["tool_" .. type .. "Bronze"] >= workersLeft then
- toolPower = toolPower + (3 * workersLeft)
- workersLeft = 0
- return choppingPower
- else
- toolPower = toolPower + (3 * usr["tool_" .. type .. "Bronze"])
- workersLeft = workersLeft - usr["tool_" .. type .. "Bronze"])
- end
- if usr["tool_" .. type .. "Stone"] >= workersLeft then
- toolPower = toolPower + (2 * workersLeft)
- workersLeft = 0
- return choppingPower
- else
- toolPower = toolPower + (2 * usr["tool_" .. type .. "Stone"])
- workersLeft = workersLeft - usr["tool_" .. type .. "Stone"])
- end
- -- YEP THEY'RE CALL CALLED CHOPPINGPOWER
- -- TOTALLY NOT A COPY/PASTE OF THE FIRST WOODCUTTING ONE
- local function doGameTick() -- Do an action every tick
- if usr["building_treeFarm"] > 0 then -- No point doing the thing if there's nothing there, is there?
- if usr["farm_tree"] > 0 then -- Do log chopping
- usr["hidden_logTick"] = usr["hidden_logTick"] + determinePower("logger", "axe")
- while usr["hidden_logTick"] >= 24000 do
- usr["resource_log"] = usr["resource_log"] + 1
- usr["hidden_lastTree"] = usr["hidden_lastTree"] + 1
- usr["hidden_logTick"] = usr["hidden_logTick"] - 24000
- if usr["hidden_lastTree"] > 10 then
- usr["farm_tree"] = usr["farm_tree"] - 1
- usr["hidden_lastTree"] = 0
- elseif usr["hidden_lastTree"] > 4 then
- local randomVar = math.random(1,4)
- if randomVar == 1 then
- usr["farm_tree"] = usr["farm_tree"] - 1
- usr["hidden_lastTree"] = 0
- end
- end
- end
- -- Do sapling gathering. This is managed by farmers.
- usr["hidden_saplingTick"] = usr["hidden_saplingTick"] + usr["worker_farmer"]
- while usr["hidden_saplingTick"] >= 30000 do
- usr["resource_sapling"] = usr["resource_sapling"] + 1
- usr["hidden_saplingTick"] = usr["hidden_saplingTick"] - 30000
- end
- end
- end
- if usr["building_stoneMine"] > 0 then
- usr["hidden_stoneTick"] = usr["hidden_stoneTick"] + determinePower("miner", "pickaxe")
- while usr["hidden_stoneTick"] >= 24000 do
- usr["hidden_stoneTick"] = usr["hidden_stoneTick"] - 24000
- local rand = random(1,10)
- if rand < 9 then -- Stone
- usr["resource_stone"] = usr["resource_stone"] + 1
- else -- Rare Ores!
- local rand2 = random(1,100)
- if rand2 < 30 then -- Coal
- local veinSize = random(1,6)
- usr["resource_coal"] = usr["resource_coal"] + veinSize
- elseif rand2 < 50 then -- Copper
- local veinSize = random(1,4)
- usr["resource_copper"] = usr["resource_copper"] + veinSize
- elseif rand2 < 70 then -- Tin
- local veinSize = random(1,4)
- usr["resource_tin"] = usr["resource_tin"] + veinSize
- elseif rand2 < 85 then -- Iron
- local veinSize = random(1,4)
- usr["resource_iron"] = usr["resource_iron"] + veinSize
- elseif rand2 < 94 then -- Gold
- local veinSize = random(1,2)
- usr["resource_gold"] = usr["resource_gold"] + veinSize
- elseif rand2 < 96 then -- Sapphire
- usr["resource_sapphire"] = usr["resource_sapphire"] + 1 -- For sapphires, emeralds and rubies, you only ever get one per mine.
- elseif rand2 < 98 then -- Emerald
- usr["resource_emerald"] = usr["resource_emerald"] + 1 -- They're rare and worth a lot of gold!
- else -- Ruby
- usr["resource_ruby"] = usr["resource_ruby"] + 1 -- They may also have other uses.
- end
- end
- end
- end
- if usr["building_cropFarm"] > 0 then
- if usr["farm_wheatSeed"] > 0 then
- usr["hidden_wheatTick"] = usr["hidden_wheatTick"] + usr["farm_wheatSeed"]
- while usr["hidden_wheatTick"] > 6000 do
- usr["farm_wheatSeed"] = usr["farm_wheatSeed"] - 1
- usr["farm_wheatCrop"] = usr["farm_wheatCrop"] + 1
- usr["hidden_wheatTick"] = usr["hidden_wheatTick"] - 6000
- end
- end
- if usr["farm_melonSeed"] > 0 then
- usr["hidden_melonTick"] = usr["hidden_melonTick"] + usr["farm_melonSeed"]
- while usr["hidden_melonTick"] > 4000 do
- usr["farm_melonSeed"] = usr["farm_melonSeed"] - 1
- usr["farm_melonCrop"] = usr["farm_melonCrop"] + 1 -- Melon multi-drops will be managed on HARVEST
- usr["hidden_melonTick"] = usr["hidden_melonTick"] - 4000
- end
- end
- if usr["farm_potatoSeed"] > 0 then
- usr["hidden_potatotTick"] = usr["hidden_potatoTick"] + usr["farm_potatoSeed"]
- while usr["hidden_potatoTick"] > 8000 do
- usr["farm_potatoSeed"] = usr["farm_potatoSeed"] - 1
- usr["farm_potatoCrop"] = usr["farm_potatoCrop"] + 1
- usr["hidden_potatoTick"] = usr["hidden_potatoTick"] - 8000
- end
- end
- if usr["farm_carrotSeed"] > 0 then
- usr["hidden_carrotTick"] = usr["hidden_carrotTick"] + usr["farm_carrotSeed"]
- while usr["hidden_carrotTick"] > 6000 do
- usr["farm_carrotSeed"] = usr["farm_carrotSeed"] - 1
- usr["farm_carrotCrop"] = usr["farm_carrotCrop"] + 1
- usr["hidden_carrotTick"] = usr["hidden_carrotTick"] - 6000
- end
- end
- if usr["farm_cowTick"] > 0 then
- usr["farm_cowTick"] = usr["farm_cowTick"] - 1 -- Most of the animalTick stuff is managed elsewhere
- end
- if usr["farm_pigTick"] > 0 then
- usr["farm_pigTick"] = usr["farm_pigTick"] - 1
- end
- if usr["farm_chickenTick"] > 0 then
- usr["farm_chickenTick"] = usr["farm_chickenTick"] - 1
- end
- if usr["farm_sheepTick"] > 0 then
- usr["farm_sheepTick"] = usr["farm_sheepTick"] - 1
- end
- if usr["worker_farmer"] > 0 then
- if usr["farm_wheatCrop"] > 0 or usr["farm_melonCrop"] > 0 or usr["farm_potatoCrop"] > 0 or usr["farm_carrotCrop"] > 0 then
- usr["hidden_harvestTick"] = usr["hidden_harvestTick"] + determinePower("farmer", "hoe")
- while usr["hidden_harvestTick"] > 2000 do
- usr["hidden_harvestTick"] = usr["hidden_harvestTick"] - 2000
- local randomize = random(0, usr["farm_wheatCrop"] + usr["farm_melonCrop"] + usr["farm_potatoCrop"] + usr["farm_carrotCrop"])
- if randomize < usr["farm_wheatCrop"] then
- -- Harvest wheat
- usr["farm_wheatCrop"] = usr["farm_wheatCrop"] - 1
- local randomize = random(1,10)
- if randomize < 7 then -- 1, 2, 3, 4, 5, 6
- usr["resource_wheatSeed"] = usr["resource_wheatSeed"] + 2
- elseif randomize < 10 then -- 7, 8, 9
- usr["resource_wheatSeed"] = usr["resource_wheatSeed"] + 1
- end -- Else, no seeds on 10.
- -- End result: 150% seed output, with 10% chance of no seeds. I like THIS system much better.
- -- Starting off with wheat might be tough though, so I need to make it worth it.
- usr["resource_wheatCrop"] = usr["resource_wheatCrop"] + 1
- if usr["setting_autoReplantWheat"] == 1 and usr["resource_wheatSeed"] > 0 then -- Can't auto replant if there's no seeds!
- usr["resource_wheatSeed"] = usr["resource_wheatSeed"] - 1
- usr["farm_wheatSeed"] = usr["farm_wheatSeed"] + 1
- end
- elseif randomize < usr["farm_wheatCrop"] + usr["farm_melonCrop"] then
- -- Harvest melons
- usr["farm_melonCrop"] = usr["farm_melonCrop"] - 1
- usr["resource_melonCrop"] = usr["resource_melonCrop"] + random(3,6) -- Change this if balance happens
- if usr["setting_autoReplantMelon"] == 1 then
- if usr["resource_melonSeed"] > 0 then -- Seeds get used first
- usr["resource_melonSeed"] = usr["resource_melonSeed"] - 1
- usr["farm_melonSeed"] = usr["farm_melonSeed"] + 1
- else
- usr["resource_melonCrop"] = usr["resource_melonCrop"] - 1 -- Melon crops can be turned into seeds
- usr["farm_melonSeed"] = usr["farm_melonSeed"] + 1 -- Melon crop will never be below 3 here, so it works without an "if"
- end
- end
- elseif randomize < usr["farm_wheatCrop"] + usr["farm_melonCrop"] + usr["farm_potatoCrop"] then
- -- Harvest potatoes
- usr["farm_potatoCrop"] = usr["farm_potatoCrop"] - 1
- usr["resource_potato"] = usr["resource_potato"] + random(1,3)
- if usr["setting_autoReplantPotato"] == 1 then -- Auto replant per crop type? May be useful.
- usr["resource_potato"] = usr["resource_potato"] - 1
- usr["farm_potatoSeed"] = usr["farm_potatoSeed"] + 1
- end
- else
- -- Harvest carrots, basically works identical to potatoes
- usr["farm_carrotCrop"] = usr["farm_carrotCrop"] - 1
- usr["resource_carrot"] = usr["resource_carrot"] + random(1,3)
- if usr["setting_autoReplantCarrot"] == 1 then
- usr["resource_carrot"] = usr["resource_carrot"] - 1
- usr["farm_carrotSeed"] = usr["farm_carrotSeed"] + 1
- end
- end
- -- Carrots and potatoes are much easier to manage than the other two so I might have to balance it or something
- end
- end
- end
- end
- if usr["building_animalFarm"] > 0 then
- -- Is it me or can everything be done with only one rancher
- -- Perhaps ranchers will determine the maximum allowed animals too or something.
- if usr["farm_cow"] > 0 then
- usr["hidden_cowFeedTick"] = usr["hidden_cowFeedTick"] + usr["farm_cow"]
- while usr["hidden_cowFeedTick"] > 10000 do -- 10,000 is a tentative amount.
- if usr["resource_wheatCrop"] > 0 then
- usr["resource_wheatCrop"] = usr["resource_wheatCrop"] - 1
- else
- logAction(msg["deadCow"] .. msg["reasonHunger"])
- usr["farm_cow"] = usr["farm_cow"] - 1
- end
- usr["hidden_cowFeedTick"] = usr["hidden_cowFeedTick"] - 10000
- end
- if usr["hidden_cowResourceTick"] < 16000 then -- Cows do not produce milk when full. That makes no sense, but whatever~
- usr["hidden_cowResourceTick"] = usr["hidden_cowResourceTick"] + usr["farm_sheep"]
- end
- end
- if usr["farm_pig"] > 0 then
- usr["hidden_pigFeedTick"] = usr["hidden_pigFeedTick"] + usr["farm_pig"]
- while usr["hidden_pigFeedTick"] > 10000 do -- 10,000 is a tentative amount.
- if usr["resource_carrot"] > 0 then
- usr["resource_carrot"] = usr["resource_carrot"] - 1
- else
- logAction(msg["deadPig"] .. msg["reasonHunger"])
- usr["farm_pig"] = usr["farm_pig"] - 1
- end
- usr["hidden_pigFeedTick"] = usr["hidden_pigFeedTick"] - 10000
- end
- end
- if usr["farm_chicken"] > 0 then
- usr["hidden_chickenFeedTick"] = usr["hidden_chickenFeedTick"] + usr["farm_chicken"]
- while usr["hidden_chickenFeedTick"] > 10000 do -- 10,000 is a tentative amount.
- if usr["resource_melonSeed"] > 0 then
- usr["resource_melonSeed"] = usr["resource_melonSeed"] - 1
- elseif usr["resource_wheatSeed"] > 0 then
- usr["resource_wheatSeed"] = usr["resource_wheatSeed"] - 1
- else
- logAction(msg["deadChicken"] .. msg["reasonHunger"])
- usr["farm_chicken"] = usr["farm_chicken"] - 1
- end
- usr["hidden_chickenFeedTick"] = usr["hidden_chickenFeedTick"] - 10000
- end
- end
- if usr["farm_sheep"] > 0 then
- usr["hidden_sheepFeedTick"] = usr["hidden_sheepFeedTick"] + usr["farm_sheep"]
- while usr["hidden_sheepFeedTick"] > 10000 do -- 10,000 is a tentative amount.
- if usr["resource_wheatCrop"] > 0 then
- usr["resource_wheatCrop"] = usr["resource_wheatCrop"] - 1
- else
- logAction(msg["deadSheep"] .. msg["reasonHunger"])
- usr["farm_sheep"] = usr["farm_sheep"] - 1
- end
- usr["hidden_sheepFeedTick"] = usr["hidden_sheepFeedTick"] - 10000
- end
- if usr["hidden_sheepResourceTick"] < 8000 then -- Sheep do not regrow wool when they already have wool
- usr["hidden_sheepResourceTick"] = usr["hidden_sheepResourceTick"] + usr["farm_sheep"]
- end
- end
- if usr["worker_rancher"] > 0 then -- This one can probably be done much better, in it's current state it only supports two animal resources!
- if usr["hidden_sheepResourceTick"] >= 8000 or usr["hidden_cowResourceTick"] >= 16000 then -- If there's something to harvest...
- usr["hidden_rancherHarvestTick"] = usr["hidden_rancherHarvestTick"] + usr["worker_rancher"]
- while usr["hidden_rancherHarvestTick"] > 4000 do
- usr["hidden_rancherHarvestTick"] = usr["hidden_rancherHarvestTick"] - 4000
- local randomize = random(0, usr["hidden_sheepResourceTick"] + usr["hidden_cowResourceTick"]) -- Yeah, this means cows get priority but whatever.
- if randomize < usr["hidden_sheepResourceTick"] then
- -- Harvest sheep
- if usr["hidden_sheepResourceTick"] >= 8000 then
- usr["hidden_sheepResourceTick"] = usr["hidden_sheepResourceTick"] - 8000
- usr["resource_wool"] = usr["resource_wool"] + random(1,3)
- else
- usr["hidden_cowResourceTick"] = usr["hidden_cowResourceTick"] - 16000
- usr["resource_milk"] = usr["resource_milk"] + 1
- end
- else
- if usr["hidden_cowResourceTick"] >= 16000 then
- usr["hidden_cowResourceTick"] = usr["hidden_cowResourceTick"] - 16000
- usr["resource_milk"] = usr["resource_milk"] + 1
- else
- usr["hidden_sheepResourceTick"] = usr["hidden_sheepResourceTick"] - 8000
- usr["resource_wool"] = usr["resource_wool"] + random(1,3)
- end
- end
- end
- end
- end
- end
- -- Army stuff, once the army system finally gets finished.
- if usr["worker_total"] > 0 then
- usr["hidden_eatTick"] = usr["hidden_eatTick"] + usr["worker_total"]
- while usr["hidden_eatTick"] > 1500 do -- 1 worker eats every 150 seconds.
- if usr["resource_food"] > 0 then
- usr["resource_food"] = usr["resource_food"] - 1
- else
- -- A random worker will quit
- local randomize = random(1, usr["worker_total"])
- if randomize < usr["worker_miner"] then
- usr["worker_miner"] = usr["worker_miner"] - 1
- usr["worker_total"] = usr["worker_total"] - 1
- logAction(msg["quitMiner"] + msg["reasonHunger"])
- elseif randomize < usr["worker_miner"] + usr["worker_farmer"] then
- usr["worker_farmer"] = usr["worker_farmer"] - 1
- usr["worker_total"] = usr["worker_total"] - 1
- logAction(msg["quitFarmer"] + msg["reasonHunger"])
- elseif randomize < usr["worker_miner"] + usr["worker_farmer"] + usr["worker_rancher"] then
- usr["worker_rancher"] = usr["worker_rancher"] - 1
- usr["worker_total"] = usr["worker_total"] - 1
- logAction(msg["quitRancher"] + msg["reasonHunger"])
- elseif randomize < usr["worker_miner"] + usr["worker_farmer"] + usr["worker_rancher"] + usr["worker_logger"] then
- usr["worker_logger"] = usr["worker_logger"] - 1
- usr["worker_total"] = usr["worker_total"] - 1
- logAction(msg["quitLogger"] + msg["reasonHunger"])
- elseif randomize < usr["worker_villager"] + usr["worker_miner"] + usr["worker_farmer"] + usr["worker_rancher"] + usr["worker_logger"] then
- usr["worker_villager"] = usr["worker_villager"] - 1
- usr["worker_total"] = usr["worker_total"] - 1
- logAction(msg["quitVillager"] + msg["reasonHunger"])
- else
- usr["worker_army"] = usr["worker_army"] - 1
- usr["worker_total"] = usr["worker_total"] - 1
- logAction(msg["quitArmy"] + msg["reasonHunger"])
- end
- local escapedAnimal = 0
- while (usr["farm_pig"] + usr["farm_sheep"] + usr["farm_cow"] + usr["farm_chicken"]) / usr["worker_rancher"] > 1 do
- local randomize = random(1,usr["farm_pig"] + usr["farm_sheep"] + usr["farm_cow"] + usr["farm_sheep"])
- if randomize < usr["farm_pig"] then
- escapedAnimal = 1
- usr["farm_pig"] = usr["farm_pig"] - 1
- elseif randomize < usr["farm_sheep"] + usr["farm_pig"] then
- escapedAnimal = 1
- usr["farm_sheep"] = usr["farm_sheep"] - 1
- elseif randomize < usr["farm_cow"] + usr["farm_sheep"] + usr["farm_pig"] then
- escapedAnimal = 1
- usr["farm_cow"] = usr["farm_cow"] - 1
- else
- escapedAnimal = 1
- usr["farm_chicken"] = usr["farm_chicken"] - 1
- end
- end
- if escapedAnimal = 1
- logAction(msg["animalsEscaped"] .. msg["reasonNoRanchers"])
- end
- -- Check if this doesn't mess anything up after.
- end
- usr["hidden_eatTick"] = usr["hidden_eatTick"] - 1500
- end
- end
- updateCounters()
- end
- local function updateScreen() -- Basically when the entire screen changes, make it visible and stuff.
- end
- local function updateCounters() -- Pointless updating the entire screen when just a bunch of counters change.
- end
- while main["running"] == true do
- local event, param1, param2, param3 = os.pullEvent()
- if event == "mouse_click" then
- if param1 == 0 then -- Left mouse button
- if param2 >= 0 and param2 <= 1 and param3 == 0 then -- (0-1, 0) - Left button for the Leftern GUI
- if usr["main_leftGUIID"] == "Forest" then -- Forest > Mine > Farm > Ranch > Barracks
- usr["main_leftGUIID"] = "Barracks"
- elseif usr["main_leftGUIID"] == "Mine" then
- usr["main_leftGUIID"] = "Forest"
- elseif usr["main_leftGUIID"] == "Farm" then
- usr["main_leftGUIID"] = "Mine"
- elseif usr["main_leftGUIID"] == "Ranch" then
- usr["main_leftGUIID"] = "Farm"
- elseif usr["main_leftGUIID"] == "Barracks" then
- usr["main_leftGUIID"] = "Ranch"
- end
- updateScreen()
- elseif param2 >= 7 and param2 <= 8 and param3 == 0 then -- (7-8, 0) - Right button for the Leftern GUI
- if usr["main_leftGUIID"] == "Forest" then -- Forest > Mine > Farm > Ranch > Barracks
- usr["main_leftGUIID"] = "Mine"
- elseif usr["main_leftGUIID"] == "Mine" then
- usr["main_leftGUIID"] = "Farm"
- elseif usr["main_leftGUIID"] == "Farm" then
- usr["main_leftGUIID"] = "Ranch"
- elseif usr["main_leftGUIID"] == "Ranch" then
- usr["main_leftGUIID"] = "Barracks"
- elseif usr["main_leftGUIID"] == "Barracks" then
- usr["main_leftGUIID"] = "Forest"
- end
- updateScreen()
- end
- elseif param1 == 1 then -- Right mouse button "Cancel"
- -- stuff
- end
- elseif event == "timer" and param1 == main["timer"] then
- -- Handle per-tick happenings
- doGameTick()
- updateCounters()
- main["timer"] = os.startTimer(0.1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement