void UnitCommandManager::drawCommandStatus(BWAPI::UnitInterface* unit)
{
	BWAPI::UnitType type = unit->getType();
	int width = type.dimensionRight();
	int height = type.dimensionDown()/6;

	int x1 = unit->getPosition().x - width;
	int x2 = unit->getPosition().y + width;
	int y1 = unit->getPosition().y - height;
	int y2 = unit->getPosition().y + height;
}
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);
}
示例#3
0
文件: Unit.cpp 项目: eras44/sparcraft
// constructor for units to construct basic units, sets some things automatically
Unit::Unit(const BWAPI::UnitType unitType, const IDType & playerID, const Position & pos) 
    : _unitType             (unitType)
    , _range                (PlayerWeapon(&PlayerProperties::Get(playerID), unitType.groundWeapon()).GetMaxRange() + unitType.dimensionDown() + 5/* + Constants::Range_Addition*/)
    //, _range                (unitType.groundWeapon().maxRange() + Constants::Range_Addition)
    , _position             (pos)
    , _unitID               (0)
    , _playerID             (playerID)
    , _currentHP            (maxHP())
	, _currentshield        (maxshield())
    , _currentEnergy        ((unitType == BWAPI::UnitTypes::Terran_Medic) ||(unitType == BWAPI::UnitTypes::Protoss_High_Templar) ? Constants::Starting_Energy : 0)
    , _timeCanMove          (0)
    , _timeCanAttack        (0)
	, _timeCanCast			(0)
    , _previousActionTime   (0)
    , _previousPosition     (pos)
    , _prevCurrentPosTime   (0)
    , _prevCurrentPos       (pos)
	, _isloaded				(false)
{
    System::checkSupportedUnitType(unitType);
}
示例#4
0
文件: Unit.cpp 项目: eras44/sparcraft
// test constructor for setting all variables of a unit
Unit::Unit(const BWAPI::UnitType unitType, const Position & pos, const IDType & unitID, const IDType & playerID, 
           const HealthType & hp,const HealthType & shield, const HealthType & energy, const TimeType & tm, const TimeType & ta,const TimeType &tc)
    : _unitType             (unitType)
    , _range                (PlayerWeapon(&PlayerProperties::Get(playerID), unitType.groundWeapon()).GetMaxRange() + unitType.dimensionDown() + 5/* + Constants::Range_Addition*/)
    //, _range                (unitType.groundWeapon().maxRange() + Constants::Range_Addition)
    , _position             (pos)
    , _unitID               (unitID)
    , _playerID             (playerID)
	, _currentHP            (hp)
	, _currentshield        (shield)
    , _currentEnergy        (energy)
    , _timeCanMove          (tm)
    , _timeCanAttack        (ta)
	, _timeCanCast 			(tc)
    , _previousActionTime   (0)
    , _prevCurrentPosTime   (0)
	, _isloaded				(false)
{
    System::checkSupportedUnitType(unitType);
}