Skip to content

Commit

Permalink
[robots] show robots and their effect in the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nroutasuo committed Jul 31, 2022
1 parent 0208bac commit 4e64c92
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
6 changes: 6 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,9 @@ body.dark span.improvement-badge.improvement-upgrade-level {
font-size: 75%;
width: 1em;
}
body.dark #in-population-details > div {
width: 100%;
}
body.dark .changelog-type {
padding: 2px 5px;
border-width: 1px;
Expand Down Expand Up @@ -4097,6 +4100,9 @@ body.sunlit span.improvement-badge.improvement-upgrade-level {
font-size: 75%;
width: 1em;
}
body.sunlit #in-population-details > div {
width: 100%;
}
body.sunlit .changelog-type {
padding: 2px 5px;
border-width: 1px;
Expand Down
6 changes: 6 additions & 0 deletions css/modules/elements-special.less
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ span.improvement-badge.improvement-upgrade-level {
width: 1em;
}

// camp population and workers

#in-population-details > div {
width: 100%;
}

// CHANGELOG

.changelog-type {
Expand Down
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ <h3>Buildings</h3>
<div class="unit unit golden-small">
<div id="in-population" class="infobox">
<h3>Population</h3>
<p style="display:none" id="in-population-status">free / diseased</p>
<div id="in-population-details" class="infobox" style='display:none'>
<div id="in-population-status">free / diseased</div>
<div class="info-callout-target">
<div style="display: none" id="in-population-robots">0 robots</div>
</div>
</div>
<table class="full-width" id="in-assign-workers">
</table>
<p style="display:none" id="in-population-next">Next worker:</p>
Expand Down
13 changes: 8 additions & 5 deletions src/game/constants/UIConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,15 @@ define(['ash',
if (showDecimalsWhenSmall && value <= 10) divisor = decimalDivisor;
if (showDecimalsAlways) divisor = decimalDivisor;

if (value % 1 === 0 || divisor <= 0) return Math.round(value);

let result = Math.round(value * divisor) / divisor;
let result = value;
if (value % 1 === 0 || divisor <= 0) {
result = Math.round(value);
} else {
result = Math.round(value * divisor) / divisor;
}

if (result == 0) {
return "< " + (0.5 / divisor);
if (value > 0 && result == 0) {
return "< 1";
}

return result;
Expand Down
27 changes: 20 additions & 7 deletions src/game/systems/ui/UIOutCampSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'game/nodes/tribe/TribeUpgradesNode',
'game/components/player/PerksComponent',
'game/components/common/CampComponent',
'game/components/common/ResourcesComponent',
'game/components/sector/OutgoingCaravansComponent',
'game/components/sector/ReputationComponent',
'game/components/sector/improvements/SectorImprovementsComponent',
Expand All @@ -30,7 +31,7 @@
ImprovementConstants, PlayerActionConstants, UIConstants, UpgradeConstants, OccurrenceConstants, CampConstants, PerkConstants, TextConstants,
PlayerLevelNode, PlayerPositionNode, PlayerLocationNode, DeityNode, TribeUpgradesNode,
PerksComponent,
CampComponent, OutgoingCaravansComponent, ReputationComponent, SectorImprovementsComponent, CampEventTimersComponent,
CampComponent, ResourcesComponent, OutgoingCaravansComponent, ReputationComponent, SectorImprovementsComponent, CampEventTimersComponent,
RecruitComponent, TraderComponent, RaidComponent
) {
var UIOutCampSystem = Ash.System.extend({
Expand Down Expand Up @@ -172,12 +173,14 @@
if (!campComponent) return;

let currentPopulation = Math.floor(campComponent.population);
let resources = this.playerLocationNodes.head.entity.get(ResourcesComponent);

if (!isActive) return;

var maxPopulation = this.getCampMaxPopulation();
var reputation = this.playerLocationNodes.head.entity.get(ReputationComponent).value;
this.updatePopulationChangeDisplay(campComponent, maxPopulation, reputation);
let maxPopulation = this.getCampMaxPopulation();
let reputation = this.playerLocationNodes.head.entity.get(ReputationComponent).value;
let robots = resources.resources.robots || 0;
this.updatePopulationDisplay(campComponent, maxPopulation, reputation, robots);
},

getCampMaxPopulation: function () {
Expand All @@ -196,7 +199,7 @@
$(id).parent().siblings(".in-assign-worker-limit").children(".callout-container").children(".info-callout-target").html(showMax ? "<span>/ " + maxWorkers + "</span>" : "");
},

updatePopulationChangeDisplay: function (campComponent, maxPopulation, reputation) {
updatePopulationDisplay: function (campComponent, maxPopulation, reputation, robots) {
var freePopulation = campComponent.getFreePopulation();
var isPopulationMaxed = campComponent.population >= maxPopulation;
var populationChangePerSec = campComponent.populationChangePerSec;
Expand All @@ -209,7 +212,8 @@
$("#in-population-next").text(campComponent.populationChangePerSec >= 0 ? "Next worker:" : "Worker leaving:");
$("#in-population-reputation").text("Reputation required: " + reqRepCur + " (current) " + reqRepNext + " (next)");
$("#in-population h3").text("Population: " + Math.floor(campComponent.population) + " / " + (maxPopulation));
$("#in-population p#in-population-status").text("Unassigned workers: " + freePopulation);
$("#in-population #in-population-status").text("Unassigned workers: " + freePopulation);
$("#in-population #in-population-robots").text("Robots: " + UIConstants.roundValue(robots, false, false, 1));

if (!isPopulationStill) {
var secondsToChange = 0;
Expand All @@ -236,8 +240,15 @@
GameGlobals.uiFunctions.slideToggleIf("#in-population-reputation", null, maxPopulation > 0 && !isPopulationMaxed, 200, 200);
GameGlobals.uiFunctions.slideToggleIf("#in-population-bar-next", null, campComponent.population > 0 && !isPopulationStill, 200, 200);
GameGlobals.uiFunctions.slideToggleIf("#in-population-next", null, campComponent.population > 0 && !isPopulationStill, 200, 200);
GameGlobals.uiFunctions.slideToggleIf("#in-population-details", null, campComponent.population >= 1, 200, 200);
GameGlobals.uiFunctions.slideToggleIf("#in-population-status", null, campComponent.population >= 1, 200, 200);
GameGlobals.uiFunctions.slideToggleIf("#in-population-robots", null, robots > 0, 200, 200);
GameGlobals.uiFunctions.slideToggleIf("#in-assign-workers", null, campComponent.population >= 1, 200, 200);

let robotBonus = GameGlobals.campBalancingHelper.getWorkerRobotBonus(robots);
let robotCalloutContent = "worker resource production: +" + UIConstants.roundValue((robotBonus - 1) * 100, true, false) + "%";
UIConstants.updateCalloutContent("#in-population #in-population-robots", robotCalloutContent);

},

updateAssignedWorkers: function (campComponent) {
Expand Down Expand Up @@ -620,7 +631,9 @@
specialConsumptionS = "<br/><span class='warning'>metal -" + GameGlobals.campHelper.getMetalConsumptionPerSecondSmith(1) + "/s</span>";
break;
case CampConstants.workerTypes.robotmaker.id:
productionS = "robots +" + UIConstants.roundValue(GameGlobals.campHelper.getRobotsProductionPerSecond(1, improvements), true, true) + "/s";
let robotVal = GameGlobals.campHelper.getRobotsProductionPerSecond(1, improvements);
let robotValDivisor = robotVal < 0.01 ? 10000 : null;
productionS = "robots +" + UIConstants.roundValue(robotVal, true, true, robotValDivisor) + "/s";
specialConsumptionS = "<br/><span class='warning'>metal -" + GameGlobals.campHelper.getMetalConsumptionPerSecondSmith(1) + "/s</span>";
break;
case CampConstants.workerTypes.scientist.id:
Expand Down

0 comments on commit 4e64c92

Please sign in to comment.