function Port() {
  
  this.id = 0;
  
  this.friendly = false;
  
  this.x = 0;
  this.y = 0;
  
  this.hp = 0;
  this.maxHp = 0;
  
  this.smoke;
  
  this.name = 0;
  
  this.destroyed = false;
  
  this.beingAttacked = false;
  
  this.healCountdown = 450;
  
  
  this.init = function(id, friendly, x, y, name) {
    this.id = id;
    this.friendly = friendly;
    this.x = x;
    this.y = y;
    this.name = name;
    
    if(friendly) {
      this.hp = 400;
      this.maxHp = 400;
    } else {
      this.hp = 100;
      this.maxHp = 100;
    }
    
    var pos = map.transform(this.x, this.y);
    this.smoke = new ParticleSystem();
    this.smoke.setType(7);
    this.smoke.setEmitter(pos.x, pos.y - 40);
    this.smoke.setV(-0.25, 0.25, -1.7, -1.5);
    this.smoke.setA(-0.15, 0.15, -0.1, 0.1);
    this.smoke.setLife(60, 80);
  };
  
  
  this.update = function() {
    if(map.paused) {
      return;
    }
    this.healCountdown--;
    if(this.healCountdown == 300) {
      this.beingAttacked = false;
    }
    if(this.healCountdown == 0) {
      this.healCountdown = 450;
      if(this.hp < this.maxHp) {
        if(this.friendly) {
          this.hp += 4;
        } else {
          this.hp++;
        }
        if(this.hp > this.maxHp) {
          this.hp = this.maxHp;
        }
      }
    }
  };
  
  
  this.damage = function(damage) {
    if(!this.destroyed) {
      this.hp -= damage;
      if(this.friendly && !this.beingAttacked) {
        panel.openInfoBox(1);
      }
      this.beingAttacked = true;
      this.healCountdown = 450;
      if(this.hp <= 0) {
        this.destroyed = true;
        if(this.friendly) {
          panel.openInfoBox(4);
        } else {
          ship.gold += 300;
          for(var piratePort in map.piratePorts) {
            if(!map.piratePorts[piratePort].destroyed) {
              map.piratePorts[piratePort].spawnShip(1);
            }
          }
        }
      }
    }
  };
  
  
  this.spawnShip = function(numOfUpgrades) {
    var tries = 0;
    var placedShip = false;
    while(tries < 50 && !placedShip) {
      tries++;
      var spawnX = ((this.x + rand(-1, 2)) * 4) + 1;
      var spawnY = ((this.y + rand(-1, 2)) * 4) + 1;
      if(map.isFreeForPirateShip(spawnX, spawnY)) {
        map.pushPirateShip(spawnX, spawnY, this.id);
        placedShip = true;
      }
    }
  };
  
  
  this.spawnShips = function(numOfShips, numOfUpgrades) {
    for(var i = 0; i < numOfShips; i++) {
      this.spawnShip(numOfUpgrades);
    }
  };
  
  
  this.draw = function() {
    var pos = map.transform(this.x, this.y);
    if(this.friendly) {
      img.draw("homePort", pos.x - 80, pos.y - 120);
    } else {
      img.draw("piratePort", pos.x - 80, pos.y - 120);
    }
    if(!this.destroyed && this.hp < this.maxHp) {
      c.strokeStyle = "rgba(0, 0, 0, 0.4)";
      c.strokeRect(pos.x - 50.5, pos.y - 58.5, 101, 5);
      
      var hpPercentage = 100 * (this.hp / this.maxHp);
      if(hpPercentage <= 10) {
        c.fillStyle = "#f00";
      } else if(hpPercentage <= 40) {
        c.fillStyle = "#fe0";
      } else {
        c.fillStyle = "#0e0";
      }
      c.fillRect(pos.x - 50, pos.y - 58, hpPercentage, 4);
    }
    if(this.destroyed) {
      this.smoke.draw();
    }
  };
  
  
}