Index: binaries/data/mods/public/simulation/components/Gate.js =================================================================== --- binaries/data/mods/public/simulation/components/Gate.js +++ binaries/data/mods/public/simulation/components/Gate.js @@ -15,6 +15,7 @@ Gate.prototype.Init = function() { this.allies = []; + this.garrisoned = []; this.opened = false; this.locked = false; }; @@ -40,6 +41,33 @@ } }; +Gate.prototype.OnGarrisonedUnitsChanged = function(msg) +{ + for (let entity of msg.added) + { + this.garrisoned.push(entity); + + let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction) + if (!cmpObstruction) + continue; + + // Disable 'block movement' and 'block pathfinding' + cmpObstruction.SetDisableBlockMovementPathfinding(true, true, -1); + } + for (let entity of msg.removed) + { + this.garrisoned.splice(this.garrisoned.indexOf(entity), 1); + + let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction) + if (!cmpObstruction) + continue; + + // Enable 'block movement' and 'block pathfinding' + cmpObstruction.SetDisableBlockMovementPathfinding(false, false, -1); + } + this.OperateGate(); +} + /** * Cleanup on destroy */ @@ -123,9 +151,9 @@ this.timer = undefined; } - if (this.opened && (this.allies.length == 0 || this.locked)) + if (this.opened && (this.locked || this.allies.every(entity => this.garrisoned.indexOf(entity) != -1))) this.CloseGate(); - else if (!this.opened && this.allies.length) + else if (!this.opened && this.allies.some(entity => this.garrisoned.indexOf(entity) == -1)) this.OpenGate(); }; @@ -221,7 +249,7 @@ // The gate can't be closed if there are entities colliding with it. var collisions = cmpObstruction.GetEntitiesBlockingConstruction(); - if (collisions.length) + if (collisions.some(entity => this.garrisoned.indexOf(entity) == -1)) { if (!this.timer) { Index: binaries/data/mods/public/simulation/templates/structures/iber_wall_gate.xml =================================================================== --- binaries/data/mods/public/simulation/templates/structures/iber_wall_gate.xml +++ binaries/data/mods/public/simulation/templates/structures/iber_wall_gate.xml @@ -4,6 +4,25 @@ 9.0 + + 3 + Ranged+Infantry + 0.1 + Unit + 0 + 2 + + + 011.50 + + + 411.50 + + + -411.50 + + + iber Biko Sarbide @@ -15,6 +34,7 @@ + structures/iberians/wall_gate.xml