Beispiel #1
0
void Enemy::AI()
{
	if( generated == false )
	{
		GenerateRandomPath();
		generated = true;
	}
	attacking = false;
	switch( myAI )
	{
	case PATHWALK: //   ---  PATHWALK ---
	PathWalk();
		break;
	case FOLLOW:
		Follow();
		break;
	case COMBAT:
		Combat();
		break;
	case RANDOM_PATHWALK:
		break;
	case RETURN_TO_PATHWALK:
		ReturnToPathWalk();
		break;
	default:
		break;
	}

	myWeapon->Logic(attacking,heroPosition);
}
int BrigadeClass::CheckTactic (int tid)
	{
	Objective	o;

	if (tid < 1)
		return 0;
	if (haveWeaps < 0)
		{
		FalconEntity	*e;
		GridIndex		x,y,dx,dy;

		e = GetTarget();
		if (Engaged() && !e)
			SetEngaged(0);
		if (GetUnitSupply() > 20)
			haveWeaps = 1;
		else
			haveWeaps = 0;
		GetLocation(&x,&y);
		o = GetUnitObjective();
		ourObjOwner = 0;
		if (o && o->GetTeam() == GetTeam())
			ourObjOwner = 1;
		if (o)
			o->GetLocation(&dx,&dy);
		else
			GetUnitDestination(&dx,&dy);
		ourObjDist = FloatToInt32(Distance(x,y,dx,dy));
		}
	if (!CheckUnitType(tid, GetDomain(), GetType()))
		return 0;
	if (!CheckTeam(tid,GetTeam()))
		return 0;
	if (!CheckEngaged(tid,Engaged()))
		return 0;
	if (!CheckCombat(tid,Combat()))
		return 0;
	if (!CheckLosses(tid,Losses()))
		return 0;
	if (!CheckRetreating(tid,Retreating()))
		return 0;
	if (!CheckAction(tid,GetUnitOrders()))
		return 0;
	if (!CheckOwned(tid,ourObjOwner))
		return 0;
	if (TeamInfo[GetTeam()]->GetGroundAction()->actionType != GACTION_OFFENSIVE && !CheckRole(tid,0))
		return 0;
	if (!CheckRange(tid,ourObjDist))
		return 0;
//	if (!CheckDistToFront(tid,ourFrontDist))
//		return 0;
	if (!CheckStatus(tid,Broken()))
		return 0;
//	if (!CheckOdds(tid,odds))
//		return 0;
	return GetTacticPriority(tid);
	}
