Skip to content

Commit

Permalink
feat(core): Implement new bulk purchase strategy
Browse files Browse the repository at this point in the history
Fixes #155
  • Loading branch information
oliversalzburg committed Aug 24, 2024
1 parent c1b5d62 commit 9f8a25f
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 92 deletions.
2 changes: 1 addition & 1 deletion packages/kitten-scientists/source/BonfireManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class BonfireManager implements Automation {
}

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, trigger, "bonfire");
const buildList = bulkManager.bulk(builds, metaData, trigger, "Bonfire");

let refreshRequired = false;
// Build all entries in the build list, where we can build any items.
Expand Down
9 changes: 4 additions & 5 deletions packages/kitten-scientists/source/ReligionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
UnicornItem,
UnicornItems,
} from "./settings/ReligionSettings.js";
import { negativeOneToInfinity } from "./tools/Format.js";
import { cwarn } from "./tools/Log.js";
import {
BuildButton,
Expand Down Expand Up @@ -92,10 +93,7 @@ export class ReligionManager implements Automation {
),
);
// Build a unicorn pasture if possible.
const maxPastures =
-1 === this.settings.buildings.unicornPasture.max
? Number.POSITIVE_INFINITY
: this.settings.buildings.unicornPasture.max;
const maxPastures = negativeOneToInfinity(this.settings.buildings.unicornPasture.max);
const meta = this._host.game.bld.getBuildingExt("unicornPasture").meta;
if (this.settings.buildings.unicornPasture.enabled && meta.val < maxPastures) {
this._bonfireManager.autoBuild({
Expand Down Expand Up @@ -172,6 +170,7 @@ export class ReligionManager implements Automation {
buildRequest,
this.getBuildMetaData(buildRequest),
this.settings.trigger,
"Religion",
);
if (0 < build.length && 0 < build[0].count) {
// We force only building 1 of the best unicorn building, because
Expand Down Expand Up @@ -199,7 +198,7 @@ export class ReligionManager implements Automation {
> = this.getBuildMetaData(builds);

// Let the bulk manager figure out which of the builds to actually build.
const buildList = this._bulkManager.bulk(builds, metaData, this.settings.trigger);
const buildList = this._bulkManager.bulk(builds, metaData, this.settings.trigger, "Religion");

let refreshRequired = false;
for (const build of buildList) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kitten-scientists/source/SpaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class SpaceManager implements Automation {
}

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, trigger, "space");
const buildList = bulkManager.bulk(builds, metaData, trigger, "Space");

let refreshRequired = false;
// Build all entries in the build list, where we can build any items.
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/TimeControlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TabManager } from "./TabManager.js";
import { WorkshopManager } from "./WorkshopManager.js";
import { CycleIndices, TimeControlSettings } from "./settings/TimeControlSettings.js";
import { objectEntries } from "./tools/Entries.js";
import { negativeOneToInfinity } from "./tools/Format.js";
import {
BuildButton,
ButtonModernController,
Expand Down Expand Up @@ -492,8 +493,7 @@ export class TimeControlManager {
}

// The maximum years to skip, based on the user configuration.
const maxSkips =
-1 === this.settings.timeSkip.max ? Number.POSITIVE_INFINITY : this.settings.timeSkip.max;
const maxSkips = negativeOneToInfinity(this.settings.timeSkip.max);

// The amount of skips we can perform.
let canSkip = Math.floor(
Expand Down
2 changes: 1 addition & 1 deletion packages/kitten-scientists/source/TimeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TimeManager {
}

// Let the bulkmanager determine the builds we can make.
const buildList = bulkManager.bulk(builds, metaData, trigger);
const buildList = bulkManager.bulk(builds, metaData, trigger, "Time");

let refreshRequired = false;
for (const build of buildList) {
Expand Down
7 changes: 2 additions & 5 deletions packages/kitten-scientists/source/TradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WorkshopManager } from "./WorkshopManager.js";
import { MaterialsCache } from "./helper/MaterialsCache.js";
import { TradeSettings } from "./settings/TradeSettings.js";
import { objectEntries } from "./tools/Entries.js";
import { ucfirst } from "./tools/Format.js";
import { negativeOneToInfinity, ucfirst } from "./tools/Format.js";
import { cwarn } from "./tools/Log.js";
import { BuildButton, Race, RaceInfo, Resource, TradeInfo, TradeTab } from "./types/index.js";

Expand Down Expand Up @@ -309,10 +309,7 @@ export class TradeManager implements Automation {

const name = racePanels[panelIndex].race.name;
const race = this._host.game.diplomacy.get(name);
const max =
this.settings.buildEmbassies.races[name].max === -1
? Number.POSITIVE_INFINITY
: this.settings.buildEmbassies.races[name].max;
const max = negativeOneToInfinity(this.settings.buildEmbassies.races[name].max);

if (
!this.settings.buildEmbassies.races[name].enabled ||
Expand Down
6 changes: 2 additions & 4 deletions packages/kitten-scientists/source/VillageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WorkshopManager } from "./WorkshopManager.js";
import { MaterialsCache } from "./helper/MaterialsCache.js";
import { VillageSettings } from "./settings/VillageSettings.js";
import { objectEntries } from "./tools/Entries.js";
import { negativeOneToInfinity } from "./tools/Format.js";
import { Resource } from "./types/index.js";
import { JobInfo, VillageTab } from "./types/village.js";

Expand Down Expand Up @@ -74,10 +75,7 @@ export class VillageManager implements Automation {
}

const maxKittensInJob = this._host.game.village.getJobLimit(job.name);
const maxKittensToAssign =
this.settings.jobs[job.name].max === -1
? Number.POSITIVE_INFINITY
: this.settings.jobs[job.name].max;
const maxKittensToAssign = negativeOneToInfinity(this.settings.jobs[job.name].max);
const kittensInJob = job.value;
if (kittensInJob < maxKittensInJob && kittensInJob < maxKittensToAssign) {
jobsNotCapped.push({ job, count: kittensInJob, toCap: maxKittensInJob - kittensInJob });
Expand Down
4 changes: 2 additions & 2 deletions packages/kitten-scientists/source/WorkshopManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { KittenScientists } from "./KittenScientists.js";
import { CraftSettingsItem, WorkshopSettings } from "./settings/WorkshopSettings.js";
import { TabManager } from "./TabManager.js";
import { objectEntries } from "./tools/Entries.js";
import { negativeOneToInfinity } from "./tools/Format.js";
import { cerror } from "./tools/Log.js";
import { CraftableInfo, ResourceInfo } from "./types/craft.js";
import { Resource, ResourceCraftable, UpgradeInfo } from "./types/index.js";
Expand Down Expand Up @@ -113,8 +114,7 @@ export class WorkshopManager extends UpgradeManager implements Automation {
}

const current = !craft.max ? false : this.getResource(craft.resource);

const max = craft.max === -1 ? Number.POSITIVE_INFINITY : craft.max;
const max = negativeOneToInfinity(craft.max);
if (current && max < current.value) {
continue;
}
Expand Down
Loading

0 comments on commit 9f8a25f

Please sign in to comment.