#include "rp.h"
#pragma hdrstop

#include "rpreg.h"
#include "rpmssn.h"
#include "rpplayer.h"
#include "rpdirect.h"
#include "crusher.h"
#include "runner.h"
#include "blocker.h"
#include "vtv.h"
#include "vtvpwr.h"
#include "booster.h"
#include "chute.h"
#include "scorzone.h"
#include "demopack.h"
#include "rivet.h"
#include "weapsys.h"
#include "..\munga\mission.h"
#include "..\munga\hostmgr.h"
#include "..\munga\app.h"

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Registry ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//
//#############################################################################
// Registry
//#############################################################################
//
RPRegistry::RPRegistry(ResourceFile *)
{
}

//
//#############################################################################
// ~Registry
//#############################################################################
//
RPRegistry::~RPRegistry()
{
}

//
//#############################################################################
// GetStaticData
//#############################################################################
//
Entity::SharedData*
	RPRegistry::GetStaticData(ClassID class_ID)
{
	switch (class_ID)
	{
	case VTVClassID:
		return &VTV::DefaultData;
	case ScoreZoneClassID:
		return &ScoreZone::DefaultData;
	case RivetClassID:
		return &Rivet::DefaultData;
	case DemolitionPackClassID:
		return &DemolitionPack::DefaultData;
	case RPPlayerClassID:
		return &RPPlayer::DefaultData;
	case CrusherClassID:
		return &Crusher::DefaultData;
	case BlockerClassID:
		return &Blocker::DefaultData;
	case RunnerClassID:
		return &Runner::DefaultData;
	default:
		return Registry::GetStaticData(class_ID);
	}
}

//
//#############################################################################
// GetStaticData
//#############################################################################
//
Player*
	RPRegistry::MakePlayer(Mission *mission)
{
	Check_Pointer(mission);

	RPMission *rp_mission = Cast_Object(RPMission*, mission);

	const char* player_name = rp_mission->GetPositionName();

	int team_id = rp_mission->GetTeamID();

	Logical score_compression;
	score_compression = rp_mission->ScoreCompressionOn();

	int player_bitmap_index = rp_mission->GetPlayerBitmapIndex();

	if (strcmp(player_name, "runner") == 0)
	{
		Runner::MakeMessage
			make_player(
				Runner::MakeMessageID,
				sizeof(Runner::MakeMessage),
				RunnerClassID,
				EntityID::Null,
				ResourceDescription::NullResourceID,
				Runner::DefaultFlags,
				Origin::Identity,
				player_bitmap_index,
				RPPlayer::RunnerPlayerType,
				team_id,
				score_compression
			);
		return new Runner(&make_player);
	}

	else if (strcmp(player_name, "crusher") == 0)
	{
		Crusher::MakeMessage
			make_player(
				Crusher::MakeMessageID,
				sizeof(Crusher::MakeMessage),
				CrusherClassID,
				EntityID::Null,
				ResourceDescription::NullResourceID,
				Crusher::DefaultFlags,
				Origin::Identity,
				player_bitmap_index,
				RPPlayer::CrusherPlayerType,
				team_id,
				score_compression
			);
		return new Crusher(&make_player);
	}

	else if (strcmp(player_name, "blocker") == 0)
	{
		Blocker::MakeMessage
			make_player(
				Blocker::MakeMessageID,
				sizeof(Blocker::MakeMessage),
				BlockerClassID,
				EntityID::Null,
				ResourceDescription::NullResourceID,
				Blocker::DefaultFlags,
				Origin::Identity,
				player_bitmap_index,
				RPPlayer::BlockerPlayerType,
				team_id,
				score_compression
			);
		return new Blocker(&make_player);
	}

	else if (strcmp(mission->GetGameModel(), "camera"))
	{
		RPPlayer::MakeMessage
			make_player(
				RPPlayer::MakeMessageID,
				sizeof(RPPlayer::MakeMessage),
				RPPlayerClassID,
				EntityID::Null,
				ResourceDescription::NullResourceID,
				RPPlayer::DefaultFlags,
				Origin::Identity,
				player_bitmap_index,
				RPPlayer::GeneralPlayerType,
				team_id,
				score_compression
			);
		return new RPPlayer(&make_player);
	}

	else
	{
		RPCameraDirector::MakeMessage create_director(
			RPCameraDirector::MakeMessageID,
			sizeof(RPCameraDirector::MakeMessage),
			CameraDirectorClassID,
			EntityID::Null,
			ResourceDescription::NullResourceID,
			RPCameraDirector::DefaultFlags,
			Origin::Identity,
			player_bitmap_index
		);
		return new RPCameraDirector(&create_director);
	}
}

