//	ZombieSpawner.cpp - Spawns zombies periodically.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  Niall Moody
//	
//	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 3 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, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#include "drawing/Drawer.h"
#include "GamePlayState.h"
#include "ZombieSpawner.h"
#include "MiscHelper.h"
#include "Random.h"
#include "Zombie.h"

//------------------------------------------------------------------------------
ZombieSpawner::ZombieSpawner(const TwoFloats& pos, const ThreeFloats& col):
NPC(L"ZombieSpawner"),
position(pos),
colour(col),
armour(1.0f)
{
	spawnCount = 90 + Random::getGlobal().getRandomInt(60);
}

//------------------------------------------------------------------------------
ZombieSpawner::~ZombieSpawner()
{

}

//------------------------------------------------------------------------------
void ZombieSpawner::update(GamePlayState& state)
{
	--spawnCount;
	if(spawnCount <= 0)
	{
		float tempAngle = Random::getGlobal().getRandomFloat();
		TwoFloats tempPos(sinf(tempAngle)*28.0f, cosf(tempAngle)*28.0f);
		shared_ptr<NPC> zombie(new Zombie(position+tempPos, colour));

		state.addNpc(zombie);

		spawnCount = 90 + Random::getGlobal().getRandomInt(60);
	}
}

//------------------------------------------------------------------------------
void ZombieSpawner::draw(shared_ptr<Drawer>& d, float timestepInterp)
{
	d->drawImage(L"TurretBaseBottom",
				   position-12.0f,
				   1.0f,
				   0.1875f);
	d->drawImage(L"TurretBaseTop",
				   position-14.0f,
				   1.0f,
				   colour);
}

//------------------------------------------------------------------------------
bool ZombieSpawner::interestedInCollisionsWith(const std::wstring& entity) const
{
	bool retval = false;

	if((entity == L"Bullet") || (entity == L"Shockwave"))
		retval = true;

	return retval;
}

//------------------------------------------------------------------------------
bool ZombieSpawner::collide(const shared_ptr<Collidable>& other, GamePlayState& state)
{
	const std::wstring& n(other->getName());

	if(n == L"Bullet")
		armour -= 0.2f;
	else if(n == L"Shockwave")
		armour -= 0.05f;

	return true;
}
