diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..e4b0f61
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..2b1b67f
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/screepCpde.iml b/.idea/screepCpde.iml
new file mode 100644
index 0000000..24643cc
--- /dev/null
+++ b/.idea/screepCpde.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..0b17175
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1730685013447
+
+
+ 1730685013447
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/index.d.ts b/src/index.d.ts
index 00d6194..d7cecc6 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -1,4 +1,8 @@
-interface CreepMemory{
+interface CreepMemory {
role: string,
- working: boolean | null
+ working?: boolean | null,
+ [property: string]: any,
}
+
+
+declare type Part = WORK | MOVE | CARRY | HEAL | ATTACK | RANGED_ATTACK | TOUGH | CLAIM;
\ No newline at end of file
diff --git a/src/modules/builder.ts b/src/modules/builder.ts
index 3bfcabe..202d184 100644
--- a/src/modules/builder.ts
+++ b/src/modules/builder.ts
@@ -1,5 +1,5 @@
import { MAIN_SOURCE_ID } from "./setting";
-import { FindCapacity, GetConstructureSet, GetContainer, GetSource } from "./util";
+import { FindCapacity, GetConstructureSet, GetContainer, GetSource } from "./creepApi";
export function Build(creep: Creep, structureType: string | null = null) {
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
@@ -27,7 +27,7 @@ export function Build(creep: Creep, structureType: string | null = null) {
}
} else {
creep.memory.working = false
- var target = GetContainer(creep);
+ const target = GetContainer(creep);
if (creep.withdraw(target[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(target[0], { visualizePathStyle: { stroke: '#ffaa00' } });
}
diff --git a/src/modules/creepApi.ts b/src/modules/creepApi.ts
new file mode 100644
index 0000000..0983368
--- /dev/null
+++ b/src/modules/creepApi.ts
@@ -0,0 +1,85 @@
+import {Role} from "@/modules/setting";
+
+export function SetRole(creep: Creep, role: Role){
+ switch(role){
+ case Role.Harvester:
+ creep.memory.role ="Harvester";
+ case Role.BigHarvester:
+ creep.memory.role = "BigHarvester";
+ case Role.Builder:
+ creep.memory.role = "Builder";
+ case Role.Upgrader:
+ creep.memory.role = "Upgrader";
+ case Role.Repairer:
+ creep.memory.role = "Repairer";
+ }
+}
+export function RoleToString(role: Role) : string{
+ switch(role){
+ case Role.Harvester:
+ return "Harvester";
+ case Role.BigHarvester:
+ return "BigHarvester";
+ case Role.Builder:
+ return "Builder";
+ case Role.Upgrader:
+ return "Upgrader";
+ case Role.Repairer:
+ return "Repairer";
+ }
+}
+
+export function SpawnCreep(spawn: StructureSpawn, body: Part[], role?:Role) : number{
+ const name = "Creep" + Game.time;
+ return spawn.spawnCreep(body, name, {memory: {role : RoleToString(role)}});
+}
+
+export function FindCapacity(creep: Creep): AnyStructure[] {
+ return creep.room.find(FIND_STRUCTURES, {
+ filter: (structure: StructureSpawn | StructureExtension) => {
+ let type = structure.structureType;
+ return (
+ (type == STRUCTURE_EXTENSION ||
+ type == STRUCTURE_SPAWN||
+ type == STRUCTURE_CONTAINER) &&
+ structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
+ )
+ }
+ })
+}
+
+export function GetSource(sourceId: Id | null): Source {
+ return Game.getObjectById(sourceId);
+}
+
+export function GetConstructureSet(creep: Creep, structureType: string | null = null): ConstructionSite[] {
+ return creep.room.find(FIND_CONSTRUCTION_SITES, {
+ filter: (structure: Structure) => {
+ if (structureType == null) return true;
+ return structure.structureType == structureType;
+ }
+ })
+}
+
+export function GetConstructure(creep: Creep, structureType: string, ){
+ return creep.room.find(FIND_STRUCTURES, {filter:(structure: AnyStructure)=>{
+ return structure.structureType == structureType;
+ }})
+}
+
+export function GetContainer(creep: Creep): StructureContainer[]{
+ let target = GetConstructure(creep, STRUCTURE_CONTAINER) as StructureContainer[];
+ return target
+}
+
+export function GetCreeps() : Map{
+ let resp: Map = new Map();
+ for (var name in Game.creeps){
+ var creep = Game.creeps[name];
+ if(resp.has(creep.memory.role))
+ resp.set(creep.memory.role, resp.get(creep.memory.role)+1)
+ else
+ resp.set(creep.memory.role, 1);
+ }
+ return resp;
+}
\ No newline at end of file
diff --git a/src/modules/harvester.ts b/src/modules/harvester.ts
index cb4e00c..e374aa2 100644
--- a/src/modules/harvester.ts
+++ b/src/modules/harvester.ts
@@ -1,4 +1,4 @@
-import { FindCapacity, GetContainer, GetSource } from "./util"
+import { FindCapacity, GetContainer, GetSource } from "./creepApi"
import { MAIN_SOURCE_ID } from "./setting";
export function Harvest(creep: Creep) {
diff --git a/src/modules/setting.ts b/src/modules/setting.ts
index 610e4d7..7e6b50d 100644
--- a/src/modules/setting.ts
+++ b/src/modules/setting.ts
@@ -1,13 +1,16 @@
-let HARVESTER_COUNT: number = 0;
-let BUILDER_COUNT: number = 1;
-let UPGRADER_COUNT: number = 6;
+export let HARVESTER_COUNT: number = 0;
+export let BUILDER_COUNT: number = 1;
+export let UPGRADER_COUNT: number = 4;
-let MAIN_SOURCE_ID: Id = "ef990774d80108c" as Id;
-
-export {
- HARVESTER_COUNT,
- BUILDER_COUNT,
- UPGRADER_COUNT,
- MAIN_SOURCE_ID,
+export let MAIN_SOURCE_ID: Id = "ef990774d80108c" as Id;
+export const enum Role {
+ Harvester,
+ BigHarvester,
+ Builder,
+ Upgrader,
+ Repairer,
}
+export let mk1Body: Part[] = [WORK, CARRY, MOVE];
+export let mk2Body: Part[] = [WORK, WORK, CARRY, CARRY, MOVE, MOVE];
+export let Mk2harvesterBody: Part[] = [WORK, WORK, WORK, WORK, MOVE];
diff --git a/src/modules/spawnCreep.ts b/src/modules/spawnCreep.ts
index 72e44a0..5036a11 100644
--- a/src/modules/spawnCreep.ts
+++ b/src/modules/spawnCreep.ts
@@ -1,70 +1,40 @@
-import "./setting";
-import { BUILDER_COUNT, HARVESTER_COUNT, UPGRADER_COUNT } from "./setting";
+import * as setting from "./setting";
+import * as creepApi from "./creepApi"
-var createDefaultHarvester = (spawn: StructureSpawn) => {
- let name = "Harvester" + Game.time;
- return spawn.spawnCreep([WORK, CARRY, MOVE], name, {
- memory: {
- role: "Harvester",
- working: false
- }
- });
-}
-var createDefaultBuilder = (spawn: StructureSpawn) => {
- let name = "Builder" + Game.time;
- return spawn.spawnCreep([WORK, CARRY, MOVE], name, {
- memory: {
- role: "Builder",
- working: false
- }
- });
+const createDefaultHarvester = (spawn: StructureSpawn) => {
+ return creepApi.SpawnCreep(spawn, setting.mk1Body, setting.Role.Harvester);
}
+const createDefaultBuilder = (spawn: StructureSpawn) => {
+ return creepApi.SpawnCreep(spawn, setting.mk1Body, setting.Role.Builder);
+};
-var createDefaultUpgrader = (spawn: StructureSpawn) => {
- let name = "Upgrader" + Game.time;
- return spawn.spawnCreep([WORK, CARRY, MOVE], name, {
- memory: {
- role: "Upgrader",
- working: false
- }
- });
+const createDefaultUpgrader = (spawn: StructureSpawn) => {
+ return creepApi.SpawnCreep(spawn, setting.mk1Body, setting.Role.Upgrader);
+};
+
+const createMk2Harvester = (spawn: StructureSpawn) => {
+ return creepApi.SpawnCreep(spawn, setting.Mk2harvesterBody, setting.Role.BigHarvester);
}
export function SpawnCreep(spawn: StructureSpawn) {
if (spawn.spawning) return;
-
- let harvesters = _.filter(Game.creeps,
- /**@param {Creep} creep*/
- (creep) => {
- return creep.memory.role == "Harvester";
- });
- let builders = _.filter(Game.creeps,
- /**@param {Creep} creep*/
- (creep) => {
- return creep.memory.role == "Builder";
- });
- let upgraders = _.filter(Game.creeps,
- /**@param {Creep} creep*/
- (creep) => {
- return creep.memory.role == "Upgrader";
- });
- if (harvesters.length < HARVESTER_COUNT) {
+ let currentCreeps = creepApi.GetCreeps();
+ if (currentCreeps.get(creepApi.RoleToString(setting.Role.Harvester)) > setting.HARVESTER_COUNT) {
if (createDefaultHarvester(spawn) == 0) {
console.log("Spawn Harvester")
}
}
- if (upgraders.length < UPGRADER_COUNT) {
+ if (currentCreeps.get(creepApi.RoleToString(setting.Role.Upgrader)) > setting.UPGRADER_COUNT) {
if (createDefaultUpgrader(spawn) == 0) {
console.log("Spawn Upgrader")
}
}
- if (builders.length < BUILDER_COUNT) {
+ if (currentCreeps.get(creepApi.RoleToString(setting.Role.Builder)) > setting.BUILDER_COUNT) {
if (createDefaultBuilder(spawn) == 0) {
console.log("Spawn Builder")
}
}
-
if (spawn.spawning) {
var spawningCreep = Game.creeps[spawn.spawning.name];
spawn.room.visual.text(
diff --git a/src/modules/upgrader.ts b/src/modules/upgrader.ts
index c52a2d4..6b2d62c 100644
--- a/src/modules/upgrader.ts
+++ b/src/modules/upgrader.ts
@@ -1,5 +1,5 @@
import { MAIN_SOURCE_ID } from "./setting";
-import { GetContainer, GetSource } from "./util";
+import { GetContainer, GetSource } from "./creepApi";
/**@param {Creep} creep */
export function Upgrade(creep: Creep) {
diff --git a/src/modules/util.ts b/src/modules/util.ts
deleted file mode 100644
index c2d23c4..0000000
--- a/src/modules/util.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-export function FindCapacity(creep: Creep): AnyStructure[] {
- return creep.room.find(FIND_STRUCTURES, {
- filter: (structure: StructureSpawn | StructureExtension) => {
- let type = structure.structureType;
- return (
- (type == STRUCTURE_EXTENSION ||
- type == STRUCTURE_SPAWN||
- type == STRUCTURE_CONTAINER) &&
- structure.store.getFreeCapacity(RESOURCE_ENERGY) as number > 0
- )
- }
- })
-}
-
-export function GetSource(sourceId: Id | null): Source {
- return Game.getObjectById(sourceId);
-}
-
-export function GetConstructureSet(creep: Creep, structureType: string | null = null): ConstructionSite[] {
- return creep.room.find(FIND_CONSTRUCTION_SITES, {
- filter: (structure: Structure) => {
- if (structureType == null) return true;
- return structure.structureType == structureType;
- }
- })
-}
-
-export function GetConstructure(creep: Creep, structureType: string, ){
- return creep.room.find(FIND_STRUCTURES, {filter:(structure: AnyStructure)=>{
- return structure.structureType == structureType;
- }})
-}
-
-export function GetContainer(creep: Creep): StructureContainer[]{
- let target = GetConstructure(creep, STRUCTURE_CONTAINER) as StructureContainer[];
- return target
-}
\ No newline at end of file