Beispiel #3
0
void TestCombat()
{
	int humanLoc = 0;
	int enemyLoc = 2;
	StringOO name = "Barry";
	int strength = 10;
	int health = 100;
	int luck = 10;
	int intellegence = 10;

	Human * humanPtr = new Human(humanLoc, name, strength, health, luck, intellegence);
	const int enemyNum = 5;
	Enemy * Enemies[enemyNum] = {};
	InitEnemies(Enemies, enemyNum);
	//Enemy * enemyPtr = new Enemy(enemyLoc, name, strength, health, luck);

	for (int i = 0; i < enemyNum; i++)
	{
		Combat(*humanPtr, *Enemies[i]);
	}
}
Beispiel #4
0
//the primary method for the game
//initializes the level and loops until the level is beaten
void Game::playLevel()
{
	//re-saves the player's stats
	al.SaveStats();

	char dir;
	int x, y;
	string place;

	bool bossBeaten = false;
	bool keyFound = false;
	bool moved = false;

	//creates and stores the first 2 bosses
	Enemy** bosses = new Enemy*[2];
	bosses[0] = new Dragon();
	bosses[1] = new Gorilla();

	//creates the final boss
	Seminole s;

	//creates the random enemies that will pop up throughout the game
	//type 1 is weaker than type 2
	Enemy** type1 = new Enemy*[3];
	Enemy** type2 = new Enemy*[3];

	//prints out the intro screen based on the level
	switch (level)
	{
	case 1:
		Level1IntroScrn();
		break;

	case 2:
		Level2IntroScrn();
		break;

	case 3:
		Level3IntroScrn();
		break;
	}

	//stores the maps data in a game field
	mapData = map.getMapData();

	//place character: bottom middle
	x = (map.getColumns() - 1) / 2;
	y = map.getRows() - 1;
	al.SetLocation(x, y);

	//a random number generator that will determine what events take place in the game
	uniform_int_distribution < mt19937::result_type > dist(1, 100);
	mt19937 gen = al.GetGen();
	int random;

	//loops until the player quits or the boss is beaten
	while (playing == true && !bossBeaten)
	{
		//checks if al has enough experience to level up
		if (al.GetExperience() >= al.GetLevelUpEXP())
		{
			al.LevelUp();
			LevelUpScrn();
		}

		//prints out the map screen
		update();

		//reverts the values stored in game at the start of each loop
		message = "";
		random = dist(gen);
		moved = false;

		//sets x and y to the player's new location
		x = al.GetxLocation();
		y = al.GetyLocation();

		//adds new enemies to the enemy type vectors to randomize their levels
		type1[0] = new Bat();
		type1[1] = new Rhino();
		type1[2] = new Centaur();

		type2[0] = new Scorpion();
		type2[1] = new Tiger();
		type2[2] = new Griffin();

		//if possible -> move
		dir = getch();

		switch (dir)
		{
		case 'w':
			//if possible, move up
			if ((y - 1) >= 0 && allow[y - 1][x])
			{
				al.MoveUp();
				moved = true;
			}
			break;
		case 's':
			//if possible, move down
			if ((y + 1) < map.getRows() && allow[y + 1][x])
			{
				al.MoveDown();
				moved = true;
			}
			break;
		case 'a':
			//if possible, move left
			if ((x - 1) >= 0 && allow[y][x - 1])
			{
				al.MoveLeft();
				moved = true;
			}
			break;
		case 'd':
			//if possible, move right
			if ((x + 1) < map.getColumns() && allow[y][x + 1])
			{
				al.MoveRight();
				moved = true;
			}
			break;
		case '3':
			//if possible, eat
			message = al.Eat();
			break;
		case '4':
			//if possible, drink
			message = al.Drink();
			break;
		case 'q':
			//calls quit screen
			QuitScrn();
			break;
		default:
			//creates error if invalid key is pressed
			message = "Invalid key pressed!";
			break;
		}

		//runs if the player has moved on the map
		if (moved)
		{
			//with new position
			x = al.GetxLocation();
			y = al.GetyLocation();

			//stores the place value located at the player's location
			place = mapData[y][x];

			//triggers if the player enters a house
			if (place.compare("H") == 0)
			{
				//find food
				if (random <= 75)
				{
					message = "You found some food in the House";
					al.FindFood();
				}
				//trigger non-fleeable combat
				if (random > 75 && random <= 85)
				{
					playing = NFCombat(&al, type1[level - 1]);
				}
				//find bed and sleep
				if (random > 85 && random <= 95)
				{
					message = "You found a nice comfy bed. Gained health && stamina!";
					al.Sleep();
				}
				//stub toe and lose health
				if (random > 95)
				{
					message = "You stubbed your toe! You lost 5 health!";
					al.ChangeHealth(-5);
				}
				//makes the house no longer enterable
				allow[y][x] = 0;
			}
			//triggers if the player enters a tower
			else if (place.compare("T") == 0)
			{
				//combat with an enemy of both type
				playing = NFCombat(&al, type1[level - 1]);
				playing = NFCombat(&al, type2[level - 1]);

				//if the player survives he gets the key to the boss
				if (playing)
				{
					keyFound = true;
				}
				//makes the tower no longer enterable
				allow[y][x] = 0;
			}
			//triggers if the player finds a gatorade machine
			else if (place.compare("G") == 0)
			{
				//find gatorade
				al.FindGatorade();
				message = "You found a Gatorade machine! Your Gatorade has increased!";
				allow[y][x] = 0;
			}
			//triggers if the player enters barracks
			else if (place.compare("M") == 0)
			{
				//step on landmine
				if (random <= 10)
				{
					message = "You stepped on a landmine";
					al.ChangeHealth(-20);
				}
				//find extra food
				if (random > 10 && random <= 30)
				{
					message = "You found some army rations!";
					al.FindFood();
					al.FindFood();
				}
				//fight two strong enemies
				if (random > 30 && random <= 50)
				{
					playing = NFCombat(&al, type2[level - 1]);
					playing = NFCombat(&al, type2[level - 1]);
				}
				//fight a strong and weak enemy
				if (random > 50 && random <= 65)
				{
					playing = NFCombat(&al, type1[level - 1]);
					playing = NFCombat(&al, type2[level - 1]);
				}
				//caught in a booby trap and lose health
				if (random > 65 && random <= 75)
				{
					message = "You got caught in a booby trap, oops!";
					al.ChangeHealth(-5);
				}
				//find scale and gain stamina
				if (random > 75 && random <= 97)
				{
					message = "You found one of Alberta's scales! Your stamina returns!";
					al.ChangeStamina(10);
				}
				//fight 3 monsters
				if (random > 97)
				{
					playing = NFCombat(&al, type2[level - 1]);
					playing = NFCombat(&al, type1[level - 1]);
					playing = NFCombat(&al, type2[level - 1]);
				}
				//makes the barracks no longer enterable
				allow[y][x] = 0;
			}
			//level boss
			else if (place.compare("B") == 0)
			{
				//key used to fight boss
				if (keyFound)
				{
					//first two bosses
					if (level < 3)
					{
						bossBeaten = NFCombat(&al, bosses[level - 1]);
						playing = bossBeaten;
					}
					//final boss
					if (level == 3)
					{
						bossBeaten = FinalBossCombat(&al, &s);
						playing = true;
					}

					if (bossBeaten)
					{
						//beat game
						if (level == 3)
						{
							BeatGameScrn();
						}
						//move to next level
						else
						{
							loadNextLevel();
						}
					}
				}
				else
				{
					message = "You must find the key before you can battle the boss!";
				}
			}
			else //if place="//"
			{
				if (random <= 17)
				{
					//chooses randomly type 1 or type 2 enemy for level
					random = dist(gen);
					if (random <= 62)
					{
						playing = Combat(&al, type1[level - 1]);
					}
					else
					{
						playing = Combat(&al, type2[level - 1]);
					}
				}
			}
		}

		//check to see if player is dead or quit
		if (al.GetHealth() == 0 || (!playing && !bossBeaten && !quit))
		{
			GameOverScrn();
		}

		//cleans the game if you are no longer playing
		if (playing == false)
		{
			Clean(bosses, type1, type2);
		}

		//removes old enemies so that new enemies can be initialized at the beginning of the loop
		for (int i = 0; i < 3; i++)
		{
			delete type1[i];
			delete type2[i];
		}
	}
}
Beispiel #5
0
void main(void)
{
    byte tbfr, tbfl, tbrr, tbrl;
    
    DisableInterrupts;
    SOPT = 0x00; //disable watchdog
    
    ICGC1 = 0b01110100; // select external crystal
    Delay(64);  // start up delay for crystal
    SCISetup(); // setup serial communication via RS-232 I/F
    
    //--------------------------------------------------------
    // Initialization
    //--------------------------------------------------------
    // for motor driving with PWM from TPM1
    TPM1SC = 0b00001000;    // edge-aligned PWM on bus clock
    TPM1MOD = (word)(pwmPeriod * busClock * 1000);  // set PWM period
    TPM1C2SC = 0b00101000;  // edge-aligned PWM with high-true pulses for PTF0 (left motor IN_A)
    TPM1C3SC = 0b00101000;  // edge-aligned PWM with high-true pulses for PTF1 (left motor IN_B)
    TPM1C4SC = 0b00101000;  // edge-aligned PWM with high-true pulses for PTF2 (right motor IN_A)
    TPM1C5SC = 0b00101000;  // edge-aligned PWM with high-true pulses for PTF3 (right motor IN_B)

    // for motor speed control with timer overflow interrupt of TPM2
    TPM2SC = 0b01001000;    // enable timer overflow and input capture on bus rate clock
    TPM2MOD = (word)(controlPeriod * busClock * 1000);  // set motor speed control period
    TPM2C0SC = 0b01000100;  // enable interrups on positive edge for PTF4 (left tachometer)
    TPM2C1SC = 0b01000100;  // enable interrups on positive edge for PTF5 (right tachometer)
    diffLeft = 0;           // difference between two consecutive counter values for left motor
    diffRight = 0;          // difference between two consecutive counter values for right motor
    travelDistance = 0;     // distance to travel; one unit is approximately 05 mm
    scaleFactor = 200;      // scale factor used in motor speed control
    nomSpeed = 0x2000;      // nominal speed
    pwLeft = defaultSpeed;  // PWM duty cycle for left motor
    pwRight = defaultSpeed; // PWM duty cycle for right motor
    pwMax = 90;             // maximum for PWM duty cycle
    pwMin = 40;             // minimum for PWM duty cycle

    // for ADC
    ADC1CFG = 0b00000000;   // on bus clock, 8-bit conversion
    APCTL1 = 0b11111111;    // use all 8 pins of port B for ADC

    // for motor status
    leftMotor = MOTOR_STATUS_STOP;
    rightMotor = MOTOR_STATUS_STOP;

    // now we are ready to go!
    EnableInterrupts;

    //
    // Now we set the mouse operation mode based on the status of two front
    // touch bars -- at the moment of turning it on -- as follows:
    //
    // ---------------------------------------------------------------------
    // touchBarFrontLeft | touchBarFrontRight | Operation Mode
    // ---------------------------------------------------------------------
    // not touched       | not touched        | MOUSE_MODE_DEBUG (DEFAULT)
    // not touched       | touched            | MOUSE_MODE_COMBAT
    // touched           | not touched        | MOUSE_MODE_LINE_FOLLOWING
    // touched           | touched            | MOUSE_MODE_OBSTACLE_AVOIDING
    // ---------------------------------------------------------------------
    //

    PTAPE = 0xFF;   // enable port A pullups for touchbar switches and infrared sensors
    PTADD = 0x00;   // set port A as input


    tbfl = touchBarFrontLeft;
    tbfr = touchBarFrontRight;
    
    tbfl = 1;
    tbfr = 1;
    if ((tbfl == 0) && (tbfr == 0)) {
        mouseMode = MOUSE_MODE_DEBUG;
        Test();
    }
    else if ((tbfl == 0) && (tbfr == 1)) {
        mouseMode = MOUSE_MODE_COMBAT;
        Combat();
    }
    else if ((tbrl == 1) && (tbrr == 0)) {
        mouseMode = MOUSE_MODE_LINE_FOLLOWING;
        LineFollowing();
    }
    else {
        mouseMode = MOUSE_MODE_OBSTACLE_AVOIDING;
        AvoidObstacle();
    }

    for (;;) {
        // do nothing; just waiting for interrupts
    }
}
Beispiel #6
0
/*******************************************************************************************************
* APPLY CHALLENGE - for the users chosen path, action the challenge for that direction
*******************************************************************************************************/
void ApplyChallenge(Challenge * ChallengePtr, Human & HumanObj, Enemy *Enemies[])
{
	//metal challenge variables
	bool incorrect = true;
	int count = 0;
	const int userInputLimit = 25;
	char userInput[userInputLimit] = {};
	StringOO userAnswer;
	StringOO actualAnswer;
	// points
	int points = ChallengePtr->GetDifficulty() + HumanObj.GetLocation();
	// if the challenge is of type FLEE
	if (ChallengePtr->GetType() == "flee")
	{
		std::cout << ">> To proceed in this direction we shall find out first if you can... \n";
		std::cout << ChallengePtr->GetDescription() << std::endl;
		Pause();
		if (BestOfThree())
		{
			std::cout << "+> Turns out yes, yes you can...you're free to pass! \n";
			HumanStats(HumanObj);
		}
		else
		{
			std::cout << "-> Nope, you can't as it turns out... \n   Someone had to come in and save you from yourself...\n   and further embarrassment...\n   Your fumbling has cost you health, strength, luck and intelligence." << std::endl;
			HumanObj.SetHealth(HumanObj.GetHealth() - points);
			HumanObj.SetStrength(HumanObj.GetStrength() - 2);
			HumanObj.SetLuck(HumanObj.GetLuck() - 2);
			HumanObj.SetIntelligence(HumanObj.GetIntelligence() - 1);
			HumanStats(HumanObj);
		}
		Pause();
	}
	// if the challenge is of type MENTAL
	else if (ChallengePtr->GetType() == "mental")
	{
		actualAnswer = ChallengePtr->GetAnswer();
		std::cout << ">> To proceed in this direction you must answer a question correctly... \n";
		std::cout << ChallengePtr->GetQuestion() << std::endl;
		while (incorrect)
		{
			std::cout << std::endl << "+ ";
			std::cin.getline(userInput, userInputLimit);
			userAnswer = userInput;
			if (userAnswer.StringCompare(actualAnswer) && count == 0)
			{
				std::cout << "\n+> Correct, please pass GO...Umm? but there is no $200 for you to collect... \n   At least you have your health ;-)" << std::endl;
				Pause();
				HumanStats(HumanObj);
				incorrect = false;
			}
			else if (userAnswer.StringCompare(actualAnswer) && count > 0)
			{
				std::cout << "-> Really? " << count << " guesses! Stop drinking the Coolade!, don't pass GO...! \n"; 
				points += count;
				std::cout << "   And give me " << points << " points of your best health and " << count << " of your intelligences... \n " << std::endl;
				Pause();
				HumanObj.SetHealth(HumanObj.GetHealth() - points);
				HumanObj.SetIntelligence(HumanObj.GetIntelligence() - count);
				HumanStats(HumanObj);
				incorrect = false;
			}
			else if (!userAnswer.StringCompare(actualAnswer) && count != 4)
			{
				std::cout << "\n   NOPE!! Try again...\n";
				count++;
			}
			else
			{
				std::this_thread::sleep_for(std::chrono::seconds(1));
				std::cout << "\n-> STOP!!...  <- \n             I think thats enough don't you?! \n";
				points += count;
				std::cout << "   For that you can give me...\n   - " << points << " points of your best health and...\n   - " << count << " of your intelligences... \n " << std::endl;
				Pause();
				HumanObj.SetHealth(HumanObj.GetHealth() - points);
				HumanObj.SetIntelligence(HumanObj.GetIntelligence() - count);
				HumanStats(HumanObj);
				incorrect = false;
			}
		}

	}
	// if the challenge is of type PHYSICAL
	else if (ChallengePtr->GetType() == "physical")
	{
		std::cout << ChallengePtr->GetDescription() << std::endl;
		Pause();
		Combat(HumanObj, Enemies[ChallengePtr->GetEnemy()]);
	}
	// if the challenge has no type
	else
	{
		std::cout << "   AND...\n" << std::endl;
		std::this_thread::sleep_for(std::chrono::seconds(3));
		std::cout << "           ...NOTHING HAPPENED!! \n" << std::endl;
		std::cout << "   Get out of Gaol Free or Just Visiting, either way your free to pass!! \n" << std::endl;
		Pause();
		HumanStats(HumanObj);
	}
}
int TaskForceClass::DoCombat (void)
{
    int combat;
    SetCombatTime(TheCampaign.CurrentTime);

#if 0 // JPO mthis stuff now done in Choose Target - like Battalion
    // KCK: Super simple targetting (c)
    Team				who = GetTeam();
    CampEntity			e;
    FalconEntity		*react_against=NULL,*air_react_against=NULL;
    int					react,spot,best_reaction=1,best_air_react=1;
    int					search_dist;
    float				react_distance,air_react_distance,d;
    react_distance = air_react_distance = 9999.0F;

    SetEngaged(0);
    SetCombat(0);
    SetChecked();

    search_dist = GetDetectionRange(Air);
#ifdef VU_GRID_TREE_Y_MAJOR
    VuGridIterator detit(RealUnitProxList,YPos(),XPos(),(BIG_SCALAR)GridToSim(search_dist));
#else
    VuGridIterator detit(RealUnitProxList,XPos(),YPos(),(BIG_SCALAR)GridToSim(search_dist));
#endif
    e = (CampEntity)detit.GetFirst();
    while (e)
    {
        if (GetRoE(who,e->GetTeam(),ROE_GROUND_FIRE) == ROE_ALLOWED)
        {
            combat = 0;
            react = DetectVs(e,&d,&combat,&spot);
            if (!e->IsFlight() && react >= best_reaction && d < react_distance)
            {
                // React vs a ground/Naval target
                best_reaction = react;
                react_distance = d;
                react_against = e;
                SetEngaged(1);
                SetCombat(combat);
            }
            else if (e->IsFlight() && react >= best_air_react && d < air_react_distance)
            {
                // React vs an air target -
                best_air_react = react;
                air_react_distance = d;
                air_react_against = e;
                if (!e->IsAggregate())
                {
                    // Pick a specific aircraft in the flight if it's deaggregated
                    CampEnterCriticalSection();
                    if (e->GetComponents())
                    {
                        VuListIterator	cit(e->GetComponents());
                        FalconEntity	*fe;
                        float			rsq,brsq=FLT_MAX;

                        fe = (FalconEntity *)cit.GetFirst();
                        while (fe)
                        {
                            rsq = DistSqu(XPos(),YPos(),fe->XPos(),fe->YPos());
                            if (rsq < brsq)
                            {
                                air_react_against = fe;
                                air_react_distance = (float)sqrt(rsq);
                                brsq = rsq;
                            }
                            fe = (FalconEntity *)cit.GetNext();
                        }
                    }
                    CampLeaveCriticalSection();
                }
                SetEngaged(1);
                SetCombat(combat);
            }
        }
        e = (CampEntity)detit.GetNext();
    }

    if (air_react_against)
        SetAirTarget(air_react_against);
    if (react_against)
        SetTarget(react_against);
#endif
    if (Engaged())
    {
        FalconEntity	*e = GetTarget();
        FalconEntity	*a = GetAirTarget();

        // Check vs our Ground Target
        if (!e)
            SetTarget(NULL);
        else
        {
            if (Combat() && IsAggregate())
            {
                combat = ::DoCombat(this,e);
                if (combat <= 0 || Targeted())
                    SetTargeted(0);
            }
        }
        // Check vs our Air Target
        if (!a)
            SetAirTarget(NULL);
        else if (Combat() && IsAggregate())
        {
            combat = ::DoCombat(this,a);
            if (combat < 0)
                SetAirTarget(NULL);							// Clear targeting data so we can look for another
        }
    }

    return 0;
}