By default a colony ship can only construct/train two things at a time.
This can be increased later via a skill tree.
--- /dev/null
+import { db } from '../src/lib/db';
+
+const queries = [
+ 'ALTER TABLE cities ADD COLUMN max_construction_queue int',
+ 'ALTER TABLE cities ADD COLUMN max_training_queue int',
+ 'UPDATE cities set max_construction_queue = 2, max_training_queue = 2'
+];
+
+async function main() {
+ queries.forEach(async sql => await db.raw(sql));
+ process.exit(0);
+}
+
+main();
"private": true,
"scripts": {
"dev": "npx nodemon src/api.ts",
+ "migrate": "npx ts-node --",
"setup:rebels": "npx ts-node scripts/generate-cities.ts",
- "setup:database": "npx ts-node scripts/setup.ts",
- "setup": "npm run setup:rebels"
+ "setup": "npm run setup:rebels",
+ "migration": "npx ts-node migrations/"
},
"dependencies": {
"@bull-board/api": "^3.11.0",
export class InsufficientResourceError extends HttpError {
constructor(resource: string, expected: number, available: number) {
super(
- `Insufficent ${resource}. Expected: ${expected}, only ${available} available`,
+ `Insufficent ${resource} available. Expected: ${expected}, only ${available} available`,
400,
ERROR_CODE.INSUFFICIENT_RESOURCE
);
special_attacker_trainer: number;
special_defender_trainer: number;
icon: string;
+ max_construction_queue: number;
+ max_training_queue: number;
}
export type CityWithLocation = {
barracks: 0,
special_attacker_trainer: 0,
special_defender_trainer: 0,
+ max_construction_queue: 2,
+ max_training_queue: 2,
icon
};
throw new InsufficientResourceError('energy', building.energy, city.energy);
}
+ // validate that they have enough empty construction queues
+ const concurrentConstruction = await this.buildQueue.list(city.owner);
+ if(concurrentConstruction.length >= city.max_construction_queue) {
+ throw new InsufficientResourceError('Training queues', concurrentConstruction.length + 1, city.max_construction_queue);
+ }
+
city.usedSpace += (building.land * amount);
city.credits -= (building.credits * amount);
city.alloys -= (building.alloys * amount);
throw new InsufficientResourceError('defenders', unit.defenders, city.defenders);
}
- console.log(city);
- console.log(unit, amount);
-
- // validate that they have enough of the buildings to support this
+ // validate that they have enough empty training queues
+ const concurrentTraining = await this.unitTrainigQueue.list(city.owner);
+ if(concurrentTraining.length >= city.max_training_queue) {
+ throw new InsufficientResourceError('Training queues', concurrentTraining.length + 1, city.max_training_queue);
+ }
// ok they have everything, lets update their city
// and create the entry in the training queue
display: string;
} & UnitTrainingQueue;
-export const FriendlyUnitNames = new Map<Unit, string>();
-FriendlyUnitNames.set(Unit.SOLDIERS, 'Soldiers');
-FriendlyUnitNames.set(Unit.ATTACKERS, 'Attackers');
-FriendlyUnitNames.set(Unit.DEFENDERS, 'Defenders');
-FriendlyUnitNames.set(Unit.SPECIAL_ATTACKERS, 'Special Attackers');
-FriendlyUnitNames.set(Unit.SPECIAL_DEFENDERS, 'Special Defenders');
-
export class UnitTrainingQueueRepository extends Repository<UnitTrainingQueue> {
constructor() {
super('unit_training_queue');