#ifndef __MISSILEACTOR_H__
#define __MISSILEACTOR_H__

#include <math.h>
#include <set>
#include "actor.h"

using std::set;

// A missile
class MissileActor : public Actor
{
public:
  enum Type {ENEMY, PLAYER};

public:
  MissileActor(f32 xi, f32 yi, f32 xf, f32 yf, Type owner, int splitafter=-1);
  bool isExploded() {return state == MS_EXPLODE;}
  void explode();
  void split(int n);
  f32 isSplit() {return state == MS_SPLIT;}
  void setSplitParent(MissileActor *parent) {splitParent = parent;}
  f32 getTargetX() {return xf;}
  f32 getTargetY() {return yf;}
  f32 getStartX() {return xi;}
  f32 getStartY() {return yi;}
  f32 getSplitTime() {return splitTime;}
  MissileActor::Type getOwner() {return owner;}
  void notifyExploded();

public:
  void activate();
  void update();
  
  f32 getX() {return x;}
  f32 getY() {return y;}
  f32 getR() {return MRAD;}
  f32 getRotation() {return theta*180.0/M_PI;}
  int getT() {return t;}
  bool isActive() {return state != MS_NULL;}

public:
  Sprite missileTarget;
  Sprite missileCircle;
  Sprite missileLine;

protected:
  const static f32 MSPEED = 3.0;
  const static f32 ENEMYSPEED = 0.5;
  const static f32 MRAD = 1.0;

  enum {
    MS_NULL,
    MS_FLIGHT,  // A missile en route to its target
    MS_EXPLODE, // An exploded missile needs to be swapped for a shockwave
    MS_SPLIT    // A missile that has split into submissiles
  } state;

  f32 xi,yi; // initial coordinates
  f32 xf,yf; // target coordinates
  f32 x,y; // current coordinates
  f32 theta; // orientation
  f32 d; // distance traveled since xi,yi
  f32 maxd; // total distance from xi,yi to xf,yf
  int t;
  Type owner; // who fired the missile
  int splitCount;
  int splitTime;
  MissileActor *splitParent;
};

#endif
