/* MegaZeux
 *
 * Copyright (C) 1996 Greg Janson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef __DATA_H
#define __DATA_H

#include "compat.h"

__M_BEGIN_DECLS

#include "const.h"
#include "graphics.h"
#include <stdio.h>
#include <stdlib.h>

extern char curr_file[MAX_PATH];
extern char curr_sav[MAX_PATH];
extern char current_dir[MAX_PATH];
extern char config_dir[MAX_PATH];

extern unsigned char scroll_color;        // Current scroll color
extern unsigned char cheats_active;       // (additive flag)
extern unsigned char current_help_sec0;   // Use for context-sens.help
extern int was_zapped;

extern char saved_pl_color;

extern const char *thing_names[128];
extern unsigned int  flags[128];

/*
 *  Change this to an explicit Uint8 instead of an enum.
 *  Rationale: the board isn't really an array of mzx_things, it's an array of
 *  chars. It would be nice if the thing the board was storing was *actually*
 *  an mzx_thing. Enums have a system dependent type.
 *  Also, I don't think things should have ever been signed.
 */
typedef Uint8 mzx_thing;
#define SPACE           0
#define NORMAL          1
#define SOLID           2
#define TREE            3
#define LINE            4
#define CUSTOM_BLOCK    5
#define BREAKAWAY       6
#define CUSTOM_BREAK    7
#define BOULDER         8
#define CRATE           9
#define CUSTOM_PUSH     10
#define BOX             11
#define CUSTOM_BOX      12
#define FAKE            13
#define CARPET          14
#define FLOOR           15
#define TILES           16
#define CUSTOM_FLOOR    17
#define WEB             18
#define THICK_WEB       19
#define STILL_WATER     20
#define N_WATER         21
#define S_WATER         22
#define E_WATER         23
#define W_WATER         24
#define ICE             25
#define LAVA            26
#define CHEST           27
#define GEM             28
#define MAGIC_GEM       29
#define HEALTH          30
#define RING            31
#define POTION          32
#define ENERGIZER       33
#define GOOP            34
#define AMMO            35
#define BOMB            36
#define LIT_BOMB        37
#define EXPLOSION       38
#define KEY             39
#define T_LOCK          40
#define DOOR            41
#define OPEN_DOOR       42
#define STAIRS          43
#define CAVE            44
#define CW_ROTATE       45
#define CCW_ROTATE      46
#define GATE            47
#define OPEN_GATE       48
#define TRANSPORT       49
#define COIN            50
#define N_MOVING_WALL   51
#define S_MOVING_WALL   52
#define E_MOVING_WALL   53
#define W_MOVING_WALL   54
#define POUCH           55
#define PUSHER          56
#define SLIDER_NS       57
#define SLIDER_EW       58
#define LAZER           59
#define LAZER_GUN       60
#define BULLET          61
#define MISSILE         62
#define FIRE            63
#define FOREST          65
#define LIFE            66
#define WHIRLPOOL_1     67
#define WHIRLPOOL_2     68
#define WHIRLPOOL_3     69
#define WHIRLPOOL_4     70
#define INVIS_WALL      71
#define RICOCHET_PANEL  72
#define RICOCHET        73
#define MINE            74
#define SPIKE           75
#define CUSTOM_HURT     76
#define T_TEXT          77
#define SHOOTING_FIRE   78
#define SEEKER          79
#define SNAKE           80
#define EYE             81
#define THIEF           82
#define SLIMEBLOB       83
#define RUNNER          84
#define GHOST           85
#define DRAGON          86
#define FISH            87
#define SHARK           88
#define SPIDER          89
#define GOBLIN          90
#define SPITTING_TIGER  91
#define BULLET_GUN      92
#define SPINNING_GUN    93
#define BEAR            94
#define BEAR_CUB        95
#define MISSILE_GUN     97
#define SPRITE          98
#define SPR_COLLISION   99
#define IMAGE_FILE      100
#define SENSOR          122
#define ROBOT_PUSHABLE  123
#define ROBOT           124
#define SIGN            125
#define SCROLL          126
#define PLAYER          127
#define NO_ID           255

#define is_fake(id)                                       \
  ((id == SPACE) || ((id >= FAKE) && (id <= THICK_WEB)))  \

#define is_robot(id)                                      \
  ((id == ROBOT) || (id == ROBOT_PUSHABLE))               \

#define is_signscroll(id)                                 \
  ((id == SIGN) || (id == SCROLL))                        \

#define is_water(id)                                      \
  ((id >= STILL_WATER) && (id <= W_WATER))                \

