/**
 * \file World.h
 * \date 14.04.2003
 *
 * World model interface
 */

#ifndef COMMON_WORLD_WORLD_H
#define COMMON_WORLD_WORLD_H

// For debugging SB and VI recalculation
//#define WORLD_RECALC_DBG DBGN
//#define WORLD_RECALC_DBG DO_NOTHING
#define WORLD_RECALC_DBG TXTN

// For debugging the World contents
//#define WORLD_STATS_DBG DBGN
#define WORLD_STATS_DBG DO_NOTHING
//#define WORLD_STATS_DBG TXTN

#define MAX_PLAYER_AGE 15

class Ball;
class Player;
class Myself;
class State;
class Params;
class Variables;

struct FEEDBACK_DATA;

#include "Player/Interfaces/Synchronization.h"
#include "Common/Protocol/ParseStructs.h"
#include "Common/World/ParamStructs.h"
#include "Common/World/Types.h"
#include "Common/World/Point.h"
#include "Common/Support/DynArray.h"
#include "Common/Support/Debug.h"

/**
 * \class World
 * \author Matus Horvath
 * \author Marek Lehuta
 * \brief World model
 * 
 * All information about player surroundings is in this world model.
 */
class World
{
public:
	void AddEnemyPlayer(Player player);
protected:
	float GetRunProb(Point from, Point to, float distance, int time);

public:
// Construction and destruction
	World();
	World(const World& world);
	virtual ~World();
	
// Operations on the world
	int FindFriendIndex(int uniform) const;
	int FindEnemyIndex(int uniform) const;
	Player* FindFriend(int uniform) const;
	Player* FindEnemy(int uniform) const;

// Internal operations
	// Set up world from server information
	void ProcessInfo(const SENSE_BODY* sb, const VISUAL_INFO* vi);
	// Use stored feedback data to update world
	void ApplyFeedback(FEEDBACK_DATA* fd);
	// Step all objects
	void Step();

	// Re-read player type information and link them to players
	void RelinkPlayerTypes();

// Initialize the synchro variable
	static void BindInterfaces();

	void SetPlayerType(Side side, int uniform, int type);
		
public:
	// Objects world consists of
	Ball* ball;
	Myself* me;

	DynArray<Player, 32> friends;
	DynArray<Player, 32> enemies;

	State* state;
	Params* params;
	Variables* variables;
	
	PLAYER_TYPE* friendTypes[12];

protected:
	void RecalculateFriends(const SENSE_BODY* sb, const VISUAL_INFO* vi);
	void RecalculateEnemies(const SENSE_BODY* sb, const VISUAL_INFO* vi);

private:
	static SynchronizationInterface* synchro;
	
};

#include "Player/World/State.h"
#include "Player/World/Params.h"
#include "Player/World/Variables.h"
#include "Player/World/Ball.h"
#include "Player/World/Player.h"
#include "Player/World/Myself.h"

#endif // COMMON_WORLD_WORLD_H
