void Player::OnKeyDown(const CL_InputEvent &key, const CL_InputState &state) { if (m_flags[eDead]) { //TODO: I was a bit lazy here, maybe introduce respawn key as a keybind? if (key.id == CL_KEY_F1) { Respawn(); } return; } //TODO: can this be turned into a switch-case without breaking logic? if (key.id == m_moveLeftKey) { m_moveLeftKeyPressed = true; StartMoving(eLeft); } if (key.id == m_moveRightKey) { m_moveRightKeyPressed = true; StartMoving(eRight); } if (key.id == m_jumpKey && !m_jumpKeyPressed) { m_jumpKeyPressed = true; StartJump(); } if (key.id == m_attackKey && !m_attackKeyPressed) { m_attackKeyPressed = true; StartAttack(); } }
void PhysicalObj::UpdatePosition() { // No ghost allowed here ! if (IsGhost()) { return; } if (m_collides_with_ground) { // object is not moving if (!IsMoving()) { // and has no reason to move if (!FootsInVacuum()) { if (!IsInWater()) { return; } } else { // it should fall ! StartMoving(); } } } // Compute new position. RunPhysicalEngine(); if (IsGhost()) { return; } // Classical object sometimes sinks in water and sometimes goes out of water! if (m_collides_with_ground) { if (IsInWater() && m_alive!=DROWNED && m_alive!=DEAD) Drown(); else if (!IsInWater() && m_alive==DROWNED) GoOutOfWater(); } }
void noFigure::StartWalking(const unsigned char newDir) { assert(!(GetGOT() == GOT_NOF_PASSIVESOLDIER && fs == FS_JOB)); assert(newDir <= 5); if(newDir > 5) { LOG.lprintf("Achtung: Bug im Spiel entdeckt! noFigure::StartWalking: dir = %d\n", unsigned(newDir)); return; } // Gehen wir in ein Gebäude? if(newDir == 1 && gwg->GetNO(gwg->GetNeighbour(pos, 1))->GetType() == NOP_BUILDING) gwg->GetSpecObj<noBuilding>(gwg->GetNeighbour(pos, 1))->OpenDoor(); // Dann die Tür aufmachen // oder aus einem raus? if(newDir == 4 && gwg->GetNO(pos)->GetType() == NOP_BUILDING) gwg->GetSpecObj<noBuilding>(pos)->OpenDoor(); // Dann die Tür aufmachen // Ist der Platz schon besetzt, wo wir hinlaufen wollen und laufen wir auf Straßen? if(!gwg->IsRoadNodeForFigures(gwg->GetNeighbour(pos, newDir), newDir) && cur_rs) { // Dann stehen bleiben! FaceDir(newDir); waiting_for_free_node = true; // Andere Figuren stoppen gwg->StopOnRoads(pos, newDir); } else { // Normal hinlaufen StartMoving(newDir, 20); } }
//----------------------------------------------------------------------------- // Purpose: We have just arrived at a key, move onto the next keyframe //----------------------------------------------------------------------------- void CBaseMoveBehavior::MoveDone( void ) { // if we're just a base then keep playing the anim if ( !stricmp(STRING(m_iClassname), "move_keyframed") ) { int direction = m_iDirection; // start moving from the keyframe we've just reached if ( !StartMoving(direction) ) { // try moving in the other direction StartMoving( -direction ); } } BaseClass::MoveDone(); }
void CHoverAirMoveType::KeepPointingTo(float3 pos, float distance, bool aggressive) { wantToStop = false; forceHeading = false; wantedHeight = orgWantedHeight; // close in a little to avoid the command AI to override the pos constantly distance -= 15; // Ignore the exact same order if ((aircraftState == AIRCRAFT_FLYING) && (flyState == FLY_CIRCLING || flyState == FLY_ATTACKING) && ((circlingPos - pos).SqLength2D() < 64) && (goalDistance == distance)) return; circlingPos = pos; goalDistance = distance; goalPos = owner->pos; // let this handle any needed state transitions StartMoving(goalPos, goalDistance); // FIXME: // the FLY_ATTACKING state is broken (unknown how long this has been // the case because <aggressive> was always false up until e7ae68df) // aircraft fly *right up* to their target without stopping // after fixing this, the "circling" behavior is now broken // (waitCounter is always 0) if (aggressive) { flyState = FLY_ATTACKING; } else { flyState = FLY_CIRCLING; } }
void NPC::TakeAction(BasicAction action, int timeElapsedMs) { //TODO: terrible code, consider using references switch (action) { case eAttack: { StopMoving(); StartAttack(); //TODO: might need to override break; } case eMove: { //compiler mistook this for the Move() method.. // reset speed to normal if (m_flags[eAffectedByGravity] && !m_flags[eJumping] && !m_flags[eFalling]) { m_speeds[eXSpeed] = m_speedX; m_speeds[eYSpeed] = m_speedY; } StartMoving(GetDirection()); break; } case eFlee: { // reset speed to normal if (m_flags[eAffectedByGravity] && !m_flags[eJumping] && !m_flags[eFalling]) { m_speeds[eXSpeed] = m_speedX; m_speeds[eYSpeed] = m_speedY; } //avoid colliding with the character //TODO: WHAT? This makes no sense (even before refactor) StartMoving(m_direction == eLeft ? eRight : eLeft); break; } case eJump: { StartJump(); break; } case eShoot: { Shoot(m_attackType); break; } default: { StopMoving(); if (!m_flags[eAffectedByGravity]) { m_speeds[eXSpeed] = 0; m_speeds[eYSpeed] = 0; } break; } } }
void PhysicalObj::GoOutOfWater() { ASSERT (m_alive == DROWNED); MSG_DEBUG("physic.state", "%s - Go out of water!...", GetName().c_str()); m_alive = ALIVE; // Set the air grab to normal air resist factor. SetAirResistFactor(m_cfg.m_air_resist_factor); SetGravityFactor(m_cfg.m_gravity_factor); StartMoving(); SignalGoingOutOfWater(); }
void CBaseMoveBehavior::Activate( void ) { BaseClass::Activate(); SetMoveDoneTime( 0.5 ); // start moving in 0.2 seconds time // if we are just the basic keyframed entity, cycle our animation if ( !stricmp(GetClassname(), "move_keyframed") ) { StartMoving( 1 ); } }
void Player::OnKeyUp(const CL_InputEvent &key, const CL_InputState &state) { if (m_flags[eDead]) { return; } //TODO: can this be turned into a switch-case without breaking logic? if (key.id == m_moveLeftKey) { m_moveLeftKeyPressed = false; //Handle case where both left and right are pressed before releasing left key if (m_moveRightKeyPressed) { StartMoving(eRight); } else { StopMoving(); } } if (key.id == m_moveRightKey) { m_moveRightKeyPressed = false; //Handle case where both left and right are pressed before releasing right key if (m_moveLeftKeyPressed) { StartMoving(eLeft); } else { StopMoving(); } } if (key.id == m_jumpKey) { m_jumpKeyPressed = false; m_stats[eJumpTime] = m_stats[eMaxJumpTime]; } if (key.id == m_attackKey) { m_attackKeyPressed = false; } }
void PhysicalObj::SetXY(const Point2d &position) { CheckOverlapping(); // Don't use METER_PER_PIXEL here: bad truncation occurs if (IsOutsideWorldXY(Point2i(position.x, position.y)) && can_be_ghost) { SetPhysXY(position / PIXEL_PER_METER); Ghost(); SignalOutOfMap(); } else { SetPhysXY(position / PIXEL_PER_METER); if (FootsInVacuum()) StartMoving(); } }
void LDesktopPluginSpace::addDesktopPlugin(QString plugID){ //This is used for generic plugins (QWidget-based) if(DEBUG){ qDebug() << "Adding Desktop Plugin:" << plugID; } LDPlugin *plug = NewDP::createPlugin(plugID, this); if(plug==0){ return; } //invalid plugin //plug->setAttribute(Qt::WA_TranslucentBackground); plug->setWhatsThis(plugID); //Now get the saved geometry for the plugin QRect geom = plug->gridGeometry(); //grid coordinates if(geom.isNull()){ //Try the old format (might be slight drift between sessions if the grid size changes) geom = plug->loadPluginGeometry(); //in pixel coords if(!geom.isNull()){ geom = geomToGrid(geom); } //convert to grid coordinates } if(DEBUG){ qDebug() << "Saved plugin geom:" << geom << plugID; } //Now determine the position to put it if(geom.isNull()){ //No previous location - need to calculate initial geom QSize sz = plug->defaultPluginSize(); //in grid coordinates geom.setSize(sz); //if an applauncher - add from top-left, otherwise add in from bottom-right if(plugID.startsWith("applauncher")){ geom = findOpenSpot(geom.width(), geom.height() ); } else{ geom = findOpenSpot(geom.width(), geom.height(), RoundUp(this->height()/GRIDSIZE), RoundUp(this->width()/GRIDSIZE), true); } }else if(!ValidGeometry(plugID, gridToGeom(geom)) ){ //Find a new location for the plugin (saved location is invalid) geom = findOpenSpot(geom.width(), geom.height(), geom.y(), geom.x(), false); //try to get it within the same general area first } if(geom.x() < 0 || geom.y() < 0){ qDebug() << "No available space for desktop plugin:" << plugID << " - IGNORING"; delete plug; }else{ if(DEBUG){ qDebug() << " - New Plugin Geometry (grid):" << geom; } //Now place the item in the proper spot/size plug->setGridGeometry(geom); //save for later MovePlugin(plug, gridToGeom(geom)); //plug->setGeometry( gridToGeom(geom) ); plug->show(); if(DEBUG){ qDebug() << " - New Plugin Geometry (px):" << plug->geometry(); } ITEMS << plug; connect(plug, SIGNAL(StartMoving(QString)), this, SLOT(StartItemMove(QString)) ); connect(plug, SIGNAL(StartResizing(QString)), this, SLOT(StartItemResize(QString)) ); connect(plug, SIGNAL(RemovePlugin(QString)), this, SLOT(RemoveItem(QString)) ); connect(plug, SIGNAL(IncreaseIconSize()), this, SIGNAL(IncreaseIcons()) ); connect(plug, SIGNAL(DecreaseIconSize()), this, SIGNAL(DecreaseIcons()) ); connect(plug, SIGNAL(CloseDesktopMenu()), this, SIGNAL(HideDesktopMenu()) ); } }
void LDesktopPluginSpace::addDesktopPlugin(QString plugID){ //This is used for generic plugins (QWidget-based) if(DEBUG){ qDebug() << "Adding Desktop Plugin:" << plugID; } LDPlugin *plug = NewDP::createPlugin(plugID, this); plug->setWhatsThis(plugID); //Now get the geometry for the plugin QRect geom = plug->loadPluginGeometry(); //in pixel coords if(!geom.isNull()){ geom = geomToGrid(geom); } //convert to grid coordinates if(geom.isNull()){ //No previous location - need to calculate initial geom QSize sz = plug->defaultPluginSize(); //in grid coordinates geom.setSize(sz); geom = findOpenSpot(geom.width(), geom.height() ); }else if(!ValidGeometry(plugID, gridToGeom(geom)) ){ //Find a new location for the plugin (saved location is invalid) geom = findOpenSpot(geom.width(), geom.height(), geom.y(), geom.x(), false); //try to get it within the same general area first } if(geom.x() < 0 || geom.y() < 0){ qDebug() << "No available space for desktop plugin:" << plugID << " - IGNORING"; delete plug; }else{ if(DEBUG){ qDebug() << " - New Plugin Geometry (grid):" << geom; } //Now place the item in the proper spot/size MovePlugin(plug, gridToGeom(geom)); //plug->setGeometry( gridToGeom(geom) ); plug->show(); if(DEBUG){ qDebug() << " - New Plugin Geometry (px):" << plug->geometry(); } ITEMS << plug; connect(plug, SIGNAL(StartMoving(QString)), this, SLOT(StartItemMove(QString)) ); connect(plug, SIGNAL(StartResizing(QString)), this, SLOT(StartItemResize(QString)) ); connect(plug, SIGNAL(RemovePlugin(QString)), this, SLOT(RemoveItem(QString)) ); connect(plug, SIGNAL(IncreaseIconSize()), this, SIGNAL(IncreaseIcons()) ); connect(plug, SIGNAL(DecreaseIconSize()), this, SIGNAL(DecreaseIcons()) ); connect(plug, SIGNAL(CloseDesktopMenu()), this, SIGNAL(HideDesktopMenu()) ); } }
void PhysicalObj::Drown() { ASSERT (m_alive != DROWNED); MSG_DEBUG("physic.state", "%s - Drowned...", GetName().c_str()); m_alive = DROWNED; // Set the air grab to water resist factor. SetAirResistFactor(m_cfg.m_water_resist_factor); // Ensure the gravity factor is upper than 0.0 if (EqualsZero(GetGravityFactor())) SetGravityFactor(0.1); // If fire, do smoke... if (m_is_fire) GetWorld().water.Smoke(GetPosition()); // make a splash in the water :-) else if (GetMass() >= 2 && GetName() != "water_particle") GetWorld().water.Splash(GetPosition()); StopMoving(); StartMoving(); SignalDrowning(); }
void CTAAirMoveType::StartMoving(float3 pos, float goalRadius, float speed) { //info->AddLine("airmove: Ignoring startmoving speed"); StartMoving(pos, goalRadius); }
void CTAAirMoveType::StartMoving(float3 pos, float goalRadius, float speed) { //logOutput.Print("airmove: Ignoring startmoving speed"); StartMoving(pos, goalRadius); }
nsresult HTMLEditor::MouseMove(nsIDOMMouseEvent* aMouseEvent) { MOZ_ASSERT(aMouseEvent); NS_NAMED_LITERAL_STRING(leftStr, "left"); NS_NAMED_LITERAL_STRING(topStr, "top"); if (mIsResizing) { // we are resizing and the mouse pointer's position has changed // we have to resdisplay the shadow int32_t clientX, clientY; aMouseEvent->GetClientX(&clientX); aMouseEvent->GetClientY(&clientY); int32_t newX = GetNewResizingX(clientX, clientY); int32_t newY = GetNewResizingY(clientX, clientY); int32_t newWidth = GetNewResizingWidth(clientX, clientY); int32_t newHeight = GetNewResizingHeight(clientX, clientY); mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::left, newX); mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::top, newY); mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width, newWidth); mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height, newHeight); return SetResizingInfoPosition(newX, newY, newWidth, newHeight); } if (mGrabberClicked) { int32_t clientX, clientY; aMouseEvent->GetClientX(&clientX); aMouseEvent->GetClientY(&clientY); int32_t xThreshold = LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdX, 1); int32_t yThreshold = LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdY, 1); if (DeprecatedAbs(clientX - mOriginalX) * 2 >= xThreshold || DeprecatedAbs(clientY - mOriginalY) * 2 >= yThreshold) { mGrabberClicked = false; StartMoving(nullptr); } } if (mIsMoving) { int32_t clientX, clientY; aMouseEvent->GetClientX(&clientX); aMouseEvent->GetClientY(&clientY); int32_t newX = mPositionedObjectX + clientX - mOriginalX; int32_t newY = mPositionedObjectY + clientY - mOriginalY; SnapToGrid(newX, newY); mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::left, newX); mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::top, newY); } return NS_OK; }
NS_IMETHODIMP nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) { NS_NAMED_LITERAL_STRING(leftStr, "left"); NS_NAMED_LITERAL_STRING(topStr, "top"); if (mIsResizing) { // we are resizing and the mouse pointer's position has changed // we have to resdisplay the shadow nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) ); PRInt32 clientX, clientY; mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); PRInt32 newX = GetNewResizingX(clientX, clientY); PRInt32 newY = GetNewResizingY(clientX, clientY); PRInt32 newWidth = GetNewResizingWidth(clientX, clientY); PRInt32 newHeight = GetNewResizingHeight(clientX, clientY); mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, leftStr, newX); mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, topStr, newY); mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, NS_LITERAL_STRING("width"), newWidth); mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, NS_LITERAL_STRING("height"), newHeight); return SetResizingInfoPosition(newX, newY, newWidth, newHeight); } if (mGrabberClicked) { nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) ); PRInt32 clientX, clientY; mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); nsCOMPtr<nsILookAndFeel> look = do_GetService(kLookAndFeelCID); NS_ASSERTION(look, "Look and feel service must be implemented for this toolkit"); PRInt32 xThreshold=1, yThreshold=1; look->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, xThreshold); look->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, yThreshold); if (PR_ABS(clientX - mOriginalX ) * 2 >= xThreshold || PR_ABS(clientY - mOriginalY ) * 2 >= yThreshold) { mGrabberClicked = PR_FALSE; StartMoving(nsnull); } } if (mIsMoving) { nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) ); PRInt32 clientX, clientY; mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); PRInt32 newX = mPositionedObjectX + clientX - mOriginalX; PRInt32 newY = mPositionedObjectY + clientY - mOriginalY; SnapToGrid(newX, newY); mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, leftStr, newX); mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, topStr, newY); } return NS_OK; }
void noAnimal::StartWalking(const unsigned char dir) { StartMoving(dir, ANIMALCONSTS[species].speed); }
void noShip::StartDriving(const unsigned char dir) { const unsigned SHIP_SPEEDS[] = {35, 25, 20, 10, 5}; StartMoving(dir, SHIP_SPEEDS[GAMECLIENT.GetGGS().getSelection(ADDON_SHIP_SPEED)]); }
void CTAAirMoveType::StartMoving(float3 pos, float goalRadius, float speed) { StartMoving(pos, goalRadius); }
void noShip::StartDriving(const unsigned char dir) { const unsigned SHIP_SPEEDS[] = {35, 25, 20, 10, 5}; StartMoving(dir, SHIP_SPEEDS[gwg->GetGGS().getSelection(AddonId::SHIP_SPEED)]); }