More farming work

This commit is contained in:
pjht 2018-10-16 09:35:19 -05:00
parent 39c8e2c914
commit 88339a793c
2 changed files with 20 additions and 3 deletions

View File

@ -59,6 +59,11 @@
<button class="hire" onclick="hire('scientist')">Hire</button> <button class="hire" onclick="hire('scientist')">Hire</button>
<button id="fireScientist" onclick="fire('scientist')">Fire</button> <button id="fireScientist" onclick="fire('scientist')">Fire</button>
</div> </div>
<div class="farmRequired">
<p id="numFarmers">Number of farmers uninitialized!</p>
<button class="hire" id="hireFarmer" onclick="hire('farmer')">Hire</button>
<button id="fireFarmer" onclick="fire('farmer')">Fire</button>
</div>
</div> </div>
<div id="tabResearch"> <div id="tabResearch">
<p id="researchPoints">Research points uninitialized!</p> <p id="researchPoints">Research points uninitialized!</p>

18
main.js
View File

@ -61,7 +61,8 @@ var allBuildings={
var allWorkers={ var allWorkers={
lumberjack:"wood", lumberjack:"wood",
miner:"metal", miner:"metal",
scientist:"researchPoints" scientist:"researchPoints",
farmer:"food"
}; };
var workerRate=0.1; var workerRate=0.1;
var allResearches={ var allResearches={
@ -163,7 +164,8 @@ function updateShown() {
var hasResources=Object.keys(resources).length>0; var hasResources=Object.keys(resources).length>0;
var hasLab=Object.keys(buildings).includes("lab"); var hasLab=Object.keys(buildings).includes("lab");
var hasTpost=Object.keys(buildings).includes("trading post"); var hasTpost=Object.keys(buildings).includes("trading post");
var hasShelter=false var hasShelter=false;
var hasFarm=numOfBuilding("farm")>0;
for (var i in shelters) { for (var i in shelters) {
var shelter=shelters[i]; var shelter=shelters[i];
if (Object.keys(buildings).includes(shelter)) { if (Object.keys(buildings).includes(shelter)) {
@ -178,6 +180,7 @@ function updateShown() {
$("#linkResearch").toggle(hasLab); $("#linkResearch").toggle(hasLab);
$(".researchRequired").toggle(hasLab); $(".researchRequired").toggle(hasLab);
$("#linkTrading").toggle(hasTpost); $("#linkTrading").toggle(hasTpost);
$(".farmRequired").toggle(hasFarm);
} }
function incResource(name,amount=1) { function incResource(name,amount=1) {
if (name=="researchPoints") { if (name=="researchPoints") {
@ -354,18 +357,23 @@ function updatePopulationInfo() {
} }
function updateWorkerInfo() { function updateWorkerInfo() {
var working=0; var working=0;
var disableFarmer=false;
for (var worker in allWorkers) { for (var worker in allWorkers) {
var workerAmount=workers[worker]; var workerAmount=workers[worker];
if (!workerAmount) { if (!workerAmount) {
workerAmount=0; workerAmount=0;
} }
working+=workerAmount; working+=workerAmount;
if (worker=="farmer") {
disableFarmer=workerAmount==maxFarmers();
}
worker=capitalizeFirst(worker); worker=capitalizeFirst(worker);
$("#fire"+worker).attr("disabled",workerAmount==0); $("#fire"+worker).attr("disabled",workerAmount==0);
$("#num"+worker+"s").text(worker+"s: "+workerAmount); $("#num"+worker+"s").text(worker+"s: "+workerAmount);
} }
$("#workPop").text("Working: "+working+"/"+pop); $("#workPop").text("Working: "+working+"/"+pop);
$(".hire").attr("disabled",working==pop); $(".hire").attr("disabled",working==pop);
$("#hireFarmer").attr("disabled",disableFarmer);
} }
function updateTradingButtons() { function updateTradingButtons() {
$("#tabTrading").html(""); $("#tabTrading").html("");
@ -467,16 +475,20 @@ function autoInc() {
for (var worker in allWorkers) { for (var worker in allWorkers) {
workerAmount=workers[worker]; workerAmount=workers[worker];
var amount=workerRate*workerAmount; var amount=workerRate*workerAmount;
if (amount>0) { var amountFood=resources.food
if (amountFood>amount*0.75 && amount>0) {
if (worker=="scientist") { if (worker=="scientist") {
var usedMetal=Math.ceil(workerAmount*0.4); var usedMetal=Math.ceil(workerAmount*0.4);
if (resources["metal"]>=usedMetal) { if (resources["metal"]>=usedMetal) {
incResource(allWorkers[worker],amount); incResource(allWorkers[worker],amount);
decResource("metal",usedMetal); decResource("metal",usedMetal);
} }
} else if (worker=="farmer") {
incResource(allWorkers[worker],amount*farmYield());
} else { } else {
incResource(allWorkers[worker],amount); incResource(allWorkers[worker],amount);
} }
decResource("food",amount*0.75);
} }
} }
} }