0 Members and 1 Guest are viewing this topic.
<CaptainJean-Luc> Doc: You have ruthlessly high standards.
Interested, not sure on the whole site doing it as it'd be very difficult on organising it.Not sure I'd join though as I'm not one for joining big things which involve stats things in the game, I prefer just to write only. A good idea though, just the size looks a little ambitious to me.
interesting, and it looks nicely thought out in a game designy way... Though question, Is it going to be Text based, or Picture based, or a hybrid of the 2?
Total costs of all resources for all buildingsTotal production of all buildingsIf total production+stores is greater than total costs we're doneElse begin limited resource calculation
Check each resource cost vs supplies. If cost is greater than supply add to limited resource list.Go through limited resource list For each resource look at supply drains calculate supply proportion. (I.E. Attempting to draw 100 oil, have 90 supply = 90% proportion) For each building type that draws this resource go through resource costs/productions For each resource lower total resource costs to meet supply proportion If a resource cost lowered such is on the limited list check if this lowered cost is within supply levels. If so remove from limited list For each resource produced lower supplies by proportion (WARNING: Only lower -produced- supplies by proportion, not total supplies!) If a resource supply is lowered below total resource costs and it is not already on the limited resource list, add to limited list
Base supplies: 100 pop.Produced supplies: 100 oil, 50 fuel, 200 electricity.Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.Total costs: 75 pop, 50 oil, 50 fuel, 100 electricity.Costs under production, we're done.
Base supplies: 100 pop.Produced supplies: 100 oil, 50 fuel, 200 electricity.Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.
(limited resource list = electricity)electricity draw 250, supply 200 = 80% electricity supply. Oil rigs use electricity Lower electricity cost to 80%(40 instead of 50), total cost now 240, still above supply, ignore list Lower pop cost to 80%(20 vs 25), total cost now 70, wasn't above supply, ignore list Lower oil production to 80%(80 vs 100), total supply now 80, supply still over cost, ignore list. Oil refinery uses electricity Lower electricity cost to 80%(40 instead of 50), total cost now 230, still above supply, ignore list Lower pop cost to 80%(20 vs 25), total cost now 65, wasn't above supply, ignore list Lower oil cost to 80%(40 vs 50), total cost now 40, wasn't above supply, ignore list Lower fuel production to 80%(40 vs 50), total supply now 40, costs now greater, add to limited resource list (now: electricity, fuel) Housing uses electricity Lower electricity cost to 80%(120 vs 150), total cost now 200, supply meets cost, remove electricity from limited resource list (now: fuel)Fuel draw 50, supply 40 = 80% fuel supply Oil powerplant uses fuel Lower fuel cost to 80%(40 vs 50), total cost now 40, supply meets cost, remove fuel from limited resource list list (now: blank) Lower pop cost to 80%(20 vs 25), total cost now 60, wasn't above supply, ignore list Lower electricity production to 80%(160 vs 200), total supply now 160, cost now greater add to limited resource list (now: electricity)electricity draw 200, supply 160 = 80% supply.
Alright folks it's algorithm time. For those of you interested in mod/game programing this will be a good intro to things you have to learn to do. Algorithm design along with a good grasp of the mathematics behind game design are absolutely critical. If anyone is interested in these things let me know in here and I'll look to making a site feature, maybe even a series of them. Now to our algorithm here.First thing you need to do is define the problem. What are you trying to solve? What obstacles are there? Sometimes you have to also define what restrictions you have. Usually this is in terms of performance/time limitations. In this case CPU power won't be limited and timing is not critical. This isn't a real time game where you are planning on doing this calc 10 times per second. It can be wasteful.So our problem: We need to define how to distribute (potentially limited) resources of various types to buildings. The largest issue is some resources being used may be being produced by the very buildings that are limited. You could even end up with a supply loop.Spoiler for Hiden: Now we begin our pseudo code, psuedo code is essentially human readable stuff that can easily be converted to actual code.Code: [Select]Total costs of all resources for all buildingsTotal production of all buildingsIf total production+stores is greater than total costs we're doneElse begin limited resource calculationThis is a quick check, if it matches here we don't have to think anymore because it's done. However if this fails we get more interesting. And we have to begin fun times.Code: [Select]Check each resource cost vs supplies. If cost is greater than supply add to limited resource list.Go through limited resource list For each resource look at supply drains calculate supply proportion. (I.E. Attempting to draw 100 oil, have 90 supply = 90% proportion) For each building type that draws this resource go through resource costs/productions For each resource lower total resource costs to meet supply proportion If a resource cost lowered such is on the limited list check if this lowered cost is within supply levels. If so remove from limited list For each resource produced lower supplies by proportion (WARNING: Only lower -produced- supplies by proportion, not total supplies!) If a resource supply is lowered below total resource costs and it is not already on the limited resource list, add to limited listThis -should- be all you need to do. Lets do a run through this with some simulation.Lets assume we have no warehoused resources. We have 100 pop. We have oil rigs trying to draw 50 electricity, 25 pop, produce 100 oil. Oil refineries trying to draw 50 electricity, 25 pop, 50 oil, produce 50 fuel. Oil powerplants trying to draw 25 pop, 50 fuel produce 200 electricity.Code: [Select]Base supplies: 100 pop.Produced supplies: 100 oil, 50 fuel, 200 electricity.Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.Total costs: 75 pop, 50 oil, 50 fuel, 100 electricity.Costs under production, we're done.Alright first run done. Now lets assume we add in houses trying to draw 150 electricity.Code: [Select]Base supplies: 100 pop.Produced supplies: 100 oil, 50 fuel, 200 electricity.Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity.Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.Now we enter our loop.Code: [Select](limited resource list = electricity)electricity draw 250, supply 200 = 80% electricity supply. Oil rigs use electricity Lower electricity cost to 80%(40 instead of 50), total cost now 240, still above supply, ignore list Lower pop cost to 80%(20 vs 25), total cost now 70, wasn't above supply, ignore list Lower oil production to 80%(80 vs 100), total supply now 80, supply still over cost, ignore list. Oil refinery uses electricity Lower electricity cost to 80%(40 instead of 50), total cost now 230, still above supply, ignore list Lower pop cost to 80%(20 vs 25), total cost now 65, wasn't above supply, ignore list Lower oil cost to 80%(40 vs 50), total cost now 40, wasn't above supply, ignore list Lower fuel production to 80%(40 vs 50), total supply now 40, costs now greater, add to limited resource list (now: electricity, fuel) Housing uses electricity Lower electricity cost to 80%(120 vs 150), total cost now 200, supply meets cost, remove electricity from limited resource list (now: fuel)Fuel draw 50, supply 40 = 80% fuel supply Oil powerplant uses fuel Lower fuel cost to 80%(40 vs 50), total cost now 40, supply meets cost, remove fuel from limited resource list list (now: blank) Lower pop cost to 80%(20 vs 25), total cost now 60, wasn't above supply, ignore list Lower electricity production to 80%(160 vs 200), total supply now 160, cost now greater add to limited resource list (now: electricity)electricity draw 200, supply 160 = 80% supply.And we call it quits here. I can recognize a death spiral when I see one. This will continue until all production is at 0% because we have a resource loop with no outside influence. Looks like our algorithm failed (as I suspected it would from the beginning). We'll have to devise a way out of this death loop I can see a couple ways out but can anyone else?Next time: After I sleep and get back up, devising ways out of this predicament.P.S. thinking about it slightly the death spiral won't actually reach 0%, it will loop forever constantly getting smaller and smaller until finally the computer decides to lock up. This is called an infinite loop and is the bane of all devs everywhere. Learning to recognize warning signs early on for these is a very important skill.
so, you now gain turns by waiting, I was personally thinking of something else (just let me know what you think of it)for example: there are 6 people who play the game. one is online and builds something using 5 turns, Instead of losing these turns the other players gain them. so: 5(turns/5(players (not counting the one who used it)=1 turn for every player.this mean that saving up turns is not good because it would slow down the game.new players would gain 50 turnsedit.that loop, what if you are able to automaticly buy extra stuff the other players have so the other players gain some credits and you get your whatever you need.this is not fail safe. so it might be a option to set in a "home planet" (this is a Future game... so why not) you will buy from this homeplanet whatever you need for high amounts of credits. until you have solved this loop military units will be disbanded because you don't have money to pay them and you will only be able to build the buildings that are needed to solve this loop (a power plant in this case)you will probaly have debts in the end of this but you will just get your taxes and slowly rebuild your military.
Hmm Interesting I'm going into the field of game design myself (though Im still 2 years away from graduating HS (Staying for an extra year for some extra maths)) this should be fun looking over the psudo code.
Total supplies: 100 pop, 100 oil, 50 fuel, 200 electricity, 200 pop support.Total costs: 75 pop, 50 oil, 50 fuel, 250 electricity.
Total draw 250, supply 200 = 50 unit overage Oil rigs, Oil refineries, Housing using electricity Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50% Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut. Housing are using 150 to produce 200 pop support, only 100 needed, can be cut up to 50%.
Our safe cut list is drawing 200, we need to cut 50 which is 25%. Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75) Housing can be cut by 25% do so (electricity cost reduced by 37.5 to 200, pop support reduced by 50 to 150) Electricity cost is within supply. Cave Johnson, we're done here.
Total draw 250, supply 200 = 50 unit overage Oil rigs, Oil refineries, Housing using electricity Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50% Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut. Housing are using 150 to produce 150 pop support, only 100 needed, can be cut up to 33.3...% (NOTE: because of how number are handled in computing you probably don't want to store this % and retrieve it later as it may be slightly wrong. Look up or ask me about floating point computing for details.) Our safe cut list is drawing 200, we need to cut 50 which is 25%. Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75) Housing can be cut by 25% do so (electricity cost reduced by 37.5 to 200, pop support reduced by 37.5 to 112.5) Electricity cost is within supply. Cave Johnson, we're done here.
Total draw 250, supply 200 = 50 unit overage Oil rigs, Oil refineries, Housing using electricity Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50% Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut. Housing are using 150 to produce 125 pop support, only 100 needed, can be cut up to 20% Our safe cut list is drawing 200, we need to cut 50 which is 25%. Oil rigs can be cut by 25% do so (electricity cost reduced by 12.5 to 237.5, oil production reduced by 25 to 75) Housing cannot be cut by 25%, only 20% do so (electricity cost reduced by 30 to 207.5, pop support reduced by 25 to 100)
Total draw 250, supply 200 = 50 unit overage Oil rigs, Oil refineries, Housing using electricity Oil rigs are using 50 to produce 100 oil, only 50 oil needed can be cut up to 50% Oil refineries are using 50 to produce 50 fuel, 50 needed cannot be cut. Housing are using 150 to produce 125 pop support, only 100 needed, can be cut up to 20% Our safe cut list is drawing 200, we need to cut 50 which is 25%. Sort cut order by percentage( housing, then oil) Housing cannot be cut by 25%, only 20% do so (electricity cost reduced by 30 to 220, pop support reduced by 25 to 100) As this didn't meet cut percentage, recalculate cut percentage for remaining items. current safe cut list is drawing 50, we need to cut 20 which is 40%. Oil rigs can be cut by 40% do so (electricity cost reduced by 20 to 200, oil production reduced by 40 to 60) Electricity draw is within supply, we're done here.
Total supplies: 100 pop, 60 oil, 50 fuel, 200 electricity, 100 pop support.Total costs: 65 pop, 50 oil, 50 fuel, 200 electricity.
Calculate total costsCalculate total productionCalculate total supply (production + stored)Create list of resources where supply is less than costFor each limited resource Calculate overdraw (cost - supply) Create list of cuttable building types (buildings that produce more than is needed to meet cost) Sort list by percentage cuttable, smallest to largest Calculate cost from the cuttable buildings (total cost) Calculate needed cut percentage (overdraw / total cost from cuttable buildings) For each building type (go through in sort order) If cuttable percent greater than or equal to needed cut percent Decrease all costs from building type by cut percentage Decrease all production from building type by cut percentage If cuttable percent less than needed cut percent Decrease all costs from building type by cuttable percentage Decrease all production from building type by cut percentage Recalculate overdraw, cost from cuttable buildings, and needed cut percentage Recalculate overdraw. If overdraw = 0 move to next limited resource.
Calculate total costsCalculate total productionCalculate total supply (stored resources + supply of electricity)Create list of resources where supply is less than costFor each limited resource Calculate supply percentage (supply / cost) For each building type consuming resource Reduce all costs by percentage Reduce all production by percentage If produces electricity recalculate supply, if new supply is lower than cost add electricity to limited resources list unless electricity is already on the list.Subtract all costs from suppliesAdd all production to suppliesCheck storage (this needs to be expanded)
resources where supply is lest than cost: Oil, Fuel, Electricity.For Oil Supply percent: 0% Oil refinery trying to use oil Reduce pop cost to 0% (now 50 total cost) Reduce oil cost to 0% (now 0 total cost) Reduce electricity cost to 0% (now 200 total cost), remove from limited resource list as supply now meets demand. Reduce fuel production to 0% (now 0 total production) No other uses, remove oil from limited listFor Fuel Supply percent: 0% Oil powerplant trying to us fuel Reduce pop cost to 0% (now 25 total cost) Reduce fuel cost to 0% (now 0 total cost) Reduce electricity production to 0% (now 0 total production) Producing electricity so Reduce electricity supply to 0% (now 0 total supply) Electricity supply below cost, not on limited list, add to limited list No other uses, remove fuel from limited listFor Electricity Supply percent: 0% Oil rigs trying to use electricity reduce pop cost to 0% (now 0 total cost) reduce electricity cost to 0% (now 150 total cost) reduce oil production to 0% (now 0 total production) Housing trying to use electricity reduce electricity cost to 0% (now 0 total cost) No other uses, remove electricity from limited list
resources where supply is lest than cost: Oil, Fuel, Electricity.For Oil Supply percent: 10% Oil refinery trying to use oil Reduce pop cost to 10% (now 52.5 total cost) Reduce oil cost to 10% (now 5 total cost) Reduce electricity cost to 10% (now 205 total cost) Reduce fuel production to 10% (now 10 total production) No other uses, remove oil from limited listFor Fuel Supply percent: 10% Oil powerplant trying to use fuel Reduce pop cost to 10% (now 30 total cost) Reduce fuel cost to 10% (now 5 total cost) Reduce electricity production to 10% (now 20 total production) Producing electricity so Reduce electricity supply to 10% (now 20 total supply) Electricity supply below cost, already on limited list, move along No other uses, remove fuel from limited listFor Electricity Supply percent: 20/205(about 9.7%)
Calculate total costsCalculate total productionCalculate total supply (stored resources + production of electricity)Create list of all running buildings tied to "run percentage" set run percentage to 100% for all.Create list of resources where supply is less than costPut electricity at the end if it's on the list (why? Because my intuition says to)For each limited resource Calculate supply percentage (supply / cost) For each building type consuming resource If current "run percentage" greater than supply percentage Reduce "run percentage" to supply percentage If building produces electricity Reduce electricity supply to percentage Add electricity to limited resources list if new supply is below costs and not already on the list.Recalculate costs, production based off run percentages, round down to avoid fractional values (may allow free production, may increase costs sometimes)Subtract all costs from suppliesAdd all production to suppliesCheck storage (this needs to be expanded)
resources where supply is lest than cost: Oil, Fuel, Electricity.For Oil Supply percent: 10% Oil refinery trying to use oil Set oil refinery "run percent" to 10%. No other uses, remove oil from limited listFor Fuel Supply percent: 10% Oil powerplant trying to use fuel Set oil powerplant run level to 10% Producing electricity so Reduce electricity supply to 10% (now 20 total supply) Electricity supply below cost, already on limited list, move along No other uses, remove fuel from limited listFor Electricity Supply percent: 8% (muuuuch cleaner numbers this time) Oil rig trying to use electricity Set oil rig run percent to 8% Oil refinery trying to use electricity Set oil refinery run percent to 8% Housing trying to use electricity Set housing run percent to 8% No other uses, remove electricity from limited listRecalculate costs, production
resources where supply is lest than cost: Oil, Fuel, Electricity.For Oil Supply percent: 16% Oil refinery trying to use oil Set oil refinery "run percent" to 16%. No other uses, remove oil from limited listFor Fuel Supply percent: 8% Oil powerplant trying to use fuel Set oil powerplant run level to 8% Producing electricity so Reduce electricity supply to 8% (now 16 total supply) Electricity supply below cost, already on limited list, move along No other uses, remove fuel from limited listFor Electricity Supply percent: 6.4% Oil rig trying to use electricity Set oil rig run percent to 6.4% Oil refinery trying to use electricity Set oil refinery run percent to 6.4% Housing trying to use electricity Set housing run percent to 6.4% No other uses, remove electricity from limited listRecalculate costs, production
Player_IDUsernamePasswordEmpire_ID
Empire_IDEmpire_NamePopulationRes_FoodRes_OilRes_FuelBld_FarmBld_OilWellBld_OilRefineryBld_OilPowerplantBld_HousingBld_WarehouseBld_Settlement
Oooooohhh, see I thought it was an RP game you were talking about initially! Yeah this I can see happening. *Mazder gives his seal of approval.*
Variables are fun I've got the RP Game version all set down