Ejemplo n.º 1
0
/**
**  PickUpItem
**
**  @return  true if the unit picks up an item, false otherwise
*/
static bool PickUpItem(CUnit &unit)
{
	if (
		!unit.Type->BoolFlag[ORGANIC_INDEX].value
		|| !unit.Player->AiEnabled
	) {
		return false;
	}
	
	if (unit.Variable[HP_INDEX].Value == unit.GetModifiedVariable(HP_INDEX, VariableMax) && !unit.HasInventory()) { //only look for items to pick up if the unit is damaged or has an inventory
		return false;
	}

	// look for nearby items to pick up
	std::vector<CUnit *> table;
	SelectAroundUnit(unit, unit.GetReactionRange(), table);

	for (size_t i = 0; i != table.size(); ++i) {
		if (!table[i]->Removed) {
			if (CanPickUp(unit, *table[i])) {
				if (table[i]->Variable[HITPOINTHEALING_INDEX].Value > 0 && (unit.GetModifiedVariable(HP_INDEX, VariableMax) - unit.Variable[HP_INDEX].Value) > 0) {
					if (UnitReachable(unit, *table[i], 1, unit.GetReactionRange() * 8)) {
						CommandPickUp(unit, *table[i], FlushCommands);
						return true;
					}
				}
			}
		}
	}
	return false;
}
Ejemplo n.º 2
0
/**
**  Draw life bar of a unit using selected variable.
**  Placed under icons on top-panel.
**
**  @param unit         Pointer to unit.
**  @param defaultfont  FIXME: docu
**
**  @todo Color and percent value Parametrisation.
*/
/* virtual */ void CContentTypeCompleteBar::Draw(const CUnit &unit, CFont *) const
{
	Assert((unsigned int) this->varIndex < UnitTypeVar.GetNumberVariable());
	//Wyrmgus start
//	if (!unit.Variable[this->varIndex].Max) {
	if (!unit.GetModifiedVariable(this->varIndex, VariableMax)) {
	//Wyrmgus end
		return;
	}
	int x = this->Pos.x;
	int y = this->Pos.y;
	int w = this->width;
	int h = this->height;
	Assert(w > 0);
	Assert(h > 4);
	const Uint32 colors[] = {ColorRed, ColorYellow, ColorGreen, ColorLightGray,
							 ColorGray, ColorDarkGray, ColorWhite, ColorOrange,
							 ColorLightBlue, ColorBlue, ColorDarkGreen, ColorBlack
							};
	const Uint32 color = (colorIndex != -1) ? colors[colorIndex] : UI.CompletedBarColor;
	//Wyrmgus start
//	const int f = (100 * unit.Variable[this->varIndex].Value) / unit.Variable[this->varIndex].Max;
	const int f = (100 * unit.GetModifiedVariable(this->varIndex, VariableValue)) / unit.GetModifiedVariable(this->varIndex, VariableMax);
	//Wyrmgus end

	if (!this->hasBorder) {
		//Wyrmgus start
		if (Preference.ProgressBarG) {
			Preference.ProgressBarG->DrawClip(this->Pos.x - 4, this->Pos.y - 5);
		}
		//Wyrmgus end
		Video.FillRectangleClip(color, x, y, f * w / 100, h);
		if (UI.CompletedBarShadow) {
			// Shadow
			Video.DrawVLine(ColorGray, x + f * w / 100, y, h);
			Video.DrawHLine(ColorGray, x, y + h, f * w / 100);

			// |~  Light
			Video.DrawVLine(ColorWhite, x, y, h);
			Video.DrawHLine(ColorWhite, x, y, f * w / 100);
		}
	} else {
		Video.DrawRectangleClip(ColorWhite,  x,     y,     w + 4, h);
		Video.DrawRectangleClip(ColorBlack, x + 1, y + 1, w + 2, h - 2);
		Video.FillRectangleClip(color, x + 2, y + 2, f * w / 100, h - 4);
	}
}
Ejemplo n.º 3
0
bool COrder_Still::AutoAttackStand(CUnit &unit)
{
	//Wyrmgus start
//	if (unit.Type->CanAttack == false) {
	if (unit.CanAttack() == false) {
	//Wyrmgus end
		return false;
	}
	// Removed units can only attack in AttackRange, from bunker
	//Wyrmgus start
	//if unit is in a container which is attacking, and the container has a goal, use that goal (if possible) instead
//	CUnit *autoAttackUnit = AttackUnitsInRange(unit);
	CUnit *autoAttackUnit = unit.Container && unit.Container->CurrentAction() == UnitActionAttack && unit.Container->CurrentOrder()->HasGoal() ? unit.Container->CurrentOrder()->GetGoal() : AttackUnitsInRange(unit);
	//Wyrmgus end

	if (autoAttackUnit == nullptr) {
		return false;
	}
	// If unit is removed, use container's x and y
	const CUnit *firstContainer = unit.GetFirstContainer();
	if (firstContainer->MapDistanceTo(*autoAttackUnit) > unit.GetModifiedVariable(ATTACKRANGE_INDEX)) {
		return false;
	}
	//Wyrmgus start
//	if (GameSettings.Inside && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldRocks | MapFieldForest) == false) {
	if (Map.IsLayerUnderground(autoAttackUnit->MapLayer->ID) && unit.GetModifiedVariable(ATTACKRANGE_INDEX) > 1 && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldAirUnpassable, autoAttackUnit->MapLayer->ID) == false) {
	//Wyrmgus end
		return false;
	}
	this->State = SUB_STILL_ATTACK; // Mark attacking.
	this->SetGoal(autoAttackUnit);
	//Wyrmgus start
