/***************************************************************************
 *            world.h
 *
 *  Fri Jan 28 16:44:05 2005
 *  Copyright  2005  Peter Baldwin
 *  pgbaldwi@uwaterloo.ca
 ****************************************************************************/

#ifndef _WORLD_H
#define _WORLD_H

#include "physics.h"

typedef enum {LEFT=-1,RIGHT=1} roll_direction;
typedef enum {NORTH=-1,SOUTH=1} magnet_pole;
typedef enum {TITLE_LEVEL, TUTORIAL1, TUTORIAL2, TUTORIAL3, TEST_LEVEL, LEVEL1, LEVEL2, LEVEL3, LEVEL4} level;

typedef struct {
	vector pos; //position of entrance
	double n; //number of gnimmels
	double delay; //delay between releases
	roll_direction roll; //direction of release (1 or -1)
	double lastrelease;
} wEntrance;

typedef struct {
	vector pos;
	int n; //number of gnimmels which have exited through this exit
} wExit;
	
typedef struct {
	pObject o; //shape is variable
	bool frozen;
	bool alive;
	bool exited;
	double hangtime; //time that the gnimmel has been in the air, up to 1 sec
	double collisionfree; //time since the gnimmel last collided with another gnimmel
	double magnet;
	double size;
	roll_direction roll; //rolls in this direction by default
	bool dig; //if true, the gnimmel will dig through the next soft block it touches
} wGnimmel;

typedef struct {
	pObject o;
	double w, h;
	bool soft; //can be dug if soft
} wBlock;

typedef struct {
	char * subtitle;
	vector pos;
	double t;
} wSound;

typedef struct {
	vector pos;
	double size;
	magnet_pole pole;
} wMagnet;

typedef struct {
	bool unfreeze;
	bool freeze;
	bool dig;
	double magnet;
	double x,y,w,h;
} wTrigger;

//toggles
extern bool wToggleRoll;
extern bool wToggleExtension;
extern double wAspectRatio;


	
void wInit(level lvl);
void wTick(double t);
wGnimmel *wGetGnimmels(int *count);
wBlock   *wGetBlocks(int *count);
wSound   *wGetSounds(int *count);
wEntrance *wGetEntrances(int *count);
wExit     *wGetExits(int *count);
wMagnet     *wGetMagnets(int *count);

bool	wIsAirborne(wGnimmel *g);
bool    wIsActive(wGnimmel *g);
void    wFreezeGnimmel(wGnimmel *g);
void    wDefrostGnimmel(wGnimmel *g);

int 	wGetGoal(); //returns the number of gnimmels that must exit for success
char   *wGetLevelTitle();
#ifdef TESTING
void wReleaseGnimmel(double x, double y, short roll); //don't allow in final product
#endif

#endif /* _WORLD_H */
