/** ** Show the current order of an unit. ** ** @param unit Pointer to the unit. */ void ShowOrder(const CUnit *unit) { int x1; int y1; COrder *order; if (unit->Destroyed) { return; } // Get current position x1 = CurrentViewport->Map2ViewportX( unit->X) + unit->IX + unit->Type->TileWidth * TileSizeX / 2; y1 = CurrentViewport->Map2ViewportY( unit->Y) + unit->IY + unit->Type->TileHeight * TileSizeY / 2; // If the current order is cancelled show the next one if (unit->OrderCount > 1 && unit->OrderFlush) { order = unit->Orders[1]; } else { order = unit->Orders[0]; } ShowSingleOrder(unit, x1, y1, order); // Show the rest of the orders for (int i = 1 + (unit->OrderFlush ? 1 : 0); i < unit->OrderCount; ++i) { GetOrderPosition(unit, unit->Orders[i - 1], &x1, &y1); ShowSingleOrder(unit, x1, y1, unit->Orders[i]); } // Show order for new trained units if (!CanMove(unit)) { ShowSingleOrder(unit, x1, y1, &unit->NewOrder); } }
/** ** Show the current order of a unit. ** ** @param unit Pointer to the unit. */ void ShowOrder(const CUnit &unit) { int x1; int y1; COrderPtr order; if (unit.Destroyed) { return; } if (unit.Player != ThisPlayer && !ThisPlayer->IsAllied(unit)) { return; } // Get current position x1 = CurrentViewport->Map2ViewportX( unit.tilePos.x) + unit.IX + unit.Type->TileWidth * TileSizeX / 2; y1 = CurrentViewport->Map2ViewportY( unit.tilePos.y) + unit.IY + unit.Type->TileHeight * TileSizeY / 2; // If the current order is cancelled show the next one if (unit.OrderCount > 1 && unit.OrderFlush) { order = unit.Orders[1]; } else { order = unit.Orders[0]; } ShowSingleOrder(unit, x1, y1, order); // Show the rest of the orders for (int i = 1 + (unit.OrderFlush ? 1 : 0); i < unit.OrderCount; ++i) { GetOrderPosition(unit, unit.Orders[i - 1], &x1, &y1); ShowSingleOrder(unit, x1, y1, unit.Orders[i]); } // Show order for new trained units if (!unit.CanMove()) { ShowSingleOrder(unit, x1, y1, (COrderPtr)(&unit.NewOrder)); } }
/** ** Show the order on map. ** ** @param unit Unit pointer. ** @param x1 X pixel coordinate. ** @param y1 Y pixel coordinate. ** @param order Order to display. */ static void ShowSingleOrder(const CUnit &unit, int x1, int y1, const COrderPtr order) { int x2; int y2; Uint32 color; Uint32 e_color; bool dest; GetOrderPosition(unit, order, &x2, &y2); dest = false; switch (order->Action) { case UnitActionNone: e_color = color = ColorGray; break; case UnitActionStill: e_color = color = ColorGray; break; case UnitActionStandGround: e_color = color = ColorGreen; break; case UnitActionFollow: case UnitActionMove: e_color = color = ColorGreen; dest = true; break; case UnitActionPatrol: Video.DrawLineClip(ColorGreen, x1, y1, x2, y2); e_color = color = ColorBlue; x1 = CurrentViewport->Map2ViewportX(order->Arg1.Patrol.x) + TileSizeX / 2; y1 = CurrentViewport->Map2ViewportY(order->Arg1.Patrol.y) + TileSizeY / 2; dest = true; break; case UnitActionRepair: e_color = color = ColorGreen; dest = true; break; case UnitActionAttackGround: x2 = CurrentViewport->Map2ViewportX(order->goalPos.x) + TileSizeX / 2; y2 = CurrentViewport->Map2ViewportY(order->goalPos.y) + TileSizeY / 2; // FALL THROUGH case UnitActionAttack: if (unit.SubAction & 2) { // Show weak targets. e_color = ColorBlue; } else { e_color = ColorRed; } color = ColorRed; dest = true; break; case UnitActionBoard: e_color = color = ColorGreen; dest = true; break; case UnitActionUnload: e_color = color = ColorGreen; dest = true; break; case UnitActionDie: e_color = color = ColorGray; break; case UnitActionSpellCast: e_color = color = ColorBlue; dest = true; break; case UnitActionTrain: e_color = color = ColorGray; break; case UnitActionUpgradeTo: e_color = color = ColorGray; break; case UnitActionResearch: e_color = color = ColorGray; break; case UnitActionBuild: { int w = order->Arg1.Type->BoxWidth; int h = order->Arg1.Type->BoxHeight; DrawSelection(ColorGray, x2 - w / 2, y2 - h / 2, x2 + w / 2, y2 + h / 2); e_color = color = ColorGreen; dest = true; } break; case UnitActionBuilt: e_color = color = ColorGray; break; case UnitActionResource: e_color = color = ColorYellow; dest = true; break; case UnitActionReturnGoods: e_color = color = ColorYellow; dest = true; break; default: e_color = color = ColorGray; DebugPrint("Unknown action %d\n" _C_ order->Action); break; } Video.FillCircleClip(color, x1, y1, 2); if (dest) { Video.DrawLineClip(color, x1, y1, x2, y2); Video.FillCircleClip(e_color, x2, y2, 3); } }