本文整理汇总了C++中CanMove函数的典型用法代码示例。如果您正苦于以下问题:C++ CanMove函数的具体用法?C++ CanMove怎么用?C++ CanMove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CanMove函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleActionUnload
/**
** The transporter unloads a unit.
**
** @param unit Pointer to unit.
*/
void HandleActionUnload(CUnit *unit)
{
int i;
int x;
int y;
if (!CanMove(unit)) {
unit->SubAction = 2;
}
switch (unit->SubAction) {
//
// Move the transporter
//
case 0:
if (!unit->Orders[0]->Goal) {
if (!ClosestFreeDropZone(unit, unit->Orders[0]->X, unit->Orders[0]->Y,
&x, &y)) {
// Sorry... I give up.
unit->ClearAction();
return;
}
unit->Orders[0]->X = x;
unit->Orders[0]->Y = y;
}
NewResetPath(unit);
unit->SubAction = 1;
case 1:
// The Goal is the unit that we have to unload.
if (!unit->Orders[0]->Goal) {
// We have to unload everything
if ((i = MoveToDropZone(unit))) {
if (i == PF_REACHED) {
if (++unit->SubAction == 1) {
unit->ClearAction();
}
} else {
unit->SubAction = 2;
}
}
break;
}
//
// Leave the transporter
//
case 2:
// FIXME: show still animations ?
LeaveTransporter(unit);
if (CanMove(unit) && unit->Orders[0]->Action != UnitActionStill) {
HandleActionUnload(unit);
}
break;
}
}
示例2: rand
bool Oneal::Collision(Entity* E) {
// Entity-to-map collision
if (E == NULL) {
int dice = rand()%100;
if (abs(SpeedX) > 0) {
//50% to go in opposite direction
if (dice > 50 && CanMove(X - SpeedX, Y)) {
//std::cout << "Diced " << dice << " to go in the opposite direction. Speed " << SpeedX;
SpeedX = -SpeedX;
//std::cout << " to " << SpeedX << std::endl;
} else if (dice > 25 && CanMove(X, Y + SpeedX)) {
//std::cout << "Diced " << dice << " to go down. Speed " << SpeedX << " " << SpeedY;
if (SpeedY == 0) SpeedY = SpeedX;
SpeedX = 0;
//std::cout << " to " << SpeedX << " " << SpeedY << std::endl;
} else {
//std::cout << "Diced " << dice << " to go up. Speed " << SpeedX << " " << SpeedY;
if (SpeedY == 0) SpeedY = -SpeedX;
SpeedX = 0;
//std::cout << " to " << SpeedX << " " << SpeedY << std::endl;
}
}
if (abs(SpeedY) > 0) {
//50% to go in opposite direction
if (dice > 50) {
//std::cout << "Diced " << dice << " to go in the opposite direction. Speed " << SpeedY;
SpeedY = -SpeedY;
//std::cout << " to " << SpeedY << std::endl;
} else if (dice > 25) {
//std::cout << "Diced " << dice << " to go right direction. Speed " << SpeedY << " " << SpeedX;
if (SpeedX == 0) SpeedX = SpeedY;
SpeedY = 0;
//std::cout << " to " << SpeedX << " " << SpeedY << std::endl;
} else {
if (SpeedX == 0) SpeedX = -SpeedY;
SpeedY = 0;
}
}
return false;
} else {
;
}
return true;
}
示例3: MoveLeft
void MoveLeft()
{
struct Brick b = Brick;
b.pos.x--;
if (CanMove(b) == TRUE) {
b.pos.x++;
b.pos.y++;
if ( CanMove(b) == FALSE )
Delay=0;
DisplayBrick(Brick,FALSE);
Brick.pos.x--;
Expect();
DisplayBrick(Brick,TRUE);
}
}
示例4: MoveDown
BOOL MoveDown()
{
struct Brick b = Brick;
b.pos.y++;
if (CanMove(b) != TRUE) {
return TRUE;
}
if ( CanMove(b) == TRUE ){
DisplayBrick(Brick,FALSE);
Brick.pos.y++;
DisplayBrick(Brick,TRUE);
return FALSE;
}
}
示例5: MoveUp
void MoveUp()
{
struct Brick b = Brick;
if(++b.rotation == 4) b.rotation=0;
if (CanMove(b) == TRUE) {
DisplayBrick(Brick,FALSE);
Brick.rotation=b.rotation;
Expect();
DisplayBrick(Brick,TRUE);
b.rotation--;
b.pos.y++;
if ( CanMove(b) == FALSE )
Delay=0;
}
}
示例6: StartMove
bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 diff)
{
// Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff
if (creature->HasUnitState(UNIT_STATE_NOT_MOVE))
{
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true;
}
// prevent a crash at empty waypoint path.
if (!i_path || i_path->empty())
return false;
if (Stopped())
{
if (CanMove(diff))
return StartMove(creature);
}
else
{
// Set home position at place on waypoint movement.
if (!creature->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) || !creature->GetTransGUID())
creature->SetHomePosition(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation());
if (creature->IsStopped())
Stop(STOP_TIME_FOR_PLAYER);
else if (creature->movespline->Finalized())
{
OnArrived(creature);
return StartMove(creature);
}
}
return true;
}
示例7: Stop
bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 diff)
{
// Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff
if (creature->HasUnitState(UNIT_STATE_NOT_MOVE))
{
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true;
}
// prevent a crash at empty waypoint path.
if (!i_path || i_path->empty())
return false;
// Xinef: Dont allow dead creatures to move
if (!creature->IsAlive())
return false;
// prevent movement while casting spells with cast time or channel time
if (creature->HasUnitState(UNIT_STATE_CASTING))
{
bool stop = true;
if (Spell* spell = creature->GetCurrentSpell(CURRENT_CHANNELED_SPELL))
if (!(spell->GetSpellInfo()->ChannelInterruptFlags & (AURA_INTERRUPT_FLAG_MOVE | AURA_INTERRUPT_FLAG_TURNING)) && !(spell->GetSpellInfo()->InterruptFlags & SPELL_INTERRUPT_FLAG_MOVEMENT))
stop = false;
if (stop)
{
Stop(1000);
if (!creature->IsStopped())
creature->StopMoving();
return true;
}
}
if (Stopped())
{
if (CanMove(diff))
return StartMove(creature);
}
else
{
if (creature->IsStopped())
Stop(STOP_TIME_FOR_PLAYER);
else
{
// xinef: code to detect pre-empetively if we should start movement to next waypoint
// xinef: do not start pre-empetive movement if current node has delay or we are ending waypoint movement
bool finished = creature->movespline->Finalized();
if (!finished && !i_path->at(i_currentNode)->delay && ((i_currentNode != i_path->size() - 1) || repeating))
finished = (creature->movespline->_Spline().length(creature->movespline->_currentSplineIdx()+1) - creature->movespline->timePassed()) < 200;
if (finished)
{
OnArrived(creature);
return StartMove(creature);
}
}
}
return true;
}
示例8: StartMove
bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 diff)
{
// Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff
if (creature->HasUnitState(UNIT_STATE_NOT_MOVE))
{
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true;
}
// prevent a crash at empty waypoint path.
if (!i_path || i_path->empty())
return false;
if (Stopped())
{
if (CanMove(diff))
return StartMove(creature);
}
else
{
if (creature->IsStopped())
Stop(STOP_TIME_FOR_PLAYER);
else if (creature->movespline->Finalized())
{
OnArrived(creature);
return StartMove(creature);
}
}
return true;
}
示例9: CommandFollow
/**
** Follow unit to new position
**
** @param unit pointer to unit.
** @param dest unit to be followed
** @param flush if true, flush command queue.
*/
void CommandFollow(CUnit *unit, CUnit *dest, int flush)
{
COrder *order;
//
// Check if unit is still valid? (NETWORK!)
//
if (!unit->Removed && unit->Orders[0]->Action != UnitActionDie) {
if (!CanMove(unit)) {
// FIXME: should find a better way for pending orders.
order = &unit->NewOrder;
ReleaseOrder(order);
} else if (!(order = GetNextOrder(unit, flush))) {
return;
}
order->Init();
order->Action = UnitActionFollow;
//
// Destination could be killed.
// Should be handled in action, but is not possible!
// Unit::Refs is used as timeout counter.
//
if (dest->Destroyed) {
order->X = dest->X + dest->Type->TileWidth / 2;
order->Y = dest->Y + dest->Type->TileHeight / 2;
} else {
order->Goal = dest;
dest->RefsIncrease();
order->Range = 1;
}
}
ClearSavedAction(unit);
}
示例10: CommandPatrolUnit
/**
** Let an unit patrol from current to new position
**
** FIXME: want to support patroling between units.
**
** @param unit pointer to unit.
** @param x X map position to patrol between.
** @param y Y map position to patrol between.
** @param flush if true, flush command queue.
*/
void CommandPatrolUnit(CUnit *unit, int x, int y, int flush)
{
COrder *order;
Assert(x >= 0 && y >= 0 && x < Map.Info.MapWidth && y < Map.Info.MapHeight);
//
// Check if unit is still valid? (NETWORK!)
//
if (!unit->Removed && unit->Orders[0]->Action != UnitActionDie) {
if (!CanMove(unit)) {
// FIXME: should find a better way for pending orders.
order = &unit->NewOrder;
ReleaseOrder(order);
} else if (!(order = GetNextOrder(unit, flush))) {
return;
}
order->Init();
order->Action = UnitActionPatrol;
order->X = x;
order->Y = y;
Assert(!(unit->X & ~0xFFFF) && !(unit->Y & ~0xFFFF));
order->Arg1.Patrol.X = unit->X;
order->Arg1.Patrol.Y = unit->Y;
}
ClearSavedAction(unit);
}
示例11: if
bool WaypointMovementGenerator<Creature>::Update(Creature& creature, const uint32& diff)
{
// Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff
if (creature.hasUnitState(UNIT_STAT_NOT_MOVE))
{
creature.clearUnitState(UNIT_STAT_ROAMING_MOVE);
return true;
}
// prevent a crash at empty waypoint path.
if (!i_path || i_path->empty())
{
creature.clearUnitState(UNIT_STAT_ROAMING_MOVE);
return true;
}
if (Stopped(creature))
{
if (CanMove(diff, creature))
{ StartMove(creature); }
}
else
{
if (creature.IsStopped())
{ Stop(STOP_TIME_FOR_PLAYER); }
else if (creature.movespline->Finalized())
{
OnArrived(creature);
StartMove(creature);
}
}
return true;
}
示例12: switch
/*
================
rvMonsterConvoyGround::State_Legs_Move
================
*/
stateResult_t rvMonsterConvoyGround::State_Legs_Move ( const stateParms_t& parms ) {
enum {
STAGE_INIT,
STAGE_MOVE
};
switch ( parms.stage ) {
case STAGE_INIT:
move.fl.allowAnimMove = true;
move.fl.allowPrevAnimMove = false;
move.fl.running = true;
move.currentDirection = MOVEDIR_FORWARD;
// TODO: Looks like current anim rate never gets reset, so they do not correctly accelerate from a stop
// unfortunately, adding this change (with a decent acceleration factor) caused them to do lots of
// not-so-good looking short moves.
// moveCurrentAnimRate = 0;
oldOrigin = physicsObj.GetOrigin ( );
PlayCycle ( ANIMCHANNEL_LEGS, "run", 0 );
StartSound( "snd_move", SND_CHANNEL_BODY3, 0, false, NULL );
return SRESULT_STAGE ( STAGE_MOVE );
case STAGE_MOVE:
// If not moving forward just go back to idle
if ( !move.fl.moving || !CanMove() ) {
StopSound( SND_CHANNEL_BODY3, 0 );
PostAnimState ( ANIMCHANNEL_LEGS, "Legs_Idle", 0 );
return SRESULT_DONE;
}
// If on the ground update the animation rate based on the normal of the ground plane
if ( !ai_debugHelpers.GetBool ( ) && physicsObj.HasGroundContacts ( ) ) {
float rate;
idVec3 dir;
dir = (physicsObj.GetOrigin ( ) - oldOrigin);
if ( DistanceTo ( move.moveDest ) < move.walkRange ) {
rate = moveAnimRateMin;
} else if ( dir.Normalize ( ) > 0.0f ) {
rate = idMath::ClampFloat ( -0.7f, 0.7f, physicsObj.GetGravityNormal ( ) * dir ) / 0.7f;
rate = moveAnimRateMin + moveAnimRateRange * (1.0f + rate) / 2.0f;
} else {
rate = moveAnimRateMin + moveAnimRateRange * 0.5f;
}
moveCurrentAnimRate += ((rate - moveCurrentAnimRate) * moveAccelRate);
animator.CurrentAnim ( ANIMCHANNEL_LEGS )->SetPlaybackRate ( gameLocal.time, moveCurrentAnimRate );
}
oldOrigin = physicsObj.GetOrigin ( );
return SRESULT_WAIT;
}
return SRESULT_ERROR;
}
示例13: Expect
void Expect(){
DisplayBrick(expect,FALSE);
expect=Brick;
expect.t=EXPECT;
while(CanMove(expect))
expect.pos.y++;
expect.pos.y--;
DisplayBrick(expect,TRUE);
}
示例14: Swipe
void Swipe(){
struct Brick b;
b=Brick;
b.type = Next.type;
if(CanMove(b)){
DisplayBrick( Brick,FALSE);
DisplayNext(FALSE);
Next.type=Brick.type;
Brick.type=b.type;
Expect();
DisplayBrick(Brick,TRUE);
DisplayNext(TRUE);
}
}
示例15: switch
END_CLASS_STATES
/*
================
rvMonsterRepairBot::State_Legs_Move
================
*/
stateResult_t rvMonsterRepairBot::State_Legs_Move ( const stateParms_t& parms ) {
enum {
STAGE_START,
STAGE_START_WAIT,
STAGE_MOVE,
STAGE_MOVE_WAIT,
STAGE_STOP,
STAGE_STOP_WAIT
};
switch ( parms.stage ) {
case STAGE_START:
PlayAnim ( ANIMCHANNEL_LEGS, "idle_to_run", 4 );
return SRESULT_STAGE ( STAGE_START_WAIT );
case STAGE_START_WAIT:
if ( AnimDone ( ANIMCHANNEL_LEGS, 4 ) ) {
return SRESULT_STAGE ( STAGE_MOVE );
}
return SRESULT_WAIT;
case STAGE_MOVE:
PlayCycle ( ANIMCHANNEL_LEGS, "run", 4 );
return SRESULT_STAGE ( STAGE_MOVE_WAIT );
case STAGE_MOVE_WAIT:
if ( !move.fl.moving || !CanMove() ) {
return SRESULT_STAGE ( STAGE_STOP );
}
return SRESULT_WAIT;
case STAGE_STOP:
PlayAnim ( ANIMCHANNEL_LEGS, "run_to_idle", 4 );
return SRESULT_STAGE ( STAGE_STOP_WAIT );
case STAGE_STOP_WAIT:
if ( AnimDone ( ANIMCHANNEL_LEGS, 4 ) ) {
PostAnimState ( ANIMCHANNEL_LEGS, "Legs_Idle", 4 );
return SRESULT_DONE;
}
return SRESULT_WAIT;
}
return SRESULT_ERROR;
}