Commit 2f55dd130c886376a45c9d0054dbd987cc055155
- Diff rendering mode:
- inline
- side by side
src/being.cpp
(29 / 13)
|   | |||
| 58 | 58 | #define BEING_EFFECTS_FILE "effects.xml" | |
| 59 | 59 | #define HAIR_FILE "hair.xml" | |
| 60 | 60 | ||
| 61 | int Being::mNumberOfHairstyles = 1; | ||
| 61 | static const int DEFAULT_BEING_WIDTH = 32; | ||
| 62 | static const int DEFAULT_BEING_HEIGHT = 32; | ||
| 63 | extern const int MILLISECONDS_IN_A_TICK; | ||
| 62 | 64 | ||
| 63 | static const int DEFAULT_WIDTH = 32; | ||
| 64 | static const int DEFAULT_HEIGHT = 32; | ||
| 65 | 65 | ||
| 66 | int Being::mNumberOfHairstyles = 1; | ||
| 67 | |||
| 66 | 68 | Being::Being(int id, int job, Map *map): | |
| 67 | 69 | #ifdef EATHENA_SUPPORT | |
| 68 | 70 | mWalkTime(0), | |
| … | … | ||
| 89 | 89 | mChildParticleEffects(&mStatusParticleEffects, false), | |
| 90 | 90 | mMustResetParticles(false), | |
| 91 | 91 | #ifdef TMWSERV_SUPPORT | |
| 92 | mWalkSpeed(100), | ||
| 92 | mWalkSpeed(6.0f), // default speed in tile per second | ||
| 93 | 93 | #else | |
| 94 | 94 | mWalkSpeed(150), | |
| 95 | 95 | #endif | |
| … | … | ||
| 527 | 527 | mDest : Vector(mPath.front().x, | |
| 528 | 528 | mPath.front().y); | |
| 529 | 529 | ||
| 530 | // The Vector representing the difference between current position | ||
| 531 | // and the next destination path node. | ||
| 530 | 532 | Vector dir = dest - mPos; | |
| 531 | const float length = dir.length(); | ||
| 532 | 533 | ||
| 534 | const float nominalLength = dir.length(); | ||
| 535 | |||
| 533 | 536 | // When we've not reached our destination, move to it. | |
| 534 | if (length > 0.0f) | ||
| 537 | if (nominalLength > 0.0f && mWalkSpeed > 0.0f) | ||
| 535 | 538 | { | |
| 536 | const float speed = mWalkSpeed / 100.0f; | ||
| 537 | 539 | ||
| 540 | // The private mWalkSpeed member is the speed in tiles per second. | ||
| 541 | // We translate it into pixels per tick, | ||
| 542 | // because the logic is called every ticks. | ||
| 543 | const float speedInTicks = ((float)DEFAULT_TILE_SIDE_LENGTH * mWalkSpeed) | ||
| 544 | / 1000 * (float)MILLISECONDS_IN_A_TICK; | ||
| 545 | |||
| 546 | // The deplacement of a point along a vector is calculated | ||
| 547 | // using the Unit Vector (â) multiplied by the point speed. | ||
| 548 | // â = a / ||a|| (||a|| is the a length.) | ||
| 549 | // Then, diff = (dir/||dir||)*speed, or (dir / ||dir|| / 1/speed). | ||
| 550 | Vector diff = (dir / (nominalLength / speedInTicks)); | ||
| 551 | |||
| 538 | 552 | // Test if we don't miss the destination by a move too far: | |
| 539 | if ((dir / (length / speed)).length() > dir.length()) | ||
| 553 | if (diff.length() > nominalLength) | ||
| 540 | 554 | { | |
| 541 | 555 | setPosition(mPos + dir); | |
| 542 | 556 | ||
| … | … | ||
| 561 | 561 | } | |
| 562 | 562 | // Otherwise, go to it using the nominal speed. | |
| 563 | 563 | else | |
| 564 | setPosition(mPos + (dir / (length / speed))); | ||
| 564 | setPosition(mPos + diff); | ||
| 565 | 565 | ||
| 566 | 566 | if (mAction != WALK) | |
| 567 | 567 | setAction(WALK); | |
| … | … | ||
| 796 | 796 | break; | |
| 797 | 797 | ||
| 798 | 798 | if (base) | |
| 799 | return std::max(base->getWidth(), DEFAULT_WIDTH); | ||
| 799 | return std::max(base->getWidth(), DEFAULT_BEING_WIDTH); | ||
| 800 | 800 | else | |
| 801 | return DEFAULT_WIDTH; | ||
| 801 | return DEFAULT_BEING_WIDTH; | ||
| 802 | 802 | } | |
| 803 | 803 | ||
| 804 | 804 | int Being::getHeight() const | |
| … | … | ||
| 810 | 810 | break; | |
| 811 | 811 | ||
| 812 | 812 | if (base) | |
| 813 | return std::max(base->getHeight(), DEFAULT_HEIGHT); | ||
| 813 | return std::max(base->getHeight(), DEFAULT_BEING_HEIGHT); | ||
| 814 | 814 | else | |
| 815 | return DEFAULT_HEIGHT; | ||
| 815 | return DEFAULT_BEING_HEIGHT; | ||
| 816 | 816 | } | |
| 817 | 817 | ||
| 818 | 818 | void Being::setTargetAnimation(SimpleAnimation* animation) |
src/being.h
(16 / 4)
|   | |||
| 259 | 259 | virtual Type getType() const { return UNKNOWN; } | |
| 260 | 260 | ||
| 261 | 261 | /** | |
| 262 | * Sets the walk speed (in pixels per second). | ||
| 262 | * Sets the walk speed. | ||
| 263 | * in pixels per second for eAthena, | ||
| 264 | * in tiles per second for TMWserv. | ||
| 263 | 265 | */ | |
| 264 | void setWalkSpeed(int speed) { mWalkSpeed = speed; } | ||
| 266 | void setWalkSpeed(float speed) { mWalkSpeed = speed; } | ||
| 265 | 267 | ||
| 266 | int getWalkSpeed() const { return mWalkSpeed; } | ||
| 268 | /** | ||
| 269 | * Gets the walk speed. | ||
| 270 | * in pixels per second for eAthena, | ||
| 271 | * in tiles per second for TMWserv (0.1 precision). | ||
| 272 | */ | ||
| 273 | float getWalkSpeed() const { return mWalkSpeed; } | ||
| 267 | 274 | ||
| 268 | 275 | /** | |
| 269 | 276 | * Sets the sprite id. | |
| … | … | ||
| 575 | 575 | /** Speech Bubble components */ | |
| 576 | 576 | SpeechBubble *mSpeechBubble; | |
| 577 | 577 | ||
| 578 | int mWalkSpeed; /**< Walking speed (pixels/sec) */ | ||
| 578 | /** | ||
| 579 | * Walk speed. | ||
| 580 | * In pixels per second for eAthena, | ||
| 581 | * In tiles per second (0.1 precision) for TMWserv. | ||
| 582 | */ | ||
| 583 | float mWalkSpeed; | ||
| 579 | 584 | ||
| 580 | 585 | Vector mPos; | |
| 581 | 586 | Vector mDest; |
src/game.h
(1 / 0)
|   | |||
| 29 | 29 | extern std::string map_path; | |
| 30 | 30 | extern volatile int fps; | |
| 31 | 31 | extern volatile int tick_time; | |
| 32 | extern const int MILLISECONDS_IN_A_TICK; | ||
| 32 | 33 | ||
| 33 | 34 | class WindowMenu; | |
| 34 | 35 |
src/map.cpp
(5 / 0)
|   | |||
| 41 | 41 | extern volatile int tick_time; | |
| 42 | 42 | ||
| 43 | 43 | /** | |
| 44 | * The used side-length for tiles | ||
| 45 | */ | ||
| 46 | const int DEFAULT_TILE_SIDE_LENGTH = 32; | ||
| 47 | |||
| 48 | /** | ||
| 44 | 49 | * A location on a tile map. Used for pathfinding, open list. | |
| 45 | 50 | */ | |
| 46 | 51 | struct Location |
src/map.h
(2 / 0)
|   | |||
| 43 | 43 | typedef MapSprites::iterator MapSprite; | |
| 44 | 44 | typedef std::vector<MapLayer*> Layers; | |
| 45 | 45 | ||
| 46 | extern const int DEFAULT_TILE_SIDE_LENGTH; | ||
| 47 | |||
| 46 | 48 | /** | |
| 47 | 49 | * A meta tile stores additional information about a location on a tile map. | |
| 48 | 50 | * This is information that doesn't need to be repeated for each tile in each |
|   | |||
| 203 | 203 | } | |
| 204 | 204 | if (speed) | |
| 205 | 205 | { | |
| 206 | /* The speed on the server is the cost of moving from one tile to | ||
| 207 | * the next. Beings get 1000 cost units per second. The speed is | ||
| 208 | * transferred as devided by 10, so that slower speeds fit in a | ||
| 209 | * byte. Here we convert the speed to pixels per second. | ||
| 210 | */ | ||
| 211 | const float tilesPerSecond = 100.0f / speed; | ||
| 212 | being->setWalkSpeed((int) (tilesPerSecond * 32)); | ||
| 206 | // The being's speed is transfered in tiles per second * 10 | ||
| 207 | // to keep it transferable in a Byte. | ||
| 208 | // We set it back to tiles per second and in a float. | ||
| 209 | being->setWalkSpeed((float) speed / 10); | ||
| 213 | 210 | } | |
| 214 | 211 | ||
| 215 | 212 | // Ignore messages from the server for the local player |

