コード例 #1
0
void BotRecycler::recycleBot(wstring botType, Bot* botToRecycle)
{
	if (isRegisteredBotType(botType))
	{
		list<Bot *> *recycleBots = recyclableBots[botType];
		recycleBots->push_back(botToRecycle);
	}
}
コード例 #2
0
/*
	It is assumed that a game will have many different types of Bots, thinking
	in different ways, some of them even custom bots defined by the game app rather
	than by this framework. So, in order to make these bots recyclable, we have to
	register them with this recycler so that this recycler knows how to make new
	ones as needed.
*/
void BotRecycler::registerBotType(wstring botType, Bot *sampleBot)
{
	// FIRST MAKE SURE WE DON'T ALREADY HAVE A BUNCH OF RECYCLABLE
	// BOTS FOR THIS TYPE. TO DO THIS, WE USE SOME C++ WEIRDNESS.
	if (!isRegisteredBotType(botType))
	{
		// REGISTER THE BOT
		registeredBotTypes[botType] = sampleBot;
	}
}
コード例 #3
0
/*
	It is assumed that a game will have many different types of Bots, thinking
	in different ways, some of them even custom bots defined by the game app rather
	than by this framework. So, in order to make these bots recyclable, we have to
	register them with this recycler so that this recycler knows how to make new
	ones as needed.
*/
void BotRecycler::registerBotType(wstring botType, Bot *firstBot)
{
	// FIRST MAKE SURE WE DON'T ALREADY HAVE A BUNCH OF RECYCLABLE
	// BOTS FOR THIS TYPE. TO DO THIS, WE USE SOME C++ WEIRDNESS.
	if (!isRegisteredBotType(botType))
	{
		// REGISTER THE BOT
		registeredBotTypes[botType] = firstBot;
		recyclableBots[botType] = new list<Bot*>();
		addMoreBots(botType, RECYCLABLE_BOT_INCREMENT - 1);
	}
}
コード例 #4
0
Bot* BotRecycler::retrieveBot(wstring botType)
{
	// FIRST MAKE SURE THIS IS A REGISTERED BOT TYPE,
	// IF IT IS NOT, WE NEED TO RETURN NULL
	if (!isRegisteredBotType(botType))
	{
		return nullptr;
	}
	else
	{
		// GET THE CORRECT LIST OF BOT TYPES
		list<Bot *> *botsOfTypeWeNeed = recyclableBots[botType];

		// MAKE SURE WE ARE NOT OUT OF THIS TYPE OF BOT
		if(botsOfTypeWeNeed->size() == 0)
			addMoreBots(botType, RECYCLABLE_BOT_INCREMENT);

		// NOW GET THE LAST ELEMENT
		Bot* botToReturn = botsOfTypeWeNeed->back();
		botsOfTypeWeNeed->pop_back();
		return botToReturn;
	}
}