#define is_whirlpool(id)                                  \
  ((id >= WHIRLPOOL_1) && (id <= WHIRLPOOL_2))            \

#define is_enemy(id)                                      \
  ((id >= SNAKE) && (id <= BEAR_CUB) &&                   \
   (id != BULLET_GUN) && (id != SPINNING_GUN))            \

#define is_storageless(id)                                \
  (id < SENSOR)                                           \

typedef enum
{
  IDLE    = 0,
  NORTH   = 1,
  SOUTH   = 2,
  EAST    = 3,
  WEST    = 4,
  RANDNS  = 5,
  RANDEW  = 6,
  RANDNE  = 7,
  RANDNB  = 8,
  SEEK    = 9,
  RANDANY = 10,
  BENEATH = 11,
  ANYDIR  = 12,
  FLOW    = 13,
  NODIR   = 14,
  RANDB   = 15,
  RANDP   = 16,
  CW      = 32,
  OPP     = 64,
  RANDNOT = 128
} mzx_dir;

#define is_cardinal_dir(d)                                \
  ((d >= NORTH) && (d <= WEST))                           \

#define dir_to_int(d)                                     \
  ((int)d - 1)                                            \

#define int_to_dir(d)                                     \
  ((mzx_dir)(d + 1))                                      \

static const int CAN_PUSH      = 0x001;
static const int CAN_TRANSPORT = 0x002;
static const int CAN_LAVAWALK  = 0x004;
static const int CAN_FIREWALK  = 0x008;
static const int CAN_WATERWALK = 0x010;
static const int MUST_WEB      = 0x020;
static const int MUST_THICKWEB = 0x040;
static const int REACT_PLAYER  = 0x080;
static const int MUST_WATER    = 0x100;
static const int MUST_LAVAGOOP = 0x200;
static const int CAN_GOOPWALK  = 0x400;
static const int SPITFIRE      = 0x800;

typedef enum
{
  NO_HIT      = 0,
  HIT         = 1,
  HIT_PLAYER  = 2,
  HIT_EDGE    = 3
} move_status;

typedef enum
{
  EQUAL                 = 0,
  LESS_THAN             = 1,
  GREATER_THAN          = 2,
  GREATER_THAN_OR_EQUAL = 3,
  LESS_THAN_OR_EQUAL    = 4,
  NOT_EQUAL             = 5,
} mzx_equality;

typedef enum
{
  WALKING               = 0,
  SWIMMING              = 1,
  FIRE_WALKING          = 2,
  TOUCHING              = 3,
  BLOCKED               = 4,
  ALIGNED               = 5,
  ALIGNED_NS            = 6,
  ALIGNED_EW            = 7,
  LASTSHOT              = 8,
  LASTTOUCH             = 9,
  RIGHTPRESSED          = 10,
  LEFTPRESSED           = 11,
  UPPRESSED             = 12,
  DOWNPRESSED           = 13,
  SPACEPRESSED          = 14,
  DELPRESSED            = 15,
  MUSICON               = 16,
  SOUNDON               = 17
} mzx_condition;

typedef enum
{
  ITEM_KEY              = 1,
  ITEM_COINS            = 2,
  ITEM_LIFE             = 3,
  ITEM_AMMO             = 4,
  ITEM_GEMS             = 5,
  ITEM_HEALTH           = 6,
  ITEM_POTION           = 7,
  ITEM_RING             = 8,
  ITEM_LOBOMBS          = 9,
  ITEM_HIBOMBS          = 10,
} mzx_chest_contents;

typedef enum
{
  POTION_DUD            = 0,
  POTION_INVINCO        = 1,
  POTION_BLAST          = 2,
  POTION_SMALL_HEALTH   = 3,
  POTION_BIG_HEALTH     = 4,
  POTION_POISON         = 5,
  POTION_BLIND          = 6,
  POTION_KILL           = 7,
  POTION_FIREWALK       = 8,
  POTION_DETONATE       = 9,
  POTION_BANISH         = 10,
  POTION_SUMMON         = 11,
  POTION_AVALANCHE      = 12,
  POTION_FREEZE         = 13,
  POTION_WIND           = 14,
  POTION_SLOW           = 15
} mzx_potion;

typedef enum
{
  TARGET_NONE           = 0,
  TARGET_POSITION       = 1,
  TARGET_ENTRANCE       = 2,
  TARGET_TELEPORT       = 3
} mzx_board_target;

__M_END_DECLS

#endif // __DATA_H
