/************************************/
/* Warcraft Tower Defense - by Noda */
/* Types definitions       21/01/08 */
/************************************/

#ifndef __TYPES__
#define __TYPES__

// Includes
#include "defines.h"    // Defines


// highscore structure
typedef struct _score {
    bool valid;         // is that score valid?
    bool finished;      // was the map finished?
    u8 finish_diff;     // at which difficulty?
    u8 score_diff;      // difficulty level where the score was made    
    int map_size;       // map size for idenficication (for new map format, this is a random num generated by the editor)
    int map_sum;        // map magic sum for identification
    u32 score;          // the score
} score;

// simple map descriptor
typedef struct _map_desc {
    char name[MAP_NAME_MAX];   // map name
    void* file;                // pointer to the map file
    char filename[256];        // map filename (if fatlib is used)
} map_desc;

// Sfx structure
typedef struct _sfx {
    void* data;     // sound data
    u32 size;       // sound size
    u8 type;        // sound type
    u8 volume;      // sound volume
    u8 pan;         // sound panning
} sfx;

// Tower descriptor
typedef struct _tower {
    char name[NAME_MAX];        // name of the tower
    char desc[DESC_MAX];        // tower description
    u8 pal;                     // palette num of the tower
    u8 gfx_idx;                 // gfx index
    u8 icon_idx;                // gfx icon of the tower (index)
    u8 attack_type;             // attack type
    u8* sound;                  // attack sound
    u32 sound_size;             // attack sound size
    u16 price;                  // price of the tower
    u16 minDamage;              // minimum damage
    u16 maxDamage;              // maximum damage
    u16 speed;                  // speed of projectiles
    u16 reload;                 // reload delay (in vbl)
    u16 range;                  // attack range (in pixels)
    bool air;                   // attack air
    bool ground;                // attack ground
    bool dark;                  // dark variation
    u8 num_sp;                   // number of special effects
    u8 special[SPECIAL_MAX];    // special effects
    s16 spParams[SPECIAL_MAX][SP_PARAMS];    // special effects parameters
    u8 num_upgrades;            // number of possible upgrades
    u8 upgrades[UPGRADES_MAX];  // tower upgrades
    u8 evo_min;                 // minimum evolution to build this tower
} tower;

// Round descriptor
typedef struct _round {
    char comment[COMMENTS_MAX]; // comments for this round
    u8 number[MAX_PATHS];       // number of monsters
    u16 type;                    // type of monsters
    u8 spawn_rate[MAX_PATHS];    // spawn rate of monsters
    u16 nextround_delay;         // delay for next round (in sec)
    u16 gold_bonus;              // gold bonus for finishing the round
    u8 mps_method;               // method of spawning when multiple paths are used
    
} round;

// Evolution descriptor
typedef struct _evolution {
    char name[NAME_MAX];      // name of the evolution
    char info[INFO_MAX];      // information about evolution
    u8 icon_idx;               // gfx icon of the evolution (index)
    u8 build_icon_idx;         // build gfx icon (index)
    u16 price;                 // price of the evolution
    u8 minRound;               // round min. for accessing this evolution
    u8 num_towers;             // number of towers for this evolution
    u8 towers[EVO_TOWERS];     // towers of the evolution
    u8 max_towers;             // max towers bonus for this evolution
} evolution;

// clan descriptor
typedef struct _clan {
    char name[NAME_MAX];       // clan name
    char info[INFO_MAX];       // clan information
    u8 icon_idx;                // gfx icon index
    u8 num_evolutions;          // number of evolution levels
    evolution* evolutions;      // towers by evolution levels
} clan;

// Monster descriptor
typedef struct _monster {
    char name[NAME_MAX];     // name of the monster
    void* gfx;               // gfx of the monster
    u8* sound;                // death sound
    u32 sound_size;           // death sound size
    u8 death_anims;           // number of death animation frames
    bool hide_corpse;        // don't show the corpse of the monster after its death
    bool air;                // is an air monster
    bool no_anim;            // no animation for this monster (boats)
    bool ghost;              // is transparent?
    u8 size;                  // monster size: 0=big, 1=normal, 2=mini
    u8 pal;                   // palette num of the monster
    bool invisible;           // is invisible
    u16 gold_bonus;           // gold bonus for killing
    int life;                 // life of the monster
    u16 armor;                // armor of the monster
    u8 speed;                 // walk speed of the monster (must be a 16 divisor, and <= 16)
    u8 num_immunes;            // number of immunes
    u8 immune[IMMUNE_MAX];    // immunes
    s16 imParams[IMMUNE_MAX][IM_PARAMS]; // immunes parameters
    u8 anim_speed;            // animation speed
} monster;

