limit construction/training queues to 2
[browser-rts.git] / src / repository / city.ts
index 4becd98836c653ba22eabf986d8e416601199ee3..272ee3b960a410c018d07cc723b5620f8922da3c 100644 (file)
@@ -37,6 +37,8 @@ export type City = {
     special_attacker_trainer: number;
     special_defender_trainer: number;
     icon: string;
+    max_construction_queue: number;
+    max_training_queue: number;
 }
 
 export type CityWithLocation = {
@@ -88,6 +90,8 @@ export class CityRepository extends Repository<City> {
             barracks: 0,
             special_attacker_trainer: 0,
             special_defender_trainer: 0,
+            max_construction_queue: 2,
+            max_training_queue: 2,
             icon
         };
 
@@ -199,6 +203,12 @@ where l.sector_id = ?`, [sector_id]);
             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);
@@ -265,10 +275,11 @@ where l.sector_id = ?`, [sector_id]);
             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