Example #1
0
bool HLUnitData::finishUnit(BWAPI::UnitType type)
{
	bool found = false;
	for (auto &item : _unitMap){
		if (item.second.type.getID() == type.getID() && !item.second.completed){
			item.second.completed = true;
			numCompletedUnits[type.getID()]++;
			found = true;
			break;
		}
	}

	UAB_ASSERT(found,"Couldn't find unit to finish: %s\n",type.getName().c_str());
	return found;
}
//----------------------------------------------------------------------------------------------
EntityClassType StarCraftTechTree::SourceEntity(int p_typeOrResearchId) const
{
    TName ident;
    TID id;
    UpgradeType upgrade;
    TechType tech;
    BWAPI::UnitType unitType;
    BWAPI::UnitType sourceType;

    if (BELONG(ResearchType, p_typeOrResearchId))
    {
        // Is Tech
        if ((int)p_typeOrResearchId >= ((int)(RESEARCH_START +  TechIdOffset)))
        {
            id = g_Database.TechMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.TechIdentMapping.GetByFirst(id);
            tech = TechType::getType(ident);
            sourceType = tech.whatResearches();

            return g_Database.EntityMapping.GetByFirst(sourceType.getID());
        }
        // Is Upgrade
        else
        {
            id = g_Database.UpgradeMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.UpgradeIdentMapping.GetByFirst(id);
            upgrade = UpgradeType::getType(ident);
            sourceType = upgrade.whatUpgrades();

            return g_Database.EntityMapping.GetByFirst(sourceType.getID());
        }
    }
    else if(BELONG(EntityClassType, p_typeOrResearchId))
    {
        id = g_Database.EntityMapping.GetBySecond((EntityClassType)p_typeOrResearchId);
        ident = g_Database.EntityIdentMapping.GetByFirst(id);
        unitType = UnitType::getType(ident);
        sourceType = unitType.whatBuilds().first;

        return g_Database.EntityMapping.GetByFirst(sourceType.getID());
    }

    return ECLASS_END;
}
//----------------------------------------------------------------------------------------------
EntityClassType StarCraftTechTree::TireBaseBuilding(BaseType p_tireId) const
{
    BWAPI::UnitType baseType;
    
    if (p_tireId == BASETYPE_END)
        return ECLASS_END;

    baseType = m_player->getRace().getCenter();

    return g_Database.EntityMapping.GetByFirst(baseType.getID());
}
Example #4
0
ActionID ActionTypeData::GetActionID(const BWAPI::UnitType & type) 
{
    const RaceID raceID = GetRaceID(type.getRace());
    BOSS_ASSERT(raceID < Races::NUM_RACES, "Race ID invalid: %d %s", (int)raceID, type.getName().c_str());


    for (ActionID a(0); a < ActionTypeData::GetNumActionTypes(raceID); ++a)
    {
        const ActionTypeData & data = GetActionTypeData(raceID, a);
        if (data.isUnit() && data.getUnitType() == type)
        {
            return data.getActionID();
        }
    }
   
	BOSS_ASSERT(false, "Could not find UnitType: %d %s", type.getID(), type.getName().c_str());
    return 0;
}
void Display::RenderUnit(const Unit & unit)
{
	
	static const float3 factionColors[12] = 
	{
		float3(1,0,0),		float3(0,1,0),			float3(0,1,0.5f),	float3(0.5f,0,1),
		float3(1,0.5f,0),	float3(0.5f,0.25f,0),	float3(1,1,1),		float3(1,1,0),
		float3(0,0,0),		float3(0,0,0),			float3(0,0,0),		float3(0,1,1)
	};
	
	glColor4f(1, 1, 1, 1);
	const int healthBoxHeight = 4;

	const Position			pos(unit.currentPosition(state.getTime()));
	const BWAPI::UnitType	type(unit.type());
	const int				tx(textureSizes[type.getID()].x()/2);
	const int				ty(textureSizes[type.getID()].y()/2);
				
	// unit box will be a square due to having square textures
	const int				x0(pos.x() - type.dimensionUp());
	const int				x1(pos.x() + type.dimensionDown());
	const int				y0(pos.y() - type.dimensionUp());
	const int				y1(pos.y() + type.dimensionDown());

	const int				tx0(pos.x() - tx);
	const int				tx1(pos.x() + tx);
	const int				ty0(pos.y() - ty);
	const int				ty1(pos.y() + ty);

	// if the unit can move right now draw its move
	if (unit.previousActionTime() == state.getTime())
	{
		const UnitAction & move = unit.previousAction();

		if (move.type() == UnitActionTypes::MOVE)
		{
			glColor4f(1, 1, 1, 0.75);
			glBegin(GL_LINES);
				glVertex2i(pos.x(), pos.y());
				glVertex2i(unit.pos().x(), unit.pos().y());
			glEnd( );
		}
		else if (move.type() == UnitActionTypes::ATTACK)
		{
			const Unit &	target(state.getUnit(state.getEnemy(unit.player()), move.index()));
			const Position	targetPos(target.currentPosition(state.getTime()));

			glColor4f(factionColors[unit.player()].x, factionColors[unit.player()].y, factionColors[unit.player()].z, 0.75);
			glBegin(GL_LINES);
				glVertex2i(pos.x(), pos.y());
				glVertex2i(targetPos.x(), targetPos.y());
			glEnd( );

			/*glColor4f(1.0, 0.0, 0.0, 0.25);
			glBegin(GL_QUADS);
				glVertex2i(targetPos.x()-type.dimensionUp(),targetPos.y()-type.dimensionUp());
				glVertex2i(targetPos.x()-type.dimensionUp(),targetPos.y()+type.dimensionUp());
				glVertex2i(targetPos.x()+type.dimensionUp(),targetPos.y()+type.dimensionUp());
				glVertex2i(targetPos.x()+type.dimensionUp(),targetPos.y()-type.dimensionUp());
			glEnd();*/
		}
		else if (move.type() == UnitActionTypes::HEAL)
		{
			const Unit &	target(state.getUnit(unit.player(), move.index()));
			const Position	targetPos(target.currentPosition(state.getTime()));

			glColor4f(factionColors[unit.player()].x, factionColors[unit.player()].y, factionColors[unit.player()].z, 0.75);
			glBegin(GL_LINES);
				glVertex2i(pos.x(), pos.y());
				glVertex2i(targetPos.x(), targetPos.y());
			glEnd( );

			/*glColor4f(0.0, 1.0, 0.0, 0.25);
			glBegin(GL_QUADS);
				glVertex2i(targetPos.x()-type.dimensionUp(),targetPos.y()-type.dimensionUp());
				glVertex2i(targetPos.x()-type.dimensionUp(),targetPos.y()+type.dimensionUp());
				glVertex2i(targetPos.x()+type.dimensionUp(),targetPos.y()+type.dimensionUp());
				glVertex2i(targetPos.x()+type.dimensionUp(),targetPos.y()-type.dimensionUp());
			glEnd();*/
		}
	}
			
	// draw the unit's texture
	glEnable( GL_TEXTURE_2D );
		glColor4f(1, 1, 1, 0.75);
		glBindTexture( GL_TEXTURE_2D, unit.type().getID() );
		glBegin( GL_QUADS );
			glTexCoord3d(0.0,0.0,.5); glVertex2i(tx0,ty0);
			glTexCoord3d(1.0,0.0,.5); glVertex2i(tx1,ty0);
			glTexCoord3d(1.0,1.0,.5); glVertex2i(tx1,ty1);
			glTexCoord3d(0.0,1.0,.5); glVertex2i(tx0,ty1);
		glEnd();
	glDisable( GL_TEXTURE_2D );

	if (unit.player() == Players::Player_None)
	{
		return;
	}

	// draw the unit HP box
	double	percHP = (double)unit.currentHP() / (double)unit.maxHP();
	int		cw = (int)((x1-x0) * percHP);
	int		xx = pos.x() - (x1-x0)/2;
	int		yy = pos.y() - healthBoxHeight - (y1-y0)/2 - 5;

	glColor4f(factionColors[unit.player()].x, factionColors[unit.player()].y, factionColors[unit.player()].z, 0.75);
	glBegin(GL_QUADS);
		glVertex2i(xx,yy);
		glVertex2i(xx+cw,yy);
		glVertex2i(xx+cw,yy+healthBoxHeight);
		glVertex2i(xx,yy+healthBoxHeight);
	glEnd();

	// draw the unit energy box
	if (unit.currentEnergy() > 0)
	{
		double	percEnergy = (double)unit.currentEnergy() / (double)Constants::Starting_Energy;
		cw = (int)((x1-x0) * percEnergy);
		xx = pos.x() - (x1-x0)/2;
		yy = pos.y() - healthBoxHeight*2 - (y1-y0)/2 - 5;

		glColor4f(0.0, 1.0, 0.0, 0.75);
		glBegin(GL_QUADS);
			glVertex2i(xx,yy);
			glVertex2i(xx+cw,yy);
			glVertex2i(xx+cw,yy+healthBoxHeight);
			glVertex2i(xx,yy+healthBoxHeight);
		glEnd();
	}

	// draw attack radius
	glColor4f(0.2f, 0.2f, 0.2f, 0.25);
	int radius = unit.canHeal() ? unit.healRange() : unit.range();
	//DrawCircle((float)pos.x(), (float)pos.y(), (float)radius, 60);
}
//----------------------------------------------------------------------------------------------
void StarCraftTechTree::GetRequirements(int p_typeOrResearchId, vector<ResearchType>& p_researches, map<EntityClassType, unsigned>& p_buildings)
{
    TName ident;
    TID id;
    UpgradeType bwapiUpgrade;
    TechType bwapiTech;
    BWAPI::UnitType bwapiUnitType;
    BWAPI::UnitType bwapiSourceType;
    BWAPI::UnitType bwapiRequiredType;
    BWAPI::UnitType bwapiRequiredUnit;
    TechType bwapiRequiredTech;
    EntityClassType requiredEntity;
    ResearchType requiredResearch;
    
    if (BELONG(ResearchType, p_typeOrResearchId))
    {
        // Is Tech
        if ((int)p_typeOrResearchId >= ((int)(RESEARCH_START +  TechIdOffset)))
        {
            /*id = g_Database.TechMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.TechIdentMapping.GetByFirst(id);
            bwapiTech = TechType::getType(ident);

            bwapiSourceType = bwapiTech.whatResearches();
            requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiSourceType.getID());
            p_buildings.push_back(requiredEntity);*/
        }
        // Is Upgrade
        else
        {
            id = g_Database.UpgradeMapping.GetBySecond((ResearchType)p_typeOrResearchId);
            ident = g_Database.UpgradeIdentMapping.GetByFirst(id);
            bwapiUpgrade = UpgradeType::getType(ident);

            /*bwapiSourceType = bwapiUpgrade.whatUpgrades();
            requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiSourceType.getID());
            p_buildings.push_back(requiredEntity);*/

            bwapiRequiredType = bwapiUpgrade.whatsRequired();

            if (bwapiRequiredType.getID() != UnitTypes::None.getID())
            {
                requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiRequiredType.getID());
                p_buildings[requiredEntity] = 1;
            }
        }
    }
    else if(BELONG(EntityClassType, p_typeOrResearchId))
    {
        id = g_Database.EntityMapping.GetBySecond((EntityClassType)p_typeOrResearchId);
        ident = g_Database.EntityIdentMapping.GetByFirst(id);
        bwapiUnitType = UnitType::getType(ident);

        /*bwapiSourceType = bwapiUnitType.whatBuilds().first;
        requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiSourceType.getID());
        p_buildings.push_back(requiredEntity);*/

        bwapiRequiredTech = bwapiUnitType.requiredTech();

        if (bwapiRequiredTech.getID() != TechTypes::None.getID())
        {
            requiredResearch = g_Database.TechMapping.GetByFirst(bwapiRequiredTech.getID());
            p_researches.push_back(requiredResearch);
        }

        const map<BWAPI::UnitType, int> &bwapiUnits = bwapiUnitType.requiredUnits();

        for (map<BWAPI::UnitType, int>::const_iterator itr =  bwapiUnits.begin();
            itr != bwapiUnits.end(); ++itr)
        {
            bwapiRequiredUnit = itr->first;
            requiredEntity = g_Database.EntityMapping.GetByFirst(bwapiRequiredUnit.getID());
            p_buildings[requiredEntity] = itr->second;;
        }
    }
}
Example #7
0
int		HLUnitData::getNumDeadUnits(BWAPI::UnitType t)					const
{
	return numDeadUnits[t.getID()];
}