"use strict";

var GO_Enemy = function(){
	// fairly empty, since most init happens in the subclasses
	this.smoke = [];
}

GO_Enemy.prototype = new GameObject(
	new Sprite(
		null,
		"Enemy"
	),
	"Enemy"
	);

	GO_Enemy.prototype.interactions = 
		DEFINE_GAMEOBJECT_INTERACTIONS.DAMAGE |
		DEFINE_GAMEOBJECT_INTERACTIONS.INFLICT;

	// all enemies will do this, but can't until after the
	// sprite is set up
	GO_Enemy.prototype._basicInit = function(def){
		this.name = def.name;

		this.sprite.collision_flags = 
			DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_PASSIVE;// |
			//DEFINE_SPRITE_COLLISION_FLAGS.SPRITES_ACTIVE;
		this.sprite.setBoundingBox(
			def.box[0],
			def.box[1],
			def.box[2],
			def.box[3]);
		//this.sprite.constraints=constraints;
		this.sprite.max_step = def.max_step;

		this.hp = def.hp;
		this.infection = def.infection;
	};

	GO_Enemy.prototype.ai = function(){
		// derp.
	};
	// apply damage and return true if destroyed
	GO_Enemy.prototype.damage = function(source,points){
		return true;
	};
	// return damage to be dealt
	GO_Enemy.prototype._inflictVal = {hp:0, chi:0};
	GO_Enemy.prototype.inflict = function(){
		return this._inflictVal;
	};
	GO_Enemy.prototype.drop = function(){
		return null;
	};

	GO_Enemy.prototype.removeSmoke = function(smoke){
		var index = this.smoke.indexOf(smoke);
		if (index!=-1){
			this.smoke.splice(index,1);
			smoke.host_obj=null;
		}
	};
	GO_Enemy.prototype.infect = function(){
		this.infection++;
	};

	GO_Enemy.prototype.Update = function(){
		this.ai();

		// check HP and destroy
		if (this.hp<=0){
			this._heap.drop = this.drop();
			if (this._heap.drop){
				this._heap.drop.spawnOnSprite(this.sprite,this.manager);
			}

			this._heap.poof = new GO_Poof("FX_splat");
			this._heap.poof.spawnOnSprite(this.sprite,this.manager);
			this._heap.poof = null;

			if (this.clearFromRoom) this.clearFromRoom(this.sprite.map_room);
			else this.sprite.map_room.removeSprite(this.sprite);
			this.manager.remove(this);
		}
	};
	// does the basic make-dangerous-iff-infected check.
	// some enemies may want to be dangerous even when uninfected,
	// so let individual AIs handle the call.
	GO_Enemy.prototype.toggleInteractionsStd = function(){
		if (this.infection>0){
			this.interactions |= 
				DEFINE_GAMEOBJECT_INTERACTIONS.DAMAGE |
				DEFINE_GAMEOBJECT_INTERACTIONS.INFLICT;
		}
		else{
			this.interactions &=
				~DEFINE_GAMEOBJECT_INTERACTIONS.DAMAGE &
				~DEFINE_GAMEOBJECT_INTERACTIONS.INFLICT;
		}
	};