There are 39 previous versions of this script.
Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)
// ==UserScript==
// @name SG Turn Automater
// @namespace http://userscripts.org/scripts/show/39195
// @include http://www.dailywheel.com/thegame/game.php?page=construct
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==
// By Brian Ballsun-Stanton. Public Domain.
/* version 0.27
0.27
Major fixes to how multiple-turn burning works.
0.26
Unstaffed warning
0.25
Bugstomp
0.24
more bootstrap friendly variables added
0.23
light post bug fixed.
0.22
Auto weapon sales
0.21
Bugstomping
0.20
Fixing underbuilding. Kinda
0.19
Nuke stuff
0.18
Fixed bug in screaming population alertbox.
0.17
More bugstomping.
0.16
Auto-get setup variables.
0.15
made "assume barrack full" flag - note, you still need excess for militia.
0.14
Added stateful turn-burning. May god have mercy on my soul.
0.13
auto-mining. Nuke focus path hooks.
0.12
Advanced labs
0.11
Fiddling with construction numbers.
0.10
More bugstomping.
Fixed workers.
Fixed min-max defense construction.
0.9
Bugstomping.
0.8
Moved to a google AJAX library. YAY!
0.7
added max construction
0.6
more useful fuel management
0.5
added alert to indicate wasted workers.
fixed bug with detecting firepits.
0.4
added auto-sell and auto-buy.
set SELL_BS to amount of BS you want to sell.
set BUY_FOOD=true to buy food that isn't coverd by food producing structures. same with disp.
set BS_TO_CEP=.30 if you're a goof
0.3
Refined randomness for defensive structure building
0.2
Added CSS refinements
Started Changelog
*/
// recruitRadiusMultiplier = ((Max Busses*50)/Circumference)*TURN_LENGTH
// pop_disp_use_ratio = disposables consumed by people / population
// fuel_ratio = Fuel per day / camp circumference
// CEP*((1+(1/3))*10) = BS purchased
var debug=false;
// Initial setup vars
var ADVANCED_LAB=false;
var BARRACKS_PCT_FILLED=1;
var BUILD_BS=true;
var BUILD_DISP=false;
var BUILD_FOOD=false;
var BUILD_FOOD_FOR_BARRACK_SPACE=0;
var BUILD_FUEL=false;
var BUILD_GOLD=true;
var BUILD_LANDFILL=true;
var BUILD_LIGHTS=true;
var BUILD_POST=true;
var BUILD_POWER=false;
var BUILD_TIT=true;
var BUILD_URA=false;
var BUILD_WALL=true;
var BUY_BS=false;
var BUY_DISP=true;
var BUY_FOOD=true;
var COMM_RELAY_EXCESS=0;
var EXCESS_BS=0;
var EXCESS_DISP=-18000;
var EXCESS_FOOD=0; //Increase this by at least the number of Army+Militia you want to support.
var EXCESS_FUEL=0;
var EXCESS_POWER=00;
var GALLONS_OF_FUEL_TO_DEVOTE_TO_POWER_PER_REFINERY=20;
var HUT_MULT=2;
var INSTALL_PATRIOTS=false;
var IS_GOOFBALL=true;
var MAX_BS_SURPLUS=.25;
var MAX_CONSTRUCTION_WORKERS=false; //hardcode if you want it to be other than max available.
var MAX_DEFENSIVE_STRUCTURE=3;
var MEALS_PER_POPULATION=.25;
var MIN_DEFENSIVE_STRUCTURE=1;
var NUKE_PATH=false;
var RESERVED_POPULATION_FOR_MILITARY=0;
var SACK_EXPLORE_FOR_EXCESS_BUILD=false;
var SELL_BS=40000; //pure CEP excess.
var SELL_BS_FOR_CEP_FOR_FOOD_AND_DISP=true;
var SELL_WEAPONS=false;
var SET_EXPLORERS=false; //set this to a value if you want to hard-code it, leave it at false otherwise
var SET_RECRUITERS=false; //set this to a value if you want to hard-code it, leave it at false otherwise
var SWAP_EXPLORE_RECRUIT_ORDER=false;
var TURN_LENGTH=2;
var WASTE_DIVISOR=3;
var WORKER_PAYMENT=.01;
/* ID, name, Bldrs, #2Bld, Bldgs, % of, Min, sort, Workrs, Disp, BS, Power, Food, Land Units
Need Per Pop Bld order
Pop
0 1 2 3 4 5 6 7 8 9 10 11 12 13
*/
var buildings = {
"alab": [ 27, "Advanced Labs", 100, 0, 30, 0.00, 0, 5, 0, 0, 0, 0, 0, 10], //26
"ama": [ 37, "Advanced Military Academy", 30000, 0, 1, 0.000, 0, 36, 0, 0, 0, 0, 0, 0], //35
"arm": [ 33, "Armories", 15, 0, 50, 0.400, 0, 32, 0, 0, 0, 0, 0, 10], //31
"racks": [ 18, "Barracks", 4, 0, 50, 0.150, 0, 24, 0, 0, 0, 0, 0, 4], //18
"class": [ 9, "Classroom", 8, 0, 1, 0.000, 0, 19, 0, 0, 0, 0, 0, 3], //9
"comfac": [ 11, "Communications Facilities", 10, 0, 1, 0.000, 0, 20, 0, 0, 0, 0, 0, 4], //11
"duster": [ 40, "Duster", 5, 0, 1, 0.000, 0, 37, 0, 0, 0, 0, 0, 4], //36
"fac": [ 15, "Factories", 16, 0, 2, 0.360, 0, 17, 0, 0, 0, 0, 0, 2], //15 - auto, if at least 1 built
"farm": [ 10, "Farms", 16, 0, -1, 0.000, 0, 2, 0, 0, 0, 0, 0, 20], //10 - auto, at least 1
"fill": [ 25, "Landfill", 2, 0, -1, 1.000, 0, 14, 0, 0, 0, 0, 0, 2], //24 - auto
"firepit": [ 6, "Firepit", 1, 0, -1, 0.000, 0, 3, 0, 0, 0, 0, 0, 1], //1 - auto, if at least 1 built
"fuelref": [ 19, "Fuel Refinery", 6, 0, 1, 0.00, 0, 8, 0, 0, 0, 0, 0, 4], //19 - auto
"garage": [ 16, "Garage", 10, 0, 1, 0.005, 0, 22, 0, 0, 0, 0, 0, 6], //16 - auto
"garden": [ 5, "Garden", 3, 0, -1, 0.000, 0, 4, 0, 0, 0, 0, 0, 1], //6 - auto, if at least 1 built
"gasgen": [ 23, "Gas Generator", 16, 0, -1, 0.000, 0, 9, 0, 0, 0, 0, 0, 2], //22 - auto, if at least 1 built
"gold": [ 34, "Gold Mine", 40, 0, 1, 0.000, 0, 33, 0, 0, 0, 0, 0, 10], //32
"hang": [ 31, "Hangars", 10, 0, 1, 0.035, 0, 30, 0, 0, 0, 0, 0, 5], //29
"hut": [ 17, "Storage Hut", 4, 0, 1, 0.05, 0, 23, 0, 0, 0, 0, 0, 1], //17 - auto
"incin": [ 26, "Incinerator", 10, 0, 6000, 1.000, 0, 13, 0, 0, 0, 0, 0, 2], //25
"labs": [ 7, "Laboratories", 6, 0, 4, 0.20, 0, 16, 0, 0, 0, 0, 0, 1], //7
"largegen": [ 13, "Large Generator", 8, 0, -1, 0.000, 0, 10, 0, 0, 0, 0, 0, 2], //13 - auto, if at least 1 built
"light": [ 14, "Light Posts", 1, 0, 1, 0.00, 0, 21, 0, 0, 0, 0, 0, 0], //14
"lot": [ 32, "Lots", 5, 0, 1, 0.035, 0, 31, 0, 0, 0, 0, 0, 15], //30
"medfac": [ 24, "Medical Facility", 16, 0, 1500, 0.000, 0, 12, 0, 0, 0, 0, 0, 15], //23
"post": [ 28, "Guard Posts", 4, 0, -1, 0.000, 0, 28, 0, 0, 0, 0, 0, 1], //27 - auto
"recfac": [ 21, "Recreation Facilities", 3, 0, 400, 0.000, 0, 26, 0, 0, 0, 0, 0, 0], //21
"recy": [ 8, "Recycling Plant", 8, 0, -1, 0.000, 0, 15, 0, 0, 0, 0, 0, 2], //8 - auto at least 1
"relay": [29, "Communications Relays ", 2, 0, -1, 0.000, 0, 0, 0, 0, 0, 0, 0, 1], //0 - auto
"shelter1": [ 1, "Shelter Level 1", 2, 0, 6, 0.000, 0, 7, 0, 0, 0, 0, 0, 1], //2
"shelter2": [ 2, "Shelter Level 2", 3, 0, 8, 0.000, 0, 6, 0, 0, 0, 0, 0, 1], //3
"shelter3": [ 3, "Shelter Level 3", 5, 0, 20, 1.050, 0, 1, 0, 0, 0, 0, 0, 2], //4
"smallgen": [ 12, "Small Generator", 4, 0, -1, 0.000, 0, 11, 0, 0, 0, 0, 0, 1], //12 - auto, if at least 1 built
"tit": [ 35, "Titanium Mine", 40, 0, 1, 0.000, 0, 34, 0, 0, 0, 0, 0, 10], //33
"ura": [ 36, "Uranium Mine", 40, 0, 1, 0.000, 0, 35, 0, 0, 0, 0, 0, 10], //34
"vault": [ 41, "Gold Vault", 10, 0, 1, 0.000, 0, 38, 0, 0, 0, 0, 0, 5], //37
"wall": [ 4, "Wall", 4, 0, -1, 0.000, 0, 18, 0, 0, 0, 0, 0, 0], //5 - auto
"weather": [ 20, "Weather Station", 4, 0, 1, 0.000, 0, 25, 0, 0, 0, 0, 0, 2], //20
"wire": [ 30, "Barbed Wire", 2, 0, -1, 0.000, 0, 29, 0, 0, 0, 0, 0, 0] //28 - auto
};
// Don't edit.
var setup = {"MAX_BUSSES": GM_getValue("MAX_BUSSES",0),
"CIRCUMFERENCE": GM_getValue("CIRCUMFERENCE",0),
"DISPOSABLES_CONSUMED_BY_PEOPLE": GM_getValue("DISPOSABLES_CONSUMED_BY_PEOPLE",0),
"POPULATION": GM_getValue("POPULATION",0),
"FUEL_PER_BUS_DAY": GM_getValue("FUEL_PER_BUS_DAY",0),
"IS_GOOFBALL": IS_GOOFBALL};
var POP_DISP_USE_RATIO=setup['DISPOSABLES_CONSUMED_BY_PEOPLE']/setup['POPULATION'];
var recruitRadiusMultiplier = ((setup['MAX_BUSSES']*50)/setup['CIRCUMFERENCE']);//*TURN_LENGTH;
var FUEL_RATIO=setup['FUEL_PER_BUS_DAY']/setup['CIRCUMFERENCE'];
if (setup['IS_GOOFBALL']){
var BS_TO_CEP = 30000/1000000;
var CEP_TO_FOOD = 20;
var CEP_TO_BS = 294/22;
} else {
var BS_TO_CEP = 15000/1000000;
var CEP_TO_FOOD = 20;
var CEP_TO_BS=294/22;
}
//Get random page elements
var population, relays, maxAvail, radius, recruits, workers=0, goldAvail=0, titAvail=0, uraAvail=0, turns, stored_bs, full_bs, workingPopulation, sortBld, burn=GM_getValue("burn",0);
if ($("font :contains('Population:')").html() == null)
population = GM_getValue("POPULATION",0);
else
population = parseInt($("font :contains('Population:')").html().replace(/,/g,"").match(/ [\d]+/g));
if ($("font :contains('Needed Immediately')").html() != null)
buildings['relay'][6] = parseInt($("font :contains('Needed Immediately')").html().replace(/,/g,"").match(/[\d]+/g) || 0);
if (BUILD_WALL)
buildings['wall'][6] = parseInt($("td > font > b > :contains('Still Needed:') ~ font > b > font").html().replace(/,/g,"").match(/ [\d]+/g) || 0);
land = parseInt($("font :contains('Land:')").html().replace(/,/g,"").match(/ +[\d]+/g) || 0);
maxAvail = parseInt($("font :contains('including currently assigned')").html().replace(/,/g,"").match(/ +[\d]+ /g) || 0);
radius = Math.round(Math.pow((land/4),.5));
recruits = Math.floor((radius*recruitRadiusMultiplier*8)/50)*50+1;
var suppliesPattern = /Supplies:([0-9]+)[^0-9]+([0-9]+)%/g;
var supp=suppliesPattern.exec($("tbody > tr > td > font :contains('Supplies:')").parent().parent().parent().parent().html().replace(/(?: )|\n|\t|,/g,"").replace(/<[^>]*>/g,""));
stored_bs=supp[1];
full_bs=supp[2];
$("table :contains('Advanced Resources') + table > tbody > tr > td").each(function(){
var goldpatt = /Gold:.*Deposits: +([0-9]+)/g;
var titpatt = /Titanium:.*Deposits: +([0-9]+)/g;
var urapatt = /Uranium:.*Deposits: +([0-9]+)/g;
goldAvail = goldpatt.exec($(this).html().replace(/,/g,"")) || goldAvail;
titAvail = titpatt.exec($(this).html().replace(/,/g,"")) || titAvail;
uraAvail = urapatt.exec($(this).html().replace(/(?: )|\n|\t|,/g,"")) || uraAvail;
//alert($(this).html().replace(/(?: )|\n|\t|,/g,""));
});
var turnMatch=/serif.([0-9]+)\/font/g;
turns = turnMatch.exec($("noscript").html().replace(/(?: )|\n|\t|,|(?:>)|(?:<)/g,""))
turns = turns[1];
//alert(GM_getValue("TURN_REGISTERED",0) +" "+(turns*1));
if (GM_getValue("TURN_REGISTERED",500) > (turns*1) || GM_getValue("burn",1) == 1){
if (GM_getValue("burn",1) == 1){
GM_setValue("burn",0);
}
getVals(true);
setup = {"MAX_BUSSES": GM_getValue("MAX_BUSSES",0),
"CIRCUMFERENCE": GM_getValue("CIRCUMFERENCE",0),
"DISPOSABLES_CONSUMED_BY_PEOPLE": GM_getValue("DISPOSABLES_CONSUMED_BY_PEOPLE",0),
"POPULATION": GM_getValue("POPULATION",0),
"FUEL_PER_BUS_DAY": GM_getValue("FUEL_PER_BUS_DAY",0),
"IS_GOOFBALL": setup['IS_GOOFBALL']};
POP_DISP_USE_RATIO=setup['DISPOSABLES_CONSUMED_BY_PEOPLE']/setup['POPULATION'];
recruitRadiusMultiplier = ((setup['MAX_BUSSES']*50)/setup['CIRCUMFERENCE'])*TURN_LENGTH;
FUEL_RATIO=setup['FUEL_PER_BUS_DAY']/setup['CIRCUMFERENCE'];
} else {
if ($("#unstaffedWarn").text() != '')
alert("Buildings unstaffed!");
main();
$("<div id='workspace3' >Construction Queue placeholder</div>").appendTo("body");
$("<input type='button' id='close' style='width:100px; z-index:500; position:fixed; background-color:rgb(200,0,0); right:0; top:0; color:#000000' name='close' value='Loading...'>").appendTo("body");
$("#workspace3").load("http://www.dailywheel.com/thegame/game.php?page=construct #que", {}, function (responseText, textStatus, XMLHttpRequest) {
if ($(this).html() == ""){
$(this).remove();
$("#close").attr('value','Hide');
$("#close").css('width','50px');
if (burn > 1 ){
$("#burnTurns").css("background-color", "rgb(200,200, 0)");
$("#burnTurns").attr("value","Burning "+(parseInt(burn)-TURN_LENGTH-1)+" more turns.");
GM_setValue("burn",burn-TURN_LENGTH);
$("#auto").css("background-color", "rgb(0,200, 0)");
burnTurn();
}
}
else
alert("There's a construction queue already! Remove it!");
});
}
function main(){
//alert(goldAvail[1] + " "+ titAvail[1] +" " +uraAvail[1]);
var powerUse=-EXCESS_POWER;
var foodUse=-EXCESS_FOOD-population*MEALS_PER_POPULATION;
var dispUse=-EXCESS_DISP-(population*POP_DISP_USE_RATIO);
var bsUse=-EXCESS_BS;
var workerPattern = /\s+([0-9]+)\s+<br>\n/m;
var foodPattern = /\s+([0-9]+)\s+food/m;
var dispUsePattern = /\s*([0-9]+)\s+<br>\n\s+\([0-9]+D/m;
var bsUsePattern = /\s*([0-9]+)\s+<br>\n\s+\([0-9]+[BS]+/m;
var bsMakePattern = /\s*([0-9]+)<br>\([0-9]+\seach\)\s+supplies/m;
var dispMakePattern = /[\s\t]*([0-9]+)\s+dispos/m;
var powerUsePattern = /\s*([0-9]+)\s*power|kWH/m;
var powerMakePattern = /\s*([0-9]+)\s*kwh\spower/m;
var seasonPattern = /(Spring|Summer|Fall|Winter)/m;
var season = seasonPattern.exec($("b :contains('Seasons')").text())[1];
$(":contains('Your Camp\'s Buildings) ~ tr").each(function(){
var buildingName = $(this).find("strong").html();
var idx = searchArray(buildings, buildingName);
if (idx != null) {
var foo = $(this).children("td").get();
//0:Name, 1:Owned, 2:Active, 3:Workers. 4:Production, 5:Daily Cost, 6:Defense, 7:Shelter Space
var bldgWker=workerPattern.exec(foo[3].innerHTML.replace(/,/g,""));
var bldgFood=foodPattern.exec(foo[4].innerHTML.replace(/,/g,""));
var bldgDispUse=dispUsePattern.exec(foo[5].innerHTML.replace(/,/g,""));
var bldgDispMake=dispMakePattern.exec(foo[4].innerHTML.replace(/,/g,""));
var bldgBSUse=bsUsePattern.exec(foo[5].innerHTML.replace(/,/g,""));
var bldgBSMake=bsMakePattern.exec(foo[4].innerHTML.replace(/,/g,""));
var bldgPowerUse=powerUsePattern.exec(foo[5].innerHTML.replace(/,/g,""));
var bldgPowerMake=powerMakePattern.exec(foo[4].innerHTML.replace(/,/g,""));
buildings[idx][3] = parseInt(foo[1].innerHTML.replace(/,/g,"")); //Current Buildings
if (bldgWker != null && bldgWker[1] > 0)
buildings[idx][8] = bldgWker[1]/buildings[idx][3];
if (bldgFood != null && bldgFood[1] > 0)
buildings[idx][12] = bldgFood[1]/buildings[idx][3];
if (bldgDispUse != null && bldgDispUse[1] > 0)
buildings[idx][9] = -(bldgDispUse[1]/buildings[idx][3]);
if (bldgDispMake != null && bldgDispMake[1] > 0)
buildings[idx][9] = (bldgDispMake[1]/buildings[idx][3]);
if (bldgBSUse != null && bldgBSUse[1] > 0)
buildings[idx][10] = -(bldgBSUse[1]/buildings[idx][3]);
if (bldgBSMake != null && bldgBSMake[1] > 0)
buildings[idx][10] = (bldgBSMake[1]/buildings[idx][3]);
if (bldgPowerMake != null && bldgPowerMake[1] > 0)
buildings[idx][11] = (bldgPowerMake[1]/buildings[idx][3]);
if (bldgPowerUse != null && bldgPowerUse[1] > 0)
buildings[idx][11] = -(bldgPowerUse[1]/buildings[idx][3]);
if (debug) GM_log(idx + ": " + buildings[idx]);
}
});
if (full_bs/100 > MAX_BS_SURPLUS){
SELL_BS = Math.floor(stored_bs*((full_bs/100)-MAX_BS_SURPLUS));
}
if (BUILD_FOOD_FOR_BARRACK_SPACE != false)
foodUse -= Math.ceil(buildings['racks'][3]*50.1055) * BUILD_FOOD_FOR_BARRACK_SPACE;
if (season == "Winter"){
bsUse -= (buildings['shelter1'][3]+buildings['shelter2'][3]+buildings['shelter3'][3]+buildings['racks'][3]);
}
for (i in buildings){
powerUse += buildings[i][11]*buildings[i][3];
foodUse += buildings[i][12]*buildings[i][3];
dispUse += buildings[i][9]*buildings[i][3];
bsUse += buildings[i][10]*buildings[i][3];
}
if (BUILD_GOLD)
buildings['gold'][6] = goldAvail[1];
if (BUILD_TIT)
buildings['tit'][6] = titAvail[1];
if (BUILD_URA)
buildings['ura'][6] = uraAvail[1];
//barbed wire
buildings['wire'][6]=Math.max((buildings['wall'][3])-buildings['wire'][3],0);
//Guard post -- one per 5 wall
if (BUILD_POST)
buildings['post'][6]=Math.max(Math.ceil((radius*8)/6.02)-buildings['post'][3],0);
//landfills
if (buildings['incin'][3] == 0 && BUILD_LANDFILL){
buildings['fill'][6] += Math.ceil( (population/WASTE_DIVISOR)/(300/TURN_LENGTH) );
}
//garages
buildings['garage'][6] += Math.max(Math.ceil(setup['MAX_BUSSES']/4*1.3) - buildings['garage'][3],0);
buildings['lot'][6] += Math.max(Math.ceil(setup['MAX_BUSSES']/2*1.3) - buildings['lot'][3],0);
// lights
var lights_needed=0;
if (BUILD_LIGHTS){
for (i in buildings)
lights_needed += buildings[i][13]*buildings[i][3];
}
buildings['light'][6] = lights_needed - buildings['light'][3];
var endTurn = "<form id='BrianEnd' name='BrianFormEndturn' method='post' action='game.php?page=construct' >"+
"<input type='hidden' name='endturn' value='"+TURN_LENGTH+"'>"+
"<input type='submit' class='ajx' name='submit' notAuto=true value='End "+TURN_LENGTH+" turns.'>"+
"</form>";
var defOpt = Math.floor(Math.random()*(MAX_DEFENSIVE_STRUCTURE-(MIN_DEFENSIVE_STRUCTURE-1)))+MIN_DEFENSIVE_STRUCTURE;
var structureName = ["Nothing", "Trenches", "Hairpins", "Pillboxes", "Anti-Tank", "Anti-Air", "SAM"];
var defenseForm ="<form name='BrianFormDef' class='ajaxify' method='post' action='game.php?page=defense'>"+
"<input type='hidden' class='ajx' name='struct' id='struct' value='"+defOpt+"'>"+
"<input name='action' type='hidden' id='action' value='struct'>"+
"<input type='submit' class='ajx' name='Submit' style='width:96%;' value='Defence Building: "+structureName[defOpt]+" '>"+
"</form>";
var labRandom = Math.floor(Math.random()*10)+1;
var labtype = ["High Explosives", "Uranium Extraction", "Isotope Gathering", "Subatomic Structure", "Reaction Stability", "Rocketry Research", "Propulsion", "Stability", "Automated Trajectory Calculations", "Ballistics", "Aerodynamics"];
var advancedForm = buildRawForm('AdvancedLab', 'game.php?page=learn2', {"action":labRandom}, "Research "+labtype[labRandom]);
if (debug) GM_log("*** Power: "+powerUse+"food: "+foodUse+"disp: "+dispUse+"bs: "+bsUse);
for (i in buildings){
var log="\n"+i;
for (var j=0;j<buildings[i].length;j++){
log+="\t"+j+":"+buildings[i][j];
}
if (debug) GM_log(log);
if (buildings[i][5] > 0){
buildings[i][6]=Math.round(Math.max(buildings[i][5]*(population/buildings[i][4])-buildings[i][3],buildings[i][6]),1);
powerUse += buildings[i][11]*buildings[i][6];
foodUse += buildings[i][12]*buildings[i][6];
dispUse += buildings[i][9]*buildings[i][6];
bsUse += buildings[i][10]*buildings[i][6];
}
}
var barterOrders ="";
if (WORKER_PAYMENT != false) {
bsUse -= Math.ceil((population*WORKER_PAYMENT)/BS_TO_CEP/14);
SELL_BS += Math.ceil((population*WORKER_PAYMENT)/BS_TO_CEP/14);
}
if (BUY_BS && bsUse < 0) {
barterOrders += barterForm(Math.ceil(-bsUse/CEP_TO_BS), "supplies", "buy");
bsUse =0;
}
if (BUY_FOOD && foodUse < 0) {
barterOrders += barterForm(Math.ceil(-foodUse/CEP_TO_FOOD), "food", "buy");
if (SELL_BS_FOR_CEP_FOR_FOOD_AND_DISP) {
bsUse += (foodUse / CEP_TO_FOOD)/BS_TO_CEP;
SELL_BS += Math.ceil(Math.ceil(-foodUse/CEP_TO_FOOD)/BS_TO_CEP);
}
}
if (BUY_DISP && dispUse < 0 ) {
barterOrders += barterForm(Math.ceil(-dispUse/CEP_TO_FOOD), "disposables", "buy");
if (SELL_BS_FOR_CEP_FOR_FOOD_AND_DISP) {
bsUse += (dispUse / CEP_TO_FOOD)/BS_TO_CEP;
SELL_BS += Math.ceil(Math.ceil(-dispUse/CEP_TO_FOOD)/BS_TO_CEP);
}
}
// Adjust food production
//first, figure out optimal food and power producers
var foodIdx ='garden';
var powerIdx ='smallgen';
for (i in buildings){
if (buildings[i][11]>buildings[powerIdx][11])
powerIdx=i;
if (buildings[i][12]/buildings[i][7]>buildings[foodIdx][12]/buildings[i][7])
foodIdx=i;
}
if (foodUse < 0 && buildings[foodIdx][12] > 0 && BUILD_FOOD) {
buildings[foodIdx][6] += Math.ceil(-foodUse/buildings[foodIdx][12]);
powerUse += buildings[foodIdx][11]*buildings[foodIdx][6];
foodUse += buildings[foodIdx][12]*buildings[foodIdx][6];
dispUse += buildings[foodIdx][9]*buildings[foodIdx][6];
bsUse += buildings[foodIdx][10]*buildings[foodIdx][6];
}
while ((bsUse < 0 && buildings['fac'][10] > 0 && BUILD_BS) || (powerUse < 0 && buildings[powerIdx][11] > 0 && BUILD_POWER)) {
if (bsUse < 0 && buildings['fac'][10] > 0 && BUILD_BS){
buildings['fac'][6] += Math.ceil(-bsUse/buildings['fac'][10]);
powerUse += buildings['fac'][11]*buildings['fac'][6];
foodUse += buildings['fac'][12]*buildings['fac'][6];
dispUse += buildings['fac'][9]*buildings['fac'][6];
bsUse += buildings['fac'][10]*buildings['fac'][6];
}
if (powerUse < 0 && buildings[powerIdx][11] > 0 && BUILD_POWER) {
buildings[powerIdx][6] += Math.ceil(-powerUse/buildings[powerIdx][11]);
powerUse += buildings[powerIdx][11]*buildings[powerIdx][6];
foodUse += buildings[powerIdx][12]*buildings[powerIdx][6];
dispUse += buildings[powerIdx][9]*buildings[powerIdx][6];
bsUse += buildings[powerIdx][10]*buildings[powerIdx][6];
}
}
var peopleGoingOut = maxAvail;
if ((Math.ceil(recruits*2/50)*(FUEL_RATIO*radius*8)) > maxAvail)
var peopleGoingOut = (Math.ceil(recruits*2/50)*(FUEL_RATIO*radius*8));
var fuelUse = (
( (buildings['gasgen'][3]+buildings['gasgen'][6])*10/GALLONS_OF_FUEL_TO_DEVOTE_TO_POWER_PER_REFINERY )+
( peopleGoingOut/TURN_LENGTH + EXCESS_FUEL )-
( buildings['fuelref'][3]*30 )
);
if (fuelUse > 0 && BUILD_FUEL){
buildings['fuelref'][6] += Math.ceil(fuelUse/30);
powerUse += buildings['fuelref'][11]*buildings['fuelref'][6];
foodUse += buildings['fuelref'][12]*buildings['fuelref'][6];
dispUse += buildings['fuelref'][9]*buildings['fuelref'][6];
bsUse += buildings['fuelref'][10]*buildings['fuelref'][6];
}
if (dispUse < 0 && buildings['recy'][9] > 0 && BUILD_DISP){
buildings['recy'][6] = Math.ceil(-dispUse/buildings['recy'][9]);
powerUse += buildings['recy'][11]*buildings['recy'][6];
foodUse += buildings['recy'][12]*buildings['recy'][6];
dispUse += buildings['recy'][9]*buildings['recy'][6];
bsUse += buildings['recy'][10]*buildings['recy'][6];
}
//storage huts.
buildings['hut'][6] += Math.ceil((buildings['fuelref'][3] + buildings['recy'][3] + buildings['fac'][3] + buildings['farm'][3] + buildings['garden'][3] +buildings['firepit'][3])*HUT_MULT) - buildings['hut'][3];
if (debug) GM_log("*** Power: "+powerUse+"food: "+foodUse+"disp: "+dispUse+"bs: "+bsUse);
sortBld = new Array();
workingPopulation=0;
var j=0;
for (i in buildings)
sortBld[j++] = j;
for (i in buildings) {
workingPopulation += buildings[i][3]*buildings[i][8];
var idx=parseInt(buildings[i][7]);
if (buildings[i][6]<0)
buildings[i][6]=0;
sortBld[idx] = buildings[i];
}
sortBld.sort(sortOrder);
for (i in sortBld){
GM_log(i+" "+sortBld[i][1]+" "+sortBld[i][6]+" "+sortBld[i][7]);
}
var buildForm = "";
workers = 0;
for (i in sortBld){
if (sortBld[i][6] > 0){
workers+=sortBld[i][2]*sortBld[i][6];
}
}
var rRecruits = SET_RECRUITERS || recruits;
var rExplore = SET_EXPLORERS || recruits;
var adjusted=maxAvail-(rRecruits+rExplore-Math.min(20,rExplore*.01));
if (SACK_EXPLORE_FOR_EXCESS_BUILD) {
adjusted = maxAvail-rRecruits;
}
var maxWorker = Math.ceil(MAX_CONSTRUCTION_WORKERS || adjusted)*TURN_LENGTH;
var idx='2', oldidx='2', loop=0;
for (var i=sortBld.length-1; i > 1 && sortBld[i] != null && (workers > maxWorker); i--){
if (sortBld[i][6] > 0){
var workers_used = sortBld[i][6]*sortBld[i][2], reduce, effectiveWorkers;
effectiveWorkers=Math.ceil(workers);
//alert(i + " " + sortBld[i][1] + " "+sortBld[i][6] +" "+effectiveWorkers+" "+maxWorker);
if ((effectiveWorkers-workers_used) > maxWorker)
sortBld[i][6] = 0;
else {
var excluded_workers = workers-workers_used;
var avail = maxWorker-excluded_workers;
sortBld[i][6] = Math.floor(avail/sortBld[i][2]);
}
workers = 0;
for (j in sortBld){
if (sortBld[j][6] > 0){
workers+=sortBld[j][2]*sortBld[j][6];
}
}
}
}
workers = 0;
for (i in sortBld){
if (sortBld[i][6] > 0){
workers+=sortBld[i][2]*sortBld[i][6];
}
}
workers = Math.ceil(workers/TURN_LENGTH);
var nukeWorkers=0;
if (NUKE_PATH) {
nukeWorkers = population-RESERVED_POPULATION_FOR_MILITARY-workingPopulation-workers-rRecruits-rExplore;
}
if (maxAvail > (nukeWorkers + workers + rRecruits+rExplore) && GM_getValue("burn",0) <= 1){
$("#auto").css("background-color", "rgb(200,200, 0)");
alert("You have more available than you will assign to construction, recruiting, and exploring! Fix this! \n"+
"Max Avail:"+maxAvail+
"\nUsed:"+(workers+rRecruits+rExplore)+
"\nDispose of:"+(maxAvail-(workers+rRecruits+rExplore)));
} else if (maxAvail > (workers + rRecruits+rExplore) && GM_getValue("burn",0) > 1 && !NUKE_PATH) {
rRecruits += (maxAvail-(workers+rRecruits+rExplore));
}
var recFormData = {"recruiters": rRecruits,
"action": "sendRecruiters",
"max": maxAvail,
"length": TURN_LENGTH,
"buss": (buildings['garage'][3]*50)};
var recruitForm = buildRawForm("Recruit","game.php?page=recruit", recFormData, "Send "+rRecruits+" recruiting for "+TURN_LENGTH+" day");
var exploreFormData = {"explorers": rExplore,
"action": "sendExplorers",
"max": maxAvail,
"days": TURN_LENGTH,
"type": "2",
"buss": (buildings['garage'][3]*50) };
var exploreForm = buildRawForm("Explore", 'game.php?page=explore', exploreFormData, "Send "+rExplore+" exploring "+TURN_LENGTH+" day");
var commandsForm = "<div id='commandsDiv' class='sidebar' style='background-color:rgb(152, 102, 102); top:5px;'>"+
"<input type='button' id='burnTurns' style='width:96%; background-color:#ee0000; color:#000000' name='burnTurn' value='Burn turns'>"+
"<input type='button' id='getVals' style='width:96%; background-color:#ee0000; color:#000000' name='getVals' value='Re-get Values'>"+
"</div>";
$(commandsForm).appendTo("body");
buildForm = "<div id='actionsDiv' class='sidebar' style='background-color:rgb(102, 152, 102); top:53px'>"+
"<input type='button' id='auto' style='width:96%; background-color:rgb(200,200,0); color:#000000' name='auto' value='Automatically iterate'>"+buildForm;
sortBld.sort(sortOrder);
for (i in sortBld){
if (sortBld[i][6] > 0){
buildForm += "<p class='ajx'>"+makeForm(i)+"</p>";
}
}
if (SELL_BS > 0){
barterOrders += barterForm(SELL_BS*TURN_LENGTH,"supplies","sell");
}
var constructFormData = {"workers":workers,
"action":"assignworkers",
"max":workers}
var constructForm = buildRawForm("ConstructWork","game.php?page=construct", constructFormData, "Assign "+workers+" to construction" );
$("[name='form3'] + td").each(function(){
var foo = '<form name="form3" method="post" style="margin:0px" action="game.php?page=construct">'+$(this).html()+'</form>';
$(this).html(foo);
});
buildForm += barterOrders;
if (ADVANCED_LAB)
buildForm += advancedForm;
if (NUKE_PATH) {
buildForm += buildRawForm('MakeNuke', "game.php?page=nuke", {"workers":nukeWorkers, "action":"assignworkers", "max":nukeWorkers}, "Assign "+nukeWorkers+" Nuke Workers", true);
}
if (SELL_WEAPONS){
SELL_BS=buildings['racks'][3]*70;
buildForm += buildRawForm("SellSwords", "game.php?page=recycle", {"qty":Math.floor((buildings['racks'][3]*15)*BARRACKS_PCT_FILLED), "weap":1, "action":"recycleWeap"}, "Recycle "+Math.floor((buildings['racks'][3]*15)*BARRACKS_PCT_FILLED)+" swords for BS");
buildForm += buildRawForm("SellBows", "game.php?page=recycle", {"qty":Math.floor((buildings['racks'][3]*15)*BARRACKS_PCT_FILLED), "weap":2, "action":"recycleWeap"}, "Recycle "+Math.floor((buildings['racks'][3]*15)*BARRACKS_PCT_FILLED)+" bows for BS");
buildForm += buildRawForm("SellPistols", "game.php?page=recycle", {"qty":Math.floor((buildings['racks'][3]*10)*BARRACKS_PCT_FILLED), "weap":3, "action":"recycleWeap"}, "Recycle "+Math.floor((buildings['racks'][3]*10)*BARRACKS_PCT_FILLED)+" pistols for BS");
buildForm += buildRawForm("SellRifles", "game.php?page=recycle", {"qty":Math.floor((buildings['racks'][3]*10)*BARRACKS_PCT_FILLED), "weap":4, "action":"recycleWeap"}, "Recycle "+Math.floor((buildings['racks'][3]*10)*BARRACKS_PCT_FILLED)+" rifles for BS");
buildForm += barterForm(SELL_BS,"supplies","sell");
}
if (INSTALL_PATRIOTS)
buildForm += buildRawForm('Patriot', "game.php?page=complex", {"banks":1, "action":"patriot"}, "Install Patriot Missle Bank", true);
buildForm += constructForm;
if (SWAP_EXPLORE_RECRUIT_ORDER)
buildForm += exploreForm + recruitForm;
else
buildForm += recruitForm + exploreForm;
buildForm += defenseForm +endTurn+"</div>";
$(buildForm).appendTo("body");
$(".sidebar").css({'padding':'1px', 'font-size':'xx-small', 'border':' solid 1px rgb(207, 207, 207)', 'position':'fixed', 'width':' 174px', 'overflow':'auto', 'right':'5px', 'z-index':'100', 'visibility':'visible'});
$(".sidebar > form").css({ 'margin':'0px' , 'padding':'0px'});
$(".sidebar > p").css({ 'margin':'0px' , 'padding':'0px'});
$(".sidebar > input ").css({ 'font-family':'Calibri' , 'font-size':'10px' , 'font-weight':'normal' , 'margin':'2px' , 'padding':'1px' , 'text-align':'left' });
$(".sidebar > * > input").css({ 'font-family':'Calibri' , 'font-size':'10px' , 'font-weight':'normal' , 'margin':'2px' , 'padding':'1px' , 'text-align':'left' });
}
function barterForm(amount, type, action){
var form="";
if (action == "sell"){
var data = {"qty":amount,
"max":amount,
"action":"trade",
"type":type}
form = buildRawForm(type, "game.php?page=barter", data, "Sell "+amount+" "+type);
}
else if (action == "buy") {
var data = {"qty":amount,
"exchange":"CEP",
"action":"add",
"forItem":type}
form = buildRawForm(type, "game.php?page=scripts", data, "Buy "+amount+" CEP of "+type);
}
return form;
}
function makeForm(idx, workers){
var data = { "buildOrNot":1,
"qty":sortBld[idx][6],
"buildingType":sortBld[idx][0],
"action":"addToQueue",
"top":0 };
if(idx == 0)
data['top']=1;
var form = buildRawForm(idx, "game.php?page=construct", data , "Queue "+sortBld[idx][6]+" "+sortBld[idx][1]);
return form;
}
function buildRawForm(name, url, data, submit, ajaxify){
ajaxify = typeof(ajaxify) != 'undefined' ? ajaxify : true;
if (ajaxify)
var class="class='ajaxify'";
else
var class="";
var form = "\n<form name='BrianForm"+name+"' style='font-family:Calibri, Tahoma; font-size:10px; font-weight:normal; margin:0px;' "+class+" method='post' action='"+url+"'>";
for (i in data)
form += "<input type='hidden' name='"+i+"' value='"+data[i]+"'>";
form += "<input type='submit' class='ajx' style='width:96%;' name='Submit' value='"+submit+"'>";
form += "</form>";
return form;
}
$(function(){
var burn=GM_getValue("burn",0);
$("#close").bind("click", function(e){
if ($(this).attr("value") == "Hide"){
$(this).attr("value","Show");
$(".sidebar").hide();
}
else if ($(this).attr("value") == "Show"){
$(this).attr("value","Hide");
$(".sidebar").show();
}
});
$("#getVals").bind("click", function(e){
getVals(true);
$(this).remove();
});
$("#burnTurns").bind("click", function(e){
if ( $("#burnTurns").css("background-color") == "rgb(200, 200, 0)"){
$("#burnTurns").css("background-color", "rgb(255,0, 0)");
$("#burnTurns").attr("value","Aborting!");
$("#auto").css("background-color", "rgb(200,200, 0)");
GM_setValue("burn",0);
}
else {
var turnsburn=prompt("Burn how many turns?");
GM_setValue("burn",turnsburn);
$("#burnTurns").css("background-color", "rgb(200, 200, 0)");
$("#burnTurns").attr("value","Burning "+(turnsburn-1)+" more turns.");
$("#auto").css("background-color", "rgb(0,200, 0)");
burnTurn();
}
});
$("#auto").bind("click",function(e){
if ($("#auto").css("background-color") == "rgb(200, 200, 0)")
$("#auto").css("background-color", "rgb(0,200, 0)");
else $("#auto").css("background-color", "rgb(200,200, 0)");
burnTurn();
});
$(".ajaxify").bind("click",function(e){
e.preventDefault();
var ddata = $(this).serializeArray();
var durl = $(this).attr("action");
//$.post(url, data)
$(this).children("[type='submit']").attr("value", "Sending.");
$.ajax(
{type: "POST",
url: durl,
data: ddata,
async: false
});
$(this).remove();
});
});
function burnTurn(){
if ($("#auto").css("background-color") == "rgb(0, 200, 0)"){
$(".ajaxify").each(function(){
if ($("#auto").css("background-color") == "rgb(0, 200, 0)"){
$(this).children("[type='submit']").attr("value", "Sending.");
var ddata = $(this).serializeArray();
var durl = $(this).attr("action");
$.ajax(
{type: "POST",
url: durl,
data: ddata,
async: false
});
$(this).remove();
}
});
if ($("#auto").css("background-color") == "rgb(0, 200, 0)")
$("#BrianEnd").submit();
}
}
function searchArray(ary, term){
var idx = null;
for ( i in ary) {
if (ary[i][1] == term)
return i;
}
return idx;
}
function sortOrder(a,b){
return a[7] - b[7];
}
function getVals(refresh){
GM_setValue("POPULATION",population);
document.write("Doing stuff. Don't touch.");
GM_setValue("TURN_REGISTERED", parseInt(turns)-10);
var gas, bus, circ, disp, done1=false, done2=false;
$("<div id='workspace1' >Recruit</div>").appendTo("body");
$("#workspace1").load("http://www.dailywheel.com/thegame/game.php?page=recruit table[width='530']", {}, function (responseText, textStatus, XMLHttpRequest) {
var work = $(this).html().replace(/(?: )|\n|\t|,/g,"");
var gasPattern= /Recruiting takes ([^G ]+)/g;
gas = gasPattern.exec(work);
var busPattern= /max of ([0-9]+) buses/g;
bus = busPattern.exec(work);
var circPattern=/Camp Circumference:[^0-9]+([0-9]+)/g;
circ = circPattern.exec(work);
GM_setValue("MAX_BUSSES",parseInt(bus[1]));
GM_setValue("CIRCUMFERENCE",parseInt(circ[1]));
GM_setValue("FUEL_PER_BUS_DAY",parseInt(gas[1]));
$("<div id='workspace2' >Disposables</div>").appendTo("body");
$("#workspace2").load("http://www.dailywheel.com/thegame/game.php?page=peoples table[width='500'] > :contains('Disposables')", {}, function (responseText, textStatus, XMLHttpRequest) {
var work = $(this).html().replace(/(?: )|\n|\t|,|(?:<.*>)/g,"");
var dispPattern= /Disposables[^0-9]+([0-9]+)/g;
disp = dispPattern.exec(work);
GM_setValue("DISPOSABLES_CONSUMED_BY_PEOPLE",parseInt(disp[1]));
if (refresh) {
location.replace("http://www.dailywheel.com/thegame/game.php?page=construct");
}
});
});
}
Function.prototype.defaults = function()
{
var _f = this;
var _a = Array(_f.length-arguments.length).concat(
Array.prototype.slice.apply(arguments));
return function()
{
return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(
_a.slice(arguments.length, _a.length)));
}
}