Alkerss

Untitled

Jun 17th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.76 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------------------------------------
  2. --[[------------ Descriptions of function calls --------------------------------------------------------------------------------
  3. -- Resm API accounts for anything that is valuable from resources to imaginery "safety" points, thus it is The economy of turtles.
  4. WiP
  5. --]]
  6. --------------------------------------------------------------------------------------------------------------------------------
  7. ---------------- Dependencies --------------------------------------------------------------------------------------------------
  8. -- Name Section:
  9. -- Declare the name library will use. Leave it alone and
  10. local Lib = {}
  11. Resm = Lib
  12.  
  13. -- Import Section:
  14. -- declare everything this library needs from outside
  15. -- FYI You can change or shorten names if you wish so.
  16.  
  17. ---- Luaj unmodified libraries. Import only needed sub-functions.
  18. -- Full list (functions): assert, collectgarbage, error, _G, ipairs, load, loadstring, next, pcall, rawequal, rawget, rawset, select, setfenv, setmetatable, tonumber, tostring, unpack, _VERSION, xpcall, require, module
  19. -- Full list (tables): coroutine, package, table, math
  20. -- local
  21. -- local
  22.  
  23. ---- CC libraries. Import only needed sub-functions.
  24. -- Full list (modified Luaj functions): getfenv, getmetatable, loadfile, dofile, print, type, string.sub, string.find, write
  25. -- Full list (modified Luaj tables): string, os, io
  26. -- Full list (new tables): os, colors, disk, gps, help, keys, paintutils, parallel, peripheral, rednet, term, textutils, turtle, vector, window
  27. -- local
  28. -- local
  29. -- local
  30.  
  31. ---- TuCoWa libraries. Import only needed sub-functions.
  32. -- Full list: Gui, Rui, Hud, Logger, Stats, Comm, Utils, Nav, Jobs, Resm, Logic, Init
  33. local Gui, Rui, Hud, Logger, Stats, Comm, Utils, Nav, Jobs = Gui, Rui, Hud, Logger, Stats, Comm, Utils, Nav, Jobs
  34.  
  35. -- no more external access after this point
  36. setfenv(1, Lib)
  37.  
  38. --------------------------------------------------------------------------------------------------------------------------------
  39. ---------------- Library wide variables ----------------------------------------------------------------------------------------
  40.  
  41. local Period = 600 -- in secs ( 600=10min, 3'600=1h, 86'400=1d, 604'800=1w, 1'814'400=3w=tournament lenght ) (tournament period = 3024 Periods)
  42.  
  43. --------------------------------------------------------------------------------------------------------------------------------
  44. ---------------- Classes -------------------------------------------------------------------------------------------------------
  45.  
  46. local UniClass = { -- WiP!!!
  47.         Type = "", -- TheWorld | Base | Farm | Turtle | Inventory | Bag | Container | Resource
  48.         Profile = {}, -- set of randomized defaults.
  49.         Meta = {}, -- Military for TheWorld, Upgrades for Bases and Farms, Hierarchy for Turtles, Item|Fluid|Energy for Containers and Resources + usual meta.
  50.         Position = {}, -- X,Z,Y,F for the back buttom left corner relative to its parent or SlotId.
  51.         Size = {} or 0, -- X,Z,Y size in blocks or amount in stack if inside.
  52.         TimeofBirth = 0,-- mostly used for registering future objects.
  53.        
  54.         Parent = "", -- TheWorld object is the only one that has Parent = nil
  55.         Children = {}, -- Table of children UniClass objects, things within this object. For Inventory|Bag|Container index = SlotId.
  56.        
  57.         PartList = {}, -- For Bases & Farms & Turles & Inventories its the resources collected if destroyed including inside Containers for Flows.
  58.         Value = 0, -- For Inventory|Bags|Containers|Resources its the supply value, for TheWorld|Base|Farm|Turtle its cached sum of PartList supply value
  59.         Flows = {       -- For objects that generate something on their own (like Turtle generates WorkSeconds)
  60.                 InputList = {
  61.                         ResourceId = 0, -- May be also a Container with a specific content or a virtual Point
  62.                         AvgAmount = 0,
  63.                         StDev = 0,
  64.                         Position = "", -- UniqId from PartList pointing to valid a Inventory | Bag | Container
  65.                         },
  66.                 OutputList = {
  67.                         ResourceId = 0, -- May be also a Container with a specific content or a virtual Point
  68.                         AvgAmount = 0,
  69.                         StDev = 0,
  70.                         Position = "", -- UniqId from PartList pointing to valid a Inventory | Bag | Container
  71.                         },
  72.                 Cycle = 0, -- Lenght of one cycle to transform InputList into OutputList
  73.                 FlagRun = true, -- True: flows until input is valid. False: flows until Inventory is full. Nil: flows only if output inventory is empty
  74.                 FlagInput = true, -- True: Input is taken at start. False: Input is taken at the end. Nil: Input is taken somewhere in middle.
  75.                 FlagOutput = true,      -- True: Output is made at start. False: Output is made at the end. Nil: Output is made somewhere in middle.
  76.                 Type = 0, -- Different types of flows can run in parralel, but only one flow per each type.
  77.                 Priority = 0, -- 1 is higher priority over 2, and only 0 will stop any non-0 priority flow.
  78.                 },
  79.  
  80.         TimeUpdated = 0, -- Time of last change
  81.         }
  82.  
  83.  
  84. --------------------------------------------------------------------------------------------------------------------------------
  85. ---------------- Public functions ----------------------------------------------------------------------------------------------
  86.  
  87. function GetPriceSupply() end
  88. function AddSupply() end
  89. function ClearSupply() end
  90.  
  91. function GetPriceDemand() end
  92. function AddDemand() end
  93. function ClearDemand() end
  94. function ClearMyDemand() end
  95.  
  96. function GetPriceEq() end
  97. function CloseDeal() end
  98.  
  99. function ReserveDemand() end
  100. function CollectDemand() end
  101. function ClosePeriod() end -- resets Deallist
  102.  
  103. --------------------------------------------------------------------------------------------------------------------------------
  104. ---------------- Private functions ---------------------------------------------------------------------------------------------
  105.  
  106. -- none
  107.  
  108. --------------------------------------------------------------------------------------------------------------------------------
  109. ---------------- Details & Notes -----------------------------------------------------------------------------------------------
  110.  
  111. --[[ How does it work?
  112.  
  113. Process: Exchange -- Add value by exchange.
  114. Goal: Build a lot Turtles! -- The only demand is a new turtle.
  115. Optimization: Growth -- Decisions are made by maximizing Added value per period.
  116.  
  117. There are Valuables (Resources, Space, Points, Containers, Time) that can be used (otherwise they Depreciate)
  118. there are Entities (Turtles, Bases) that can own Valuables by holding them (mostly in Containers),
  119. there are Entities (Turtles, Farms) that can make ("make"="exchange"="add value") Valuables and Entities.
  120.  
  121. --[=[ Value & Amount
  122.  
  123. Value is measured in "virtual cookies". Resources and Points can be exchanged for a given value, but Resources and Space can be lended for a given interest (value/time). Valuables have a dynamic value that is assigned according to its demand and supply.
  124.  
  125.         There is always a demand for a brand new main turtle for 1'000'000 cookies. Demand value is calculated like in the following example. Lets suppose that Resource Fuel has a supply value of 20, Resource "Coal" has a Demand value of 800, and it can be acquired by Job "Burn Wood". In Job #1 description says that for 1 Coal there is needed 10+20 fuel and 1 Wood. Because fuel has a price (20), the unallocated value is 800-20*(10+20) = 200, therefore the Demand value for Resource "Wood" becomes 200. Demand is virtual (heurestic) and may not be accurate but is the best we have.
  126.  
  127.         Supply value is determined at the point of production. Supply value is calculated simply as a sum of input Supply value divided by amount outputted. Bear in mind that Supply value used in decision making is heurestic and thus may deviate from real Supply value used for Exchange value. If there is more than 1 type of item outputted, then the values are distributed proportionally to Demand values. Supply value lags in time but lets say that we are ok with that.
  128.        
  129.         Exchange value is determined at the point of exchange. Sum of Exchange values is proportionally between sum of Demand values and sum of Supply values. For statistics and heurestics it is advised to use Exchange value. Fun Fact: we can say that parties negotiated for a middle price to evenly and honestly distribute the Added value. What a perfect free market economy!
  130.        
  131. Amount is measured in items/mB/1RFs for Resources, in blocks for Space and in "grams" for Points. Demand and Supply always comes in Amount, and there may be different combinations of Demand/Supply and Amount at the same time per each Valuable.
  132.  
  133.         Amount Demanded is simply the Amount of Valuable that has been demanded. If Amount Demanded can be satisfied with Amount Supplied then the deal closes, both Amount Demanded and Amount Supplied are cleared and written into statistics and heurestics. If Amount Demanded is not satisfied, then it hangs and waits to be cleared by either someone Supplying it or by creator cancelling it. If turtle or base demands more than once, then both Demands are combinded in a complex way (simply: not by sum, but by max).
  134.        
  135.         Amount of Supply is either a present Supply or a future Supply. Present Supply is ready to be taken and depreciates over time (by paying rent to the owner of Container). Future Supply needs to be waited for but doesn't depreciates over time, yet.
  136.        
  137.         Amount cleared is the Amount that was successfully exchanged.
  138.  
  139. --]=]
  140. --[=[ (WiP!) Owning. Interest & depreciation rate
  141.  
  142. Interest rate is valuation of opportunity cost for other Entities for not being able to use the Valuable. Any Entity that has reserved a Valuable exchanges it's future Added Value for value of Interest rate for a given time period in future.
  143.  
  144. Depreciation is valuation of rent for Container or Space for its holder. Valuables that lays in Containers or Space for a long time will depreciate a lot of value away, thus will be cheaper until a point where someone will be ready to buy it (or discard if value manages to go into negative).
  145.  
  146.         Example: Lets say that we have a base with some infrastructure (computer, wires, defence, etc.) with a chest that holds bucklet that holds water. The base has a lot of Valuables reserved (all of its infrastructure) therefore it has to pay interest of, lets say, 100c per period (100c/p). It collects exchangable value from renting out Space to its 0 farms and 4 chests (1 chest is double sized), and each chest relative to its space occupied has to transfer 100c/p together, or 20c/p each (or 40c/p for double-sized one). Our chest has to transfer value for rent of 20c/p, therefore it collects it from its contents relative to its space occupied (stack of 1 transfers the same amount as stack of 64 together). Lets say that chest holds our water bucklet, 2 full stacks of cobblestone and 1 sole cobblestone. The sole cobblestone has to transfer 5c/p, therefore it depreciates by 5c/p until it reaches 0, but the full stack of cobblestone depreciates by 5c/p altogether or by 0.078c/p each cobblestone. The bucklet of water also has to transfer 5c/p, but it has content, therefore it doesn't depreciate but collects it from it's contents first. The only content is water so the water will depreciate 5c/p. If water reacher value 0, then bucklet cannot collect transferable value anymore so it will start to depreciate itself.
  147.  
  148. Owning chains can be like this, everything optional except TheEverything and Resource:
  149. TheEverything, Base, Farm, Inventory, Bag, Bag, Bag, ..., Container, Resource.
  150.  
  151.         TheEverything has all the placeable blocks in the world. Base, Farm and Turtle is a bunch of blocks, Turtle always is exactly 1 block and that is a Inventory. Bag is like "Bag of Holding", that is a inventory within inventory. Container is something like bucklet, energy cell or compressed cobblestone. Resource is the resource within Container, Inventory or placed as a single block. Resources may stack within Containers and Inventories. If Resource are dropped in TheEverything, its considered deleted and don't register in the Resm, but individual Jobs may take drops into account (like collection saplings in tree farms).
  152.        
  153. --]=]
  154. --[=[ (WiP!) Making. Jobs
  155. --]=]
  156. --[=[ Classes
  157.  
  158. Turtle = { Universal, Worker, Major, Computer, President }
  159. Base = { Central, Proximity }
  160. Farm = { Surface, Underground }
  161. Valuables = { Resource, Space, Point, Container, Time }
  162.  
  163. --]=]
  164. --]]
Advertisement
Add Comment
Please, Sign In to add comment