本文整理汇总了C++中CUnit::MoveToXY方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnit::MoveToXY方法的具体用法?C++ CUnit::MoveToXY怎么用?C++ CUnit::MoveToXY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnit
的用法示例。
在下文中一共展示了CUnit::MoveToXY方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeUnitAndPlace
/**
** Cast circle of power.
**
** @param caster Unit that casts the spell
** @param spell Spell-type pointer
** @param target Target unit that spell is addressed to
** @param goalPos tilePos of target spot when/if target does not exist
**
** @return =!0 if spell should be repeated, 0 if not
*/
/* virtual */ int Spell_SpawnPortal::Cast(CUnit &caster, const SpellType &, CUnit *, const Vec2i &goalPos)
{
// FIXME: vladi: cop should be placed only on explored land
CUnit *portal = caster.Goal;
DebugPrint("Spawning a portal exit.\n");
if (portal) {
portal->MoveToXY(goalPos);
} else {
portal = MakeUnitAndPlace(goalPos, *this->PortalType, &Players[PlayerNumNeutral]);
}
// Goal is used to link to destination circle of power
caster.Goal = portal;
//FIXME: setting destination circle of power should use mana
return 0;
}
示例2: DoActionMove
/**
** Unit moves! Generic function called from other actions.
**
** @param unit Pointer to unit.
**
** @return >0 remaining path length, 0 wait for path, -1
** reached goal, -2 can't reach the goal.
*/
int DoActionMove(CUnit &unit)
{
Vec2i posd; // movement in tile.
int d;
Assert(unit.CanMove());
if (!unit.Moving && (unit.Type->Animations->Move != unit.Anim.CurrAnim || !unit.Anim.Wait)) {
Assert(!unit.Anim.Unbreakable);
// FIXME: So units flying up and down are not affected.
unit.IX = 0;
unit.IY = 0;
UnmarkUnitFieldFlags(unit);
d = NextPathElement(unit, &posd.x, &posd.y);
MarkUnitFieldFlags(unit);
switch (d) {
case PF_UNREACHABLE: // Can't reach, stop
if (unit.Player->AiEnabled) {
AiCanNotMove(unit);
}
unit.Moving = 0;
return d;
case PF_REACHED: // Reached goal, stop
unit.Moving = 0;
return d;
case PF_WAIT: // No path, wait
// Reset frame to still frame while we wait
// FIXME: Unit doesn't animate.
unit.Frame = unit.Type->StillFrame;
UnitUpdateHeading(unit);
unit.Wait = 10;
unit.Moving = 0;
return d;
default: // On the way moving
unit.Moving = 1;
break;
}
if (unit.Type->UnitType == UnitTypeNaval) { // Boat (un)docking?
const CMapField &mf_cur = *Map.Field(unit.Offset);
const CMapField &mf_next = *Map.Field(unit.tilePos + posd);
if (mf_cur.WaterOnMap() && mf_next.CoastOnMap()) {
PlayUnitSound(unit, VoiceDocking);
} else if (mf_cur.CoastOnMap() && mf_next.WaterOnMap()) {
PlayUnitSound(unit, VoiceDocking); // undocking
}
}
Vec2i pos = unit.tilePos + posd;
unit.MoveToXY(pos);
// Remove unit from the current selection
if (unit.Selected && !Map.Field(pos)->playerInfo.IsTeamVisible(*ThisPlayer)) {
if (NumSelected == 1) { // Remove building cursor
CancelBuildingMode();
}
if (!ReplayRevealMap) {
UnSelectUnit(unit);
SelectionChanged();
}
}
unit.IX = -posd.x * PixelTileSize.x;
unit.IY = -posd.y * PixelTileSize.y;
unit.Frame = unit.Type->StillFrame;
UnitHeadingFromDeltaXY(unit, posd);
} else {
posd.x = Heading2X[unit.Direction / NextDirection];
posd.y = Heading2Y[unit.Direction / NextDirection];
d = unit.pathFinderData->output.Length + 1;
}
unit.pathFinderData->output.Cycles++;//reset have to be manualy controled by caller.
int move = UnitShowAnimationScaled(unit, unit.Type->Animations->Move, Map.Field(unit.Offset)->Cost);
unit.IX += posd.x * move;
unit.IY += posd.y * move;
// Finished move animation, set Moving to 0 so we recalculate the path
// next frame
// FIXME: this is broken for subtile movement
if (!unit.Anim.Unbreakable && !unit.IX && !unit.IY) {
unit.Moving = 0;
}
return d;
}