UI update for map with sector selector
[browser-rts.git] / src / repository / city.ts
index df808786e71fbf7890b91b0ce35d573530d357b5..7b8818510e9b45761473d6da7411c27735ce4299 100644 (file)
@@ -30,6 +30,7 @@ export type City = {
     barracks: number;
     special_attacker_trainer: number;
     special_defender_trainer: number;
+    icon: string;
 }
 
 export type CityWithLocation = {
@@ -54,7 +55,8 @@ export class CityRepository extends Repository<City> {
         this.armyRepository = new ArmyRepository();
     }
 
-    async create(accountId: string): Promise<CityWithLocation> {
+    async create(accountId: string, rebel: boolean = false): Promise<CityWithLocation> {
+      const icon = rebel ? `/colony-ships/rebels/${random(1, 6)}.png` : '/colony-ships/01.png';
         const info: City = {
             id: uuid(),
             owner: accountId,
@@ -74,6 +76,7 @@ export class CityRepository extends Repository<City> {
             barracks: 0,
             special_attacker_trainer: 0,
             special_defender_trainer: 0,
+            icon
         };
 
         await this.Insert(info);
@@ -204,7 +207,10 @@ where l.sector_id = ?`, [sector_id]);
             Math.pow((city2.location_y - city1.location_y), 2)
         );
 
-        return _.round(dist/4, 2);
+        // sectors always add 4 hours
+        const sector_dist = Math.abs(city1.sector_id - city2.sector_id) * 6;
+
+        return _.round(dist/4, 2) + sector_dist;
 
     }