Пример #1
0
void CombatCommander::onStart()
{
    m_squadData.clearSquadData();

    SquadOrder idleOrder(SquadOrderTypes::Idle, m_bot.GetStartLocation(), 5, "Chill Out");
    m_squadData.addSquad("Idle", Squad("Idle", idleOrder, IdlePriority, m_bot));

    // the main attack squad that will pressure the enemy's closest base location
    SquadOrder mainAttackOrder(SquadOrderTypes::Attack, sc2::Point2D(0.0f, 0.0f), 25, "Attack Enemy Base");
    m_squadData.addSquad("MainAttack", Squad("MainAttack", mainAttackOrder, AttackPriority, m_bot));

    // the scout defense squad will handle chasing the enemy worker scout
    SquadOrder enemyScoutDefense(SquadOrderTypes::Defend, m_bot.GetStartLocation(), 25, "Get the scout");
    m_squadData.addSquad("ScoutDefense", Squad("ScoutDefense", enemyScoutDefense, ScoutDefensePriority, m_bot));
}
Пример #2
0
/*-------------------------------------------------------------------------*/
static void KB_InterpolateSingle (double s, SquadInfo* si, Rotation3* R)
{
    /* assert:  0 <= s <= 1 */
  
    Quaternion squad;
    Squad(&squad, s, &(si->p), &(si->a), &(si->b), &(si->q)); 
    ToAngleAxis(&squad, &(R->angle),&(R->x),&(R->y),&(R->z)); 
}
Пример #3
0
void NodeCombat::sendSquad(int ressource, int nodeId)
{
    if(nodeId != getId() && mapConnexion.contains(nodeId))
    {
        int nbToSend = ressource > nbRessources ? nbRessources : ressource;
        if(nbToSend > 0)
        {
            nbRessources -= nbToSend;
            Squad s = Squad(*owner);
            s.setNbRessources(nbToSend);
            mapConnexion.value(nodeId)->sendSquad(s, getId());
        }
    }
}
Пример #4
0
void Game::setUpShips() {
	const int maxAmountInSquad = 3;
	if (wave == 1) {
		if (nextSquadTimer % timeTillNextSquad == 0 && nextSquadTimer != 0 && !doneIt && squadsCreatedWave < squadsPerWave) {
			int shipType;
			int noOfShipsInSquad = rand() % maxAmountInSquad + 1;
			squadVector.push_back(Squad());
			for (int i = 0; i < noOfShipsInSquad; i++) {
				shipType = rand() % 2;		
				makeEnemy(shipType, squadVector.size() - 1);		
			}
			timeTillNextSquad = rand() % 4 + minTimeBetweenSquad;
			doneIt = true;
			totalShipCreatedLevel = totalShipCreatedLevel + totalEnemyShipCreatedLevel + totalInsectCreatedLevel;
			//totalShipCreatedWave = ;	
			squadsCreatedLevel++;
			squadsCreatedWave++;
		}
		else if (nextSquadTimer % timeTillNextSquad != 0 && doneIt) doneIt = false;
		if (squadsDefeatedWave >= squadsPerWave) {
			wave++;
			totalShipCreatedWave = 0; //not needed but f**k it for now
			squadsCreatedWave = 0;
			squadsDefeatedWave = 0;
		}
	}
	
	if (wave == 2) {

	}

	/*if (nextSquadTimer % 2 == 0 && !doneIt) {
		int a = rand() % 2;
		makeEnemy(a, 0);
		doneIt = true;
	}
	else doneIt = false;*/	
}
Пример #5
0
//
//#############################################################################
//#############################################################################
//
UnitQuaternion
	UnitQuaternion::SquadRev(
		Scalar angle,			// angle of rotation 
		const Point3D& axis,	// the axis of rotation 
		const UnitQuaternion& p,	// start quaternion 
		const UnitQuaternion& a, 	// start tangent quaternion 
		const UnitQuaternion& b, 	// end tangent quaternion 
		const UnitQuaternion& q,	// end quaternion 
		Scalar t 				// parameter, in range [0.0,1.0] 
	)
{
	Scalar s,v;
	Scalar omega = angle*0.5f;
	Scalar nrevs = 0.0f;
	UnitQuaternion r,pp,qq;


	if (omega<Pi-0.0001f) 
	{ 
		r = Squad(p,a,b,q,t); 

		return(r); 
	}

	while (omega > (Pi-0.0001f)) 
	{  
		omega -= Pi; nrevs += (float)1.0; 
	}

	if (omega<0.0f) 
	{
		omega = (float)0.0;
	}

	s = t*angle/Pi;		  /* 2t(omega+Npi)/pi */
	
	if (s < (float)1.0) 
	{
		pp.Orthog(p,axis);
		r = Squad(p,a,pp,pp,s); 	/* in first 90 degrees */
	}
	else 
	{
		if ( ( v = s + 1.0f - 2.0f*(nrevs+(omega/Pi)) ) <=  0.0f)  
		{
			/* middle part, on great circle(p,q) */
			while (s >= 2.0f) 
			{
				s -= 2.0f;
			}
			pp.Orthog(p,axis);
			r = Lerp(p,pp,s);
		}
		else 
		{ 	  /* in last 90 degrees */ 
			qq.Orthog(q,axis);
			qq.Negate();
			r= Squad(qq,qq,b,q,v);
		}
	}

	return(r);
}
Пример #6
0
void CombatCommander::updateDefenseSquads()
{
    if (m_combatUnits.empty())
    {
        return;
    }

    // for each of our occupied regions
    const BaseLocation * enemyBaseLocation = m_bot.Bases().getPlayerStartingBaseLocation(Players::Enemy);
    for (const BaseLocation * myBaseLocation : m_bot.Bases().getOccupiedBaseLocations(Players::Self))
    {
        // don't defend inside the enemy region, this will end badly when we are stealing gas or cannon rushing
        if (myBaseLocation == enemyBaseLocation)
        {
            continue;
        }

        sc2::Point2D basePosition = myBaseLocation->getPosition();

        // start off assuming all enemy units in region are just workers
        int numDefendersPerEnemyUnit = 2;

        // all of the enemy units in this region
        std::vector<UnitTag> enemyUnitsInRegion;
        for (auto & unit : m_bot.UnitInfo().getUnits(Players::Enemy))
        {
            // if it's an overlord, don't worry about it for defense, we don't care what they see
            if (unit.unit_type == sc2::UNIT_TYPEID::ZERG_OVERLORD)
            {
                continue;
            }

            if (myBaseLocation->containsPosition(unit.pos))
            {
                enemyUnitsInRegion.push_back(unit.tag);
            }
        }

        // we can ignore the first enemy worker in our region since we assume it is a scout
        for (auto & unitTag : enemyUnitsInRegion)
        {
            auto unit = m_bot.GetUnit(unitTag);
            BOT_ASSERT(unit, "null enemyt unit in region");

            if (Util::IsWorker(*unit))
            {
                enemyUnitsInRegion.erase(std::remove(enemyUnitsInRegion.begin(), enemyUnitsInRegion.end(), unitTag), enemyUnitsInRegion.end());
                break;
            }
        }

        // calculate how many units are flying / ground units
        int numEnemyFlyingInRegion = 0;
        int numEnemyGroundInRegion = 0;
        for (auto & unitTag : enemyUnitsInRegion)
        {
            auto unit = m_bot.GetUnit(unitTag);
            BOT_ASSERT(unit, "null enemyt unit in region");

            if (unit->is_flying)
            {
                numEnemyFlyingInRegion++;
            }
            else
            {
                numEnemyGroundInRegion++;
            }
        }


        std::stringstream squadName;
        squadName << "Base Defense " << basePosition.x << " " << basePosition.y;

        // if there's nothing in this region to worry about
        if (enemyUnitsInRegion.empty())
        {
            // if a defense squad for this region exists, remove it
            if (m_squadData.squadExists(squadName.str()))
            {
                m_squadData.getSquad(squadName.str()).clear();
            }

            // and return, nothing to defend here
            continue;
        }
        else
        {
            // if we don't have a squad assigned to this region already, create one
            if (!m_squadData.squadExists(squadName.str()))
            {
                SquadOrder defendRegion(SquadOrderTypes::Defend, basePosition, 32 * 25, "Defend Region!");
                m_squadData.addSquad(squadName.str(), Squad(squadName.str(), defendRegion, BaseDefensePriority, m_bot));
            }
        }

        // assign units to the squad
        if (m_squadData.squadExists(squadName.str()))
        {
            Squad & defenseSquad = m_squadData.getSquad(squadName.str());

            // figure out how many units we need on defense
            int flyingDefendersNeeded = numDefendersPerEnemyUnit * numEnemyFlyingInRegion;
            int groundDefensersNeeded = numDefendersPerEnemyUnit * numEnemyGroundInRegion;

            updateDefenseSquadUnits(defenseSquad, flyingDefendersNeeded, groundDefensersNeeded);
        }
        else
        {
            BOT_ASSERT(false, "Squad should have existed: %s", squadName.str().c_str());
        }
    }

    // for each of our defense squads, if there aren't any enemy units near the position, remove the squad
    std::set<std::string> uselessDefenseSquads;
    for (const auto & kv : m_squadData.getSquads())
    {
        const Squad & squad = kv.second;
        const SquadOrder & order = squad.getSquadOrder();

        if (order.getType() != SquadOrderTypes::Defend)
        {
            continue;
        }

        bool enemyUnitInRange = false;
        for (auto & unit : m_bot.UnitInfo().getUnits(Players::Enemy))
        {
            if (Util::Dist(unit.pos, order.getPosition()) < order.getRadius())
            {
                enemyUnitInRange = true;
                break;
            }
        }

        if (!enemyUnitInRange)
        {
            m_squadData.getSquad(squad.getName()).clear();
        }
    }
}
Пример #7
0
void Battle::initSquads(Formation leftFormation, Formation rightFormation)
{
	char buff[100];
	int indexCount = 0;
    
    for(int row = 0; row< 4 ; row ++)
    {
        for(int col = 0; col < 5; col ++)
        {
            // Create left side squads
            if(leftFormation[row][col] != SquadType::None)
            {
                sprintf(buff,"%d(TeamA)",indexCount);
                std::string name = buff;
                
                Point p(_battleFieldSize.width/2 - 12 - _squadSize.width * col,
                        _battleFieldSize.height  - _squadSize.height/2 - _squadSize.height * row);
                
                Squad a = Squad(name,p,indexCount);
                
                if(leftFormation[row][col] == SquadType::Footman)
                {
                    a.setSoldierRes(Resources::getInstance()->getFootmanResourceA());
                    initSquadProperty(&a, SquadType::Footman);
                }
                
                if(leftFormation[row][col] == SquadType::Knight)
                {
                    a.setSoldierRes(Resources::getInstance()->getKnightResourceA());
                    initSquadProperty(&a, SquadType::Knight);
                }
                
                if(leftFormation[row][col] == SquadType::Archer)
                {
                    a.setSoldierRes(Resources::getInstance()->getArcherResourceA());
                    initSquadProperty(&a, SquadType::Archer);
                }
                
                indexCount ++;
                a.setSquadSide(SquadSide::TeamA);
                a.setTargetSquadIndex(NONETARGET);
                initSquadSprite(&a);
                _allSquads.push_back(a);
                
            }
            
            // Create right side suqads
            if(rightFormation[row][col] != SquadType::None)
            {
                sprintf(buff,"%d(TeamB)",indexCount);
                std::string name = buff;
                
                Point p(_battleFieldSize.width/2 + 12 + _squadSize.width * col,
                        _battleFieldSize.height  - _squadSize.height/2 - _squadSize.height * row);
                
                Squad b = Squad(name,p,indexCount);
                
                if(rightFormation[row][col] == SquadType::Footman)
                {
                    b.setSoldierRes(Resources::getInstance()->getFootmanResourceB());
                    initSquadProperty(&b,Footman);
                }
                if(rightFormation[row][col] == SquadType::Knight)
                {
                    b.setSoldierRes(Resources::getInstance()->getKnightResourceB());
                    initSquadProperty(&b,Knight);
                }
                if(rightFormation[row][col] == SquadType::Archer)
                {
                    b.setSoldierRes(Resources::getInstance()->getArcherResourceB());
                    initSquadProperty(&b,Archer);
                }
                
                indexCount ++;
                b.setSquadSide(SquadSide::TeamB);
                b.setTargetSquadIndex(NONETARGET);
                initSquadSprite(&b);
                _allSquads.push_back(b);
            }
        }
    }
}