//----------------------------------------------------------------------------- // // VActorPhysicsController::updateMoveState(); // // ... // //----------------------------------------------------------------------------- void VActorPhysicsController::updateMoveState( void ) { switch( mControlState ) { case k_PathControlState : { AssertFatal( isPathing(), "VActorPhysicsController::updateMoveState() - Invalid Path State." ); // Update Move State. VPathObject *pathObject = mMountedPath->getPathObject( mObject ); if ( !pathObject->isActive() ) { // Idle. setMoveState( k_NullMove ); } else { // Set Movement Direction. setMoveState( ( pathObject->isForward() ) ? k_ForwardMove : k_BackwardMove ); } } break; default : { // Set Idle. setMoveState( k_NullMove ); } break; } }
bool SimMovingShape::onSimTriggerEvent(const SimTriggerEvent* event) { switch(event->action) { case SimTriggerEvent::Activate: setMoveState(Forward); break; case SimTriggerEvent::Deactivate: setMoveState(Backward); break; default: return false; } return true; }
void WorkerBee::onEnterState(State state) { if (state == IN_HIVE) { setMoveState(MoveState::AT_REST); } else if (state == COLLECT_POLLEN) { setDebugStatus("collecting_pollen"); setMoveState(MoveState::AT_REST); } else if (state == TO_FLOWER) { setMoveState(MoveState::TARGET); } else if (state == RETURN_HIVE) { setDebugStatus("back_to_hive"); setMoveTarget(getHive().getPosition()); setMoveState(MoveState::TARGET); } }
bool SimMovingShape::processEvent(const SimEvent* event) { switch (event->type) { onEvent(SimMovementCollisionEvent); onEvent(SimMessageEvent); onEvent(SimTimerEvent); onEvent(SimTriggerEvent); // case SimActionEventType: { const SimActionEvent* ep = static_cast<const SimActionEvent*>(event); switch(ep->action) { case MoveForward: setMoveState(Forward); break; case MoveBackward: setMoveState(Backward); break; } } } return Parent::processEvent(event); }
bool SimMovingShape::onSimMovementCollisionEvent(const SimMovementCollisionEvent* event) { if (record.flags.test(Record::ForwardOnCollision) && state != Forward && state != End) { SimObject* obj = event->getObject(manager); if (obj && obj->getType() & objectMask) { // Only use the forward delay if we are not moving // (or there is none). if (state == Backward || !record.forwardDelay) setMoveState(Forward); else SimMessageEvent::post(this, float(manager->getCurrentTime()) + record.forwardDelay, Forward); } } return true; }
void WorkerBee::onState(State state, sf::Time dt) { Vec2d empty(-1.0, -1.0); // first state if (state == IN_HIVE) { // if bee has pollen transfer it to hive if (getPollen() > 0) { transferPollen(dt); flower_location_ = empty; setDebugStatus("in_hive_leaving_pollen"); } else { // if bee has not enough energy to leave hive, eat its nectar if (getEnergy() < energy_leave_hive_ && getHive().getNectar() > 0) { setDebugStatus("in_hive_eating"); eatFromHive(dt); } // if there is a flower in memory and enough energy, target move // to this flower else if (flower_location_ != empty && getEnergy() > energy_collect_pollen_) { setDebugStatus("in_hive_leaving"); setMoveTarget(flower_location_); // change state to to flower nextState(); } else { setDebugStatus("in_hive_no_flower"); } } } // second state else if (state == TO_FLOWER) { setDebugStatus("to_flower"); if (getEnergy() < energy_collect_pollen_) { nextState(); nextState(); } Flower* flower = getAppEnv().getCollidingFlower(getVisionRange()); if (flower) { setMoveTarget(flower->getPosition()); setMoveState(MoveState::TARGET); if (isPointInside(flower->getPosition())) { nextState(); } } else if (isPointInside(flower_location_)) { // go back to hive and clear location nextState(); nextState(); setFlowerLocation(Vec2d(-1,-1)); } } // third state else if (state == COLLECT_POLLEN) { // if there is a flower at flower location and it has pollen and // bee has not enough pollen, eat pollen from flower Flower* flower(getAppEnv().getCollidingFlower(getCollider())); if ((getPollen() < max_pollen_) && (flower != nullptr) && (flower->getPollen() > 0)) { eatPollen(flower, dt); } else { // else skip collection nextState(); } } else if (state == RETURN_HIVE) { // if bee is in hive change state to in hive if (getHive().isColliderInside(getCollider())) { nextState(); } } }
bool SimMovingShape::onSimMessageEvent(const SimMessageEvent* event) { setMoveState(State(event->message)); return Parent::onSimMessageEvent(event); }