/*
 * Stonage: a puzzle game
 * Copyright (C) 2001 Luc Saillard <luc@saillard.org>
 *
 * Header file for loading, manage Level file
 * 
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 */

#ifndef __LEVEL_H
#define __LEVEL_H

#include "square.h"
#include "list.h"
#include "sprites.h"

#ifndef _NO_GFX_

#include <SDL.h>

struct t_level
{
  int sizex, sizey, nsquares;
  struct t_square *squares;
  int *map;
  SDL_Surface *background;
  SDL_Surface *timebar;        /* The look of the time bar who was precalculated */
  SDL_Surface *board;          /* The board at bottom of the screen */
  char *comment;
  const char *theme;           /* name of theme use by this level */
  enum                         /* This is the state machine ... */
   {
     CONTROL_PLAYER   = 1,
     CONTROL_KINESIST = 2,
     CONTROL_SQUARE   = 4
   } control;
  int xdino,ydino;		/* Dinosaur position in the playfield */
  int xdino_old,ydino_old;	/* Last Dinosaur position in the playfield */

  /* Kinesist part */
  
  int   xkinesist, ykinesist;	/* Position of the telekinesist */
  int   update_kinesist_sprite; /* a boolean that indicate we need to update kinesist_sprite */
  List *kinesists_selected;     /* Kinesist sprites when the kinesist is selected */
  List *kinesists_notselected;  /* Kinesist sprites when the kinesist is not selected */
  List *kinesist_sprite;        /* a pointer that move in the 2 precedent list */

  /* Dinosaur part */
  struct t_dinosaur dinosaur;

  int start_x,start_y;		/* Start square position */
  int keys_red;
  int keys_blue;
  int keys_green;               /* List of key we have collected */

  /* Time is in number of milliseconds */
  int time_start; /* Time when the game have started */
  
  int times[3];                 /* Times to complete the level */
};

enum movement_type
{
  MOVE_DOWN=0,
  MOVE_UP=1,
  MOVE_RIGHT=2,
  MOVE_LEFT=3
};

enum sprite_index
{
  SPRITE_DINOSAUR=0,
  SPRITE_KINESIST_NOTSELECTED,
  SPRITE_KINESIST_SELECTED,
  SPRITE_KEY_RED,
  SPRITE_KEY_BLUE,
  SPRITE_KEY_GREEN,
  SPRITE_NEED_KEY_RED,
  SPRITE_NEED_KEY_BLUE,
  SPRITE_NEED_KEY_GREEN,
  SPRITE_HOURGLASS,
  SPRITE_MAX
};

enum e_difficulty
{
  DIFFICULT_EASY=0,
  DIFFICULT_MEDIUM=1,
  DIFFICULT_HARD=2,
  DIFFICULT_LEVEL=DIFFICULT_HARD+1
};

extern struct enum_list level_sprites[];

int Level_Sanity_Check(struct t_level *l);
int Level_Draw2Screen(struct t_level *l,SDL_Surface *screen);
int Level_MoveDinoTo(struct t_level *l, enum movement_type direction, int automove);
int Level_MoveKinesistTo(struct t_level *l, enum movement_type direction);
int Level_CanMoveSquare(const struct t_level *l);
int Level_MoveSquareTo(struct t_level *l, enum movement_type direction);
int Level_IsFinish(struct t_level *l);
int Level_DoPostMoveAction(struct t_level *l);
void Level_Free(struct t_level *l);

#endif


#endif

