Esempio n. 1
0
void Animal::Update(double dt)
{
	int probability = rand() % 2;
	
	counting++;

	if (counting > 20)
	{
		switch (probability)
		{
		case IDLING:
			Idling();
			break;

		case PATROL:
			Patrolling(dt);
			break;

		case EATING:
			Eating(dt);
			break;

		case DIES:
			Dying(dt);
			break;
		}
		counting = 0.0f;
		timeLimit = rand() % 30 + 20;
	}
	cout << counting << endl;

	if (walking)
		Patrolling(dt);
}
Esempio n. 2
0
void aiEvents::generateEvent()
{
	if (personA->dailyEvents[eventTime] == NULL)
	{
		eventType = ai_schedule1[eventTime];

		if (eventType == EATING)
		{			
			Eating* eating = &Eating(personA,aiList, eventTime);
			eating->generateEating();
			for (std::vector<aiPerson*>::iterator it = eating->aiInvolved.begin(); it != eating->aiInvolved.end(); it++)
			{
				eating->personA = (*it);
				(*it)->dailyEvents[eventTime] = eating;
			}
		}
		else if (eventType == WORKING)
		{
			Working* working = &Working(personA,aiList, eventTime);
			working->generateWorking();
			for (std::vector<aiPerson*>::iterator it = working->aiInvolved.begin(); it != working->aiInvolved.end(); it++)
			{
				working->personA = (*it);
				(*it)->dailyEvents[eventTime] = working;
			}
		}
		else if (eventType == RESTING)
		{
			Resting* resting = &Resting(personA,aiList, eventTime);
			resting->generateResting();
			for (std::vector<aiPerson*>::iterator it = resting->aiInvolved.begin(); it != resting->aiInvolved.end(); it++)
			{
				resting->personA = (*it);
				(*it)->dailyEvents[eventTime] = resting;
			}
		}
		else if (eventType == FIGHTING)
		{	
			Fighting* fighting = &Fighting(personA,aiList, eventTime);
			fighting->generateFighting();
			for (std::vector<aiPerson*>::iterator it = fighting->aiInvolved.begin(); it != fighting->aiInvolved.end(); it++)
			{
				fighting->personA = (*it);
				(*it)->dailyEvents[eventTime] = fighting;
			}
		}
		else if (eventType == OTHER)
		{
			Other* other = &Other(personA,aiList, eventTime);
			other->generateOther();
			for (std::vector<aiPerson*>::iterator it = other->aiInvolved.begin(); it != other->aiInvolved.end(); it++)
			{
				other->personA = (*it);
				(*it)->dailyEvents[eventTime] = other;
			}
		}
	}
}
Esempio n. 3
0
void aiEvents::updateEvent(int stages, aiPerson* person)
{
	ai_event eventType = person->dailyEvents[stages]->eventType;

	if (eventType != ai_schedule1[stages])   //reduece the aiInvolved by 1
	{
		for (std::vector<aiPerson*>::iterator it = person->dailyEvents[stages]->aiInvolved.begin(); it != person->dailyEvents[stages]->aiInvolved.end(); it++)
		{
			if ((*it) == person)
			{
				person->dailyEvents[stages]->aiInvolved.erase(it);
				person->dailyEvents[stages]->possibility *= 0.75;
				break;
			}
		}

		if (eventType ==  WORKING)   //generate new event for the ai
		{
			Working(person,aiList, (ai_time)stages).generateWorkingInterruptive();
		}
		else if (eventType == EATING)
		{
			 Eating(person,aiList, (ai_time)stages).generateEatingInterruptive();
		}
		else if (eventType == RESTING)
		{
			Resting(person,aiList, (ai_time)stages).generateRestingInterruptive();
		}
		else if (eventType == FIGHTING)
		{
			Fighting(person,aiList, (ai_time)stages).generateFightingInterruptive();
		}
		else if (eventType == OTHER)
		{
			 Other(person,aiList, (ai_time)stages).generateOtherInterruptive();
		}
	}
}