// Monster basics
typedef struct _monster_base {
    void* gfx;               // gfx of the monster
    u8* sound;                // death sound
    u32 sound_size;           // death sound size
    u8 death_anims;           // number of death animation frames
    bool hide_corpse;        // don't show the corpse of the monster after its death
    bool air;                // is an air monster
    bool no_anim;            // no animation for this monster (boats)
} monster_base;

// Map descriptor
typedef struct _map {
    char name[MAP_NAME_MAX];    // name of the map
    char welcome[WELCOME_MAX];  // welcome message
    bool simple_presentation;   // choose simple or normal presentation screen
    char presentation[PRESENTATION_MAX];    // presentation message
    u16* map_Pal;                // map gfx
    u8* map_Tiles;
    u16* map_Map;
    int map_Width;
    int map_Height;
    u8* minimap_Sprite;         // minimap gfx
    u16* minimap_Pal;           // minimap palette
    u16 minimap_x_adjust;       // minimap x adjustement
    u16 minimap_y_adjust;       // minimap y adjustement
    s32 start_x;                // initial x view position
    s32 start_y;                // initial y view position
    u8* m_path;                 // monsters space
    u8* t_path;                 // towers space
    s32 spawn_x;                // x spawn position
    s32 spawn_y;                // y spawn position
    u16 gold_start;             // amount of gold at start
    u8 sell_pct;                // amount of gold refunded when selling a tower (in %)
    u16 max_towers_start;       // max towers at start
    u16 init_delay;             // initial delay before start (in sec)
    u16 lifes;                  // number of lives
    bool timed_gold;            // gold increase each second by round.gold_bonus instead of gaining it after finishing it
    u16 initial_bonus;          // only useful when timed_gold is on, starting gold bonus / sec
    bool w3_damage_style;       // standard (min. 0 damage) / W3 damage style (min. 1 damage)
    u8 minimap_colors;          // minimap colors
    bool fast_pathfinder;       // use the fast pathfinder or the normal one
    u8 num_paths;               // number of paths
//    u8 num_waypoints;           // number of waypoints * 2
//    u16* waypoints;             // the waypoints
    u8 num_waypoints[MAX_PATHS];       // number of waypoints * 2
    u16* waypoints[MAX_PATHS];  // the waypoints
    u8 numRounds;               // number of rounds
    round* rounds;              // the rounds
    tower* towers;              // the towers
    u8 numClans;                // number of clans
    clan* clans;                // the clans
    monster* monsters;          // the monsters
} map;

// Tower instance
typedef struct _tower_instance {
    u8 type;            // tower type
    s32 pos_x;          // x position
    s32 pos_y;          // y position
    bool attack;       // attack state
    u16 reload;         // reload delay
    u8 id;              // sprite id
} tower_instance;

// Attack instance
typedef struct _attack_instance {
    s32 pos_x;          // x position
    s32 pos_y;          // y position
    u8 dir;             // direction
//    u8 cycle;           // animation cycle
    u8 id;              // sprite id
    bool explode;       // explode animation
//    u8 tower_idx;       // parent tower index
    u8 monster_idx;     // monster attacked index
} attack_instance;

// Monster instance
typedef struct _monster_instance {
    u8 type;            // monster type
    s32 pos_x;          // x position
    s32 pos_y;          // y position
    s32 last_x;         // last moved position (to forbid tower placement on monster)
    s32 last_y;
    u8 dir;             // direction of the monster
    u8 last_dir;        // last direction of the monster
    u8 wp;              // waypoint number
    int life;           // monster life
    bool transp;        // boolean for alpha blending effect
    s16 slow;           // slow effect counter
    s16 slow2;          // slow effect counter 2
    s16 slow_time;      // slow effect remaining time
    s16 slow_param1;    // initial slow parameter 1
    s16 slow_param2;    // initial slow parameter 2
    s16 poison;         // poison effect counter
    s16 poison_time;    // poison effect remaining time
    s16 poison_param1;  // initial poison parameter 1
    s16 poison_param2;  // initial poison parameter 2
    u8 id;              // sprite id
    u8 steps;           // 
    u8 cycle;           // animation cycle
    u8 wait;            // vbl to wait before animate
    bool reverse;      // reversed animation
    bool step;         // step of the animation
    bool dead;         // dead animation
    bool visible;      // is visible
    u8 ai_count;        // used to even ai path
    u8 path;            // path followed
} monster_instance;

#endif