//	UnitHeadingFromDeltaXY(unit, autoAttackUnit->tilePos + autoAttackUnit->Type->GetHalfTileSize() - unit.tilePos);
	UnitHeadingFromDeltaXY(unit, PixelSize(PixelSize(autoAttackUnit->tilePos) * Map.GetMapLayerPixelTileSize(autoAttackUnit->MapLayer->ID)) + autoAttackUnit->GetHalfTilePixelSize() - PixelSize(PixelSize(unit.tilePos) * Map.GetMapLayerPixelTileSize(autoAttackUnit->MapLayer->ID)) - unit.GetHalfTilePixelSize());
	//Wyrmgus end
	return true;
}
Ejemplo n.º 4
0
/**
**  Draw life bar of a unit using selected variable.
**  Placed under icons on top-panel.
**
**  @param unit         Pointer to unit.
**  @param defaultfont  FIXME: docu
**
**  @todo Color and percent value Parametrisation.
*/
/* virtual */ void CContentTypeLifeBar::Draw(const CUnit &unit, CFont *) const
{
	Assert((unsigned int) this->Index < UnitTypeVar.GetNumberVariable());
	//Wyrmgus start
	int max = 0;
	if (this->Index == XP_INDEX) {
		max = unit.Variable[XPREQUIRED_INDEX].Value;
	} else {
		max = unit.GetModifiedVariable(this->Index, VariableMax);
	}
//	if (!unit.Variable[this->Index].Max) {
	if (!max) {
	//Wyrmgus end
		return;
	}

	Uint32 color;
	//Wyrmgus start
	Uint32 lighter_color;
//	int f = (100 * unit.Variable[this->Index].Value) / unit.Variable[this->Index].Max;
	int f = (100 * unit.Variable[this->Index].Value) / max;
	//Wyrmgus end

	//Wyrmgus start
	/*
	if (f > 75) {
		color = ColorDarkGreen;
		//Wyrmgus start
		lighter_color = Video.MapRGB(TheScreen->format, 67, 137, 8);
		//Wyrmgus end
	} else if (f > 50) {
		color = ColorYellow;
		//Wyrmgus start
		lighter_color = Video.MapRGB(TheScreen->format, 255, 255, 210);
		//Wyrmgus end
	} else if (f > 25) {
		color = ColorOrange;
		//Wyrmgus start
		lighter_color = Video.MapRGB(TheScreen->format, 255, 180, 90);
		//Wyrmgus end
	} else {
		color = ColorRed;
		//Wyrmgus start
		lighter_color = Video.MapRGB(TheScreen->format, 255, 100, 100);
		//Wyrmgus end
	}
	*/

	if (this->Index == HP_INDEX) {
		if (f > 75) {
			color = ColorDarkGreen;
			//Wyrmgus start
			lighter_color = Video.MapRGB(TheScreen->format, 67, 137, 8);
			//Wyrmgus end
		} else if (f > 50) {
			color = ColorYellow;
			//Wyrmgus start
			lighter_color = Video.MapRGB(TheScreen->format, 255, 255, 210);
			//Wyrmgus end
		} else if (f > 25) {
			color = ColorOrange;
			//Wyrmgus start
			lighter_color = Video.MapRGB(TheScreen->format, 255, 180, 90);
			//Wyrmgus end
		} else {
			color = ColorRed;
			//Wyrmgus start
			lighter_color = Video.MapRGB(TheScreen->format, 255, 100, 100);
			//Wyrmgus end
		}
	} else if (this->Index == MANA_INDEX) {
		color = Video.MapRGB(TheScreen->format, 4, 70, 100);
		lighter_color = Video.MapRGB(TheScreen->format, 8, 97, 137);
	} else if (this->Index == XP_INDEX) {
		color = Video.MapRGB(TheScreen->format, 97, 103, 0);
		lighter_color = Video.MapRGB(TheScreen->format, 132, 141, 3);
	} else {
		color = ColorDarkGreen;
		lighter_color = Video.MapRGB(TheScreen->format, 67, 137, 8);
	}
	//Wyrmgus end

	// Border
	//Wyrmgus start
//	Video.FillRectangleClip(ColorBlack, this->Pos.x - 2, this->Pos.y - 2,
//							this->Width + 3, this->Height + 3);
	if (Preference.BarFrameG) {
		Preference.BarFrameG->DrawClip(this->Pos.x - 1 - 4, this->Pos.y - 1 - 4);
		Video.FillRectangleClip(ColorBlack, this->Pos.x - 1, this->Pos.y - 1,
								this->Width, this->Height);
	} else {
		Video.FillRectangleClip(ColorBlack, this->Pos.x - 3, this->Pos.y - 3,
								this->Width + 4, this->Height + 4);
	}
	//Wyrmgus end

	Video.FillRectangleClip(color, this->Pos.x - 1, this->Pos.y - 1,
							(f * this->Width) / 100, this->Height);
	//Wyrmgus start
	Video.FillRectangleClip(lighter_color, this->Pos.x - 1, this->Pos.y - 1,
							(f * this->Width) / 100, 1);
	//Wyrmgus end
}