예제 #1
0
파일: Human.cpp 프로젝트: MattWiper/Zombies
int* Human::recruit(City &city, Human* human)
{
	std::vector<int> possiblePos; 
	int y = human->y;
	int x = human->x;
	if (human->m_turncount >= 2)
	{
		human->m_turncount = 0;

		//populate vector with possible random positions for human to spawn 
		if (city.grid[human->x + 1][human->y] == ' ' && human->x < 19) possiblePos.push_back(MoveDirection(SOUTH));
		if (city.grid[human->x - 1][human->y] == ' ' && human->x > 0)	possiblePos.push_back(MoveDirection(NORTH));
		if (city.grid[human->x][human->y + 1] == ' ' && human->y < 19) possiblePos.push_back(MoveDirection(EAST));
		if (city.grid[human->x][human->y - 1] == ' ' && human->y > 0)	possiblePos.push_back(MoveDirection(WEST));
		
		if (possiblePos.size() != 0)
		{
			int pos[2]; 
			//shuffle these elements to ensure randomness 
			auto engine = std::default_random_engine{};
			std::shuffle(std::begin(possiblePos), std::end(possiblePos), engine); //shuffle the elemenets. Only max of 4 -> performace wont take a hit
			
			//create human 
			switch (possiblePos.front())
			{
				case MoveDirection(NORTH):
				{
					pos[0] = human->x - 1; 
					pos[1] = human->y; 
					return pos; 
					break;
				}
				case MoveDirection(SOUTH):
				{
					pos[0] = human->x + 1;
					pos[1] = human->y;
					return pos;
					break; 
				}
				case MoveDirection(EAST):
				{
					pos[0] = human->x;
					pos[1] = human->y + 1;
					return pos;
					break;
				}
				case MoveDirection(WEST):
				{
					pos[0] = human->x;
					pos[1] = human->y - 1;
					return pos;
					break; 
				}
			}
			//vector is on stack -> auto delete
		}
	}
	return NULL;
}
예제 #2
0
파일: Human.cpp 프로젝트: MattWiper/Zombies
void Human::move(City &city)
{
	int movDir = std::rand() % 4;
	int* pos = Human::getPosition();
	int x = pos[0];
	int y = pos[1];

	std::vector<int> possiblePos;
	if (city.grid[this->x + 1][this->y] == ' ' && this->x < 19)	possiblePos.push_back(MoveDirection(SOUTH));
	if (city.grid[this->x - 1][this->y] == ' ' && this->x > 0)	possiblePos.push_back(MoveDirection(NORTH));
	if (city.grid[this->x][this->y + 1] == ' ' && this->y < 19)	possiblePos.push_back(MoveDirection(EAST));
	if (city.grid[this->x][this->y - 1] == ' ' && this->y > 0)	possiblePos.push_back(MoveDirection(WEST));

	if (possiblePos.size() != 0)
	{
		//shuffle these elements to ensure randomness 
		auto engine = std::default_random_engine{};
		std::shuffle(std::begin(possiblePos), std::end(possiblePos), engine); //shuffle the elemenets. Only max of 4 -> performace wont take a hit

		switch (MoveDirection(possiblePos.front()))
		{
		case NORTH:
			//one square north
			{
				this->setPosition(x - 1, y, city, OrganismType(HUMAN));
				city.grid[x][y] = ' ';
			}
			break;
		case SOUTH:
			//one square south 
			{
				this->setPosition(x + 1, y, city, OrganismType(HUMAN));
				city.grid[x][y] = ' ';
			}
			break;
		case WEST:
			{
				this->setPosition(x, y - 1, city, OrganismType(HUMAN));
				city.grid[x][y] = ' ';
			}
			break;
		case EAST:
			//one square east
			{
				this->setPosition(x, y + 1, city, OrganismType(HUMAN));
				city.grid[x][y] = ' ';
			}
			break;
		}
	}
	m_turncount += 1; 
}
예제 #3
0
///*
 // turn right
void PlayerController::Run() {
    DebugPosition();
    bool wasAbleToMove = MoveDirection(moveDirection);
    if (!wasAbleToMove) {
        moveDirection += 1;
        moveDirection = moveDirection % 4;
    }
}
예제 #4
0
void	Pilot_Steer_Vehicle()
{
	if (!NPC->enemy || !NPC->enemy->client)
	{
		return;
	}






// SETUP
//=======
	// Setup Actor Data
	//------------------
	CVec3		ActorPos(NPC->currentOrigin);
	CVec3		ActorAngles(NPC->currentAngles);
				ActorAngles[2]	= 0;
	Vehicle_t*	ActorVeh		= NPCInfo->greetEnt->m_pVehicle;
	bool		ActorInTurbo	= (ActorVeh->m_iTurboTime>level.time);
	float		ActorSpeed		= (ActorVeh)?(VectorLength(ActorVeh->m_pParentEntity->client->ps.velocity)):(NPC->client->ps.speed);


	// If my vehicle is spinning out of control, just hold on, we're going to die!!!!!
	//---------------------------------------------------------------------------------
	if (ActorVeh && (ActorVeh->m_ulFlags & VEH_OUTOFCONTROL))
	{
		if (NPC->client->ps.weapon!=WP_NONE)
		{
			NPC_ChangeWeapon(WP_NONE);
		}
		ucmd.buttons	&=~BUTTON_ATTACK;
		ucmd.buttons	&=~BUTTON_ALT_ATTACK;
		return;
	}

	CVec3		ActorDirection;
				AngleVectors(ActorAngles.v, ActorDirection.v, 0, 0);

	CVec3		ActorFuturePos(ActorPos);
				ActorFuturePos.ScaleAdd(ActorDirection, FUTURE_PRED_DIST);

	bool		ActorDoTurbo	= false;
	bool		ActorAccelerate	= false;
	bool		ActorAimAtTarget= true;
	float		ActorYawOffset	= 0.0f;


	// Setup Enemy Data
	//------------------
	CVec3		EnemyPos(NPC->enemy->currentOrigin);
	CVec3		EnemyAngles(NPC->enemy->currentAngles);
				EnemyAngles[2]	= 0;
	Vehicle_t*	EnemyVeh		= (NPC->enemy->s.m_iVehicleNum)?(g_entities[NPC->enemy->s.m_iVehicleNum].m_pVehicle):(0);
	bool		EnemyInTurbo	= (EnemyVeh && EnemyVeh->m_iTurboTime>level.time);
	float		EnemySpeed		= (EnemyVeh)?(EnemyVeh->m_pParentEntity->client->ps.speed):(NPC->enemy->resultspeed);
	bool		EnemySlideBreak	= (EnemyVeh && (EnemyVeh->m_ulFlags&VEH_SLIDEBREAKING || EnemyVeh->m_ulFlags&VEH_STRAFERAM));
	bool		EnemyDead		= (NPC->enemy->health<=0);

	bool		ActorFlank		= (NPCInfo->lastAvoidSteerSideDebouncer>level.time && EnemyVeh && EnemySpeed>10.0f);

	CVec3		EnemyDirection;
	CVec3		EnemyRight;
				AngleVectors(EnemyAngles.v, EnemyDirection.v, EnemyRight.v, 0);

	CVec3		EnemyFuturePos(EnemyPos);
				EnemyFuturePos.ScaleAdd(EnemyDirection, FUTURE_PRED_DIST);

	ESide		EnemySide		= ActorPos.LRTest(EnemyPos, EnemyFuturePos);
	CVec3		EnemyFlankPos(EnemyFuturePos);
				EnemyFlankPos.ScaleAdd(EnemyRight, (EnemySide==Side_Right)?(FUTURE_SIDE_DIST):(-FUTURE_SIDE_DIST));

	// Debug Draw Enemy Data
	//-----------------------
	if (false)
	{
		CG_DrawEdge(EnemyPos.v,			EnemyFuturePos.v, EDGE_IMPACT_SAFE);
		CG_DrawEdge(EnemyFuturePos.v,	EnemyFlankPos.v, EDGE_IMPACT_SAFE);
	}


	// Setup Move And Aim Directions
	//-------------------------------
	CVec3		MoveDirection((ActorFlank)?(EnemyFlankPos):(EnemyFuturePos));
				MoveDirection	-= ActorPos;
	float		MoveDistance	= MoveDirection.SafeNorm();
	float		MoveAccuracy	= MoveDirection.Dot(ActorDirection);

	CVec3		AimDirection(EnemyPos);
				AimDirection	-= ActorPos;
	float		AimDistance		= AimDirection.SafeNorm();
	float		AimAccuracy		= AimDirection.Dot(ActorDirection);



	if (!ActorFlank && TIMER_Done(NPC, "FlankAttackCheck"))
	{
		TIMER_Set(NPC, "FlankAttackCheck", Q_irand(1000, 3000));
		if (MoveDistance<4000 && Q_irand(0, 1)==0)
		{
			NPCInfo->lastAvoidSteerSideDebouncer	= level.time + Q_irand(8000, 14000);
		}
	}



	// Fly By Sounds
	//---------------
	if ((ActorVeh->m_pVehicleInfo->soundFlyBy || ActorVeh->m_pVehicleInfo->soundFlyBy2) &&
		EnemyVeh &&
		MoveDistance<800 &&
		ActorSpeed>500.0f &&
		TIMER_Done(NPC, "FlybySoundDebouncer")
		)
	{
		if (EnemySpeed<100.0f || (ActorDirection.Dot(EnemyDirection)*(MoveDistance/800.0f))<-0.5f)
		{
			TIMER_Set(NPC, "FlybySoundDebouncer", 2000);
			int soundFlyBy = ActorVeh->m_pVehicleInfo->soundFlyBy;
			if (ActorVeh->m_pVehicleInfo->soundFlyBy2 && (!soundFlyBy || !Q_irand(0,1)))
			{
				soundFlyBy = ActorVeh->m_pVehicleInfo->soundFlyBy2;
			}
			G_Sound(ActorVeh->m_pParentEntity, soundFlyBy);		
		}
	}



// FLY PAST BEHAVIOR
//===================
 	if (EnemySlideBreak || !TIMER_Done(NPC, "MinHoldDirectionTime"))
	{
		if (TIMER_Done(NPC, "MinHoldDirectionTime"))
		{ 
			TIMER_Set(NPC, "MinHoldDirectionTime", 500);	// Hold For At Least 500 ms
		}
		ActorAccelerate		= true;							// Go
		ActorAimAtTarget	= false;						// Don't Alter Our Aim Direction
		ucmd.buttons		&=~BUTTON_VEH_SPEED;			// Let Normal Vehicle Controls Go
	}


// FLANKING BEHAVIOR
//===================
	else if (ActorFlank)
	{
  		ActorAccelerate	= true;
		ActorDoTurbo	= (MoveDistance>2500 || EnemyInTurbo);
		ucmd.buttons	|= BUTTON_VEH_SPEED;			// Tells PMove to use the ps.speed we calculate here, not the one from g_vehicles.c


		// For Flanking, We Calculate The Speed By Hand, Rather Than Using Pure Accelerate / No Accelerate Functionality
		//---------------------------------------------------------------------------------------------------------------
		NPC->client->ps.speed = ActorVeh->m_pVehicleInfo->speedMax * ((ActorInTurbo)?(1.35f):(1.15f));


		// If In Slowing Distance, Scale Down The Speed As We Approach Our Move Target
		//-----------------------------------------------------------------------------
		if (MoveDistance<ATTACK_FLANK_SLOWING)
		{
			NPC->client->ps.speed *= (MoveDistance/ATTACK_FLANK_SLOWING);
			NPC->client->ps.speed += EnemySpeed;

			// Match Enemy Speed
			//-------------------
			if (NPC->client->ps.speed<5.0f && EnemySpeed<5.0f)
			{
				NPC->client->ps.speed = EnemySpeed;
			}

			// Extra Slow Down When Out In Front
			//-----------------------------------
 			if  (MoveAccuracy<0.0f)
			{
				NPC->client->ps.speed *= (MoveAccuracy + 1.0f);
			}

	
			MoveDirection	*=        (MoveDistance/ATTACK_FLANK_SLOWING);
			EnemyDirection	*= 1.0f - (MoveDistance/ATTACK_FLANK_SLOWING);
			MoveDirection	+= EnemyDirection;

			if (TIMER_Done(NPC, "RamCheck"))
			{
				TIMER_Set(NPC, "RamCheck", Q_irand(1000, 3000));
				if (MoveDistance<RAM_DIST && Q_irand(0, 2)==0)
				{
					VEH_StartStrafeRam(ActorVeh, (EnemySide==Side_Left));
				}
			}
		}
	}


// NORMAL CHASE BEHAVIOR
//=======================
	else
	{
		if (!EnemyVeh && AimAccuracy>0.99f && MoveDistance<500 && !EnemyDead)
		{
			ActorAccelerate = true;
			ActorDoTurbo	= false;
		}
		else
		{
			ActorAccelerate = ((MoveDistance>500 && EnemySpeed>20.0f) || MoveDistance>1000);
			ActorDoTurbo	= (MoveDistance>3000 && EnemySpeed>20.0f);
		}
		ucmd.buttons	&=~BUTTON_VEH_SPEED;
	}




// APPLY RESULTS
//=======================
	// Decide Turbo
	//--------------
	if (ActorDoTurbo || ActorInTurbo)
	{
		ucmd.buttons |= BUTTON_ALT_ATTACK;
	}
	else
	{
		ucmd.buttons &=~BUTTON_ALT_ATTACK;
	}

	// Decide Acceleration
	//---------------------
	ucmd.forwardmove = (ActorAccelerate)?(127):(0);



	// Decide To Shoot
	//-----------------
	ucmd.buttons	&=~BUTTON_ATTACK;
	ucmd.rightmove	= 0;
 	if (AimDistance<2000 && !EnemyDead)
	{
		// If Doing A Ram Attack
		//-----------------------
		if (ActorYawOffset!=0)
		{
			if (NPC->client->ps.weapon!=WP_NONE)
			{
				NPC_ChangeWeapon(WP_NONE);
			}
			ucmd.buttons	&=~BUTTON_ATTACK;
		}
 		else if (AimAccuracy>ATTACK_FWD)
		{
			if (NPC->client->ps.weapon!=WP_NONE)
			{
				NPC_ChangeWeapon(WP_NONE);
			}
			ucmd.buttons	|= BUTTON_ATTACK;
		}
		else if (AimAccuracy<AIM_SIDE && AimAccuracy>-AIM_SIDE)
		{
			if (NPC->client->ps.weapon!=WP_BLASTER)
			{
				NPC_ChangeWeapon(WP_BLASTER);
			}

			if (AimAccuracy<ATTACK_SIDE && AimAccuracy>-ATTACK_SIDE)
			{
				//if (!TIMER_Done(NPC, "RiderAltAttack"))
				//{
				//	ucmd.buttons |= BUTTON_ALT_ATTACK;
				//}
				//else
				//{
                    ucmd.buttons |= BUTTON_ATTACK;

			/*		if (TIMER_Done(NPC, "RiderAltAttackCheck"))
					{
						TIMER_Set(NPC, "RiderAltAttackCheck", Q_irand(1000, 3000));
						if (Q_irand(0, 2)==0)
						{
							TIMER_Set(NPC, "RiderAltAttack", 300);
						}
					}*/
				//}
				WeaponThink(true);
			}
			ucmd.rightmove = (EnemySide==Side_Left)?( 127):(-127);
		}
		else
		{
			if (NPC->client->ps.weapon!=WP_NONE)
			{
				NPC_ChangeWeapon(WP_NONE);
			}
		}
	}
	else
	{
		if (NPC->client->ps.weapon!=WP_NONE)
		{
			NPC_ChangeWeapon(WP_NONE);
		}
	}


	// Aim At Target
	//---------------
	if (ActorAimAtTarget)
	{
		MoveDirection.VecToAng();
		NPCInfo->desiredPitch	= AngleNormalize360(MoveDirection[PITCH]);
		NPCInfo->desiredYaw		= AngleNormalize360(MoveDirection[YAW] + ActorYawOffset);
	}
	NPC_UpdateAngles(qtrue, qtrue);
}
예제 #5
0
void Camera::SetPosition(const Vector3D & v)
{
	MoveDirection(v - position);
}
예제 #6
0
void Camera::SetCenter(const Vector3D & v)
{
	MoveDirection(v - center);
}
예제 #7
0
void Camera::UpDown(float s)
{
	MoveDirection(GetAxisY() * s);
}
예제 #8
0
void Camera::LeftRight(float s)
{
    MoveDirection(-GetAxisX() * s);
}
예제 #9
0
void Camera::Move(float s)
{
	MoveDirection(GetAxisZ() * s);
}
예제 #10
0
    void JoystickEntityHandler::MoveJoystick() 
    {
        // Safir::Logging::SendSystemLog(Safir::Logging::Critical,
        //                              L"JoystickEntityHandler::MoveJoystick");
     
             Safir::Dob::EntityProxy entityProxy = m_connection.Read(m_JoystickEntity);
        Consoden::TankGame::JoystickPtr joystick = 
            boost::static_pointer_cast<Consoden::TankGame::Joystick>(entityProxy.GetEntity());

        Consoden::TankGame::Direction::Enumeration newDirection;

        // Make a random movement
        float r = random();
        r = r / RAND_MAX;

        // Since moving backwards will kill the tank, make that unprobable (1%)
        if (r < 0.01) {
            // Backwards (1%)
            newDirection = InvertDirection(m_LastDirection);
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else if (r < 0.41) {
            // Forward (40%)
            newDirection = m_LastDirection;
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else if (r < 0.61) {
            // Turn right (20%)
            newDirection = TurnRight(m_LastDirection);
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else if (r < 0.81) {
            // Turn left (20%)
            newDirection = TurnLeft(m_LastDirection);
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else {
            // Stand still (19%) 
            MoveDirection(Consoden::TankGame::Direction::Neutral, joystick);
        }

        // Set a random fire direction
        r = random();
        r = r / RAND_MAX;
        if (r < 0.25) {
            TowerDirection(Consoden::TankGame::Direction::Left, joystick);
        } else if (r < 0.50) {
            TowerDirection(Consoden::TankGame::Direction::Right, joystick);
        } else if (r < 0.75) {
            TowerDirection(Consoden::TankGame::Direction::Up, joystick);
        } else {
            TowerDirection(Consoden::TankGame::Direction::Down, joystick);
        }

        // Fire?
        r = random();
        r = r / RAND_MAX;
        if (r < 0.2) {
            // Yes! 20%
            Fire(true, joystick);
        } else {
            // No! 80%
            Fire(false, joystick);
        }

    }
void UFallingState::ProcessInput(float DeltaTime)
{
	float xSpeed = Glad->MoveForwardAxis;
	float ySpeed = Glad->MoveRightAxis;
	MoveDirection(xSpeed, ySpeed);
}