Skip to content

Commit

Permalink
Changed citizen speed values.
Browse files Browse the repository at this point in the history
Using 16 units per frame which converts to 3 1/8 voxels per second. Feels almost too fast but it's the original values.
  • Loading branch information
afritz1 committed Nov 20, 2024
1 parent 489d11d commit 328be49
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions OpenTESArena/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ SET(TES_COLLISION
"${SRC_ROOT}/Collision/SelectionUtils.h")

SET(TES_ENTITIES
"${SRC_ROOT}/Entities/ArenaCitizenUtils.h"
"${SRC_ROOT}/Entities/CharacterClassDefinition.cpp"
"${SRC_ROOT}/Entities/CharacterClassDefinition.h"
"${SRC_ROOT}/Entities/CharacterClassLibrary.cpp"
Expand Down
33 changes: 33 additions & 0 deletions OpenTESArena/src/Entities/ArenaCitizenUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef ARENA_CITIZEN_UTILS_H
#define ARENA_CITIZEN_UTILS_H

#include <cstdint>

#include "../Assets/MIFUtils.h"
#include "../Rendering/ArenaRenderUtils.h"

namespace ArenaCitizenUtils
{
// How far away a citizen will consider idling to the player.
constexpr int IDLE_DISTANCE_UNITS = 200;
constexpr double IDLE_DISTANCE_REAL = static_cast<double>(IDLE_DISTANCE_UNITS) / MIFUtils::ARENA_UNITS;
constexpr double IDLE_DISTANCE_REAL_SQR = IDLE_DISTANCE_REAL * IDLE_DISTANCE_REAL;

constexpr int MOVE_UNITS_PER_FRAME = static_cast<int>(MIFUtils::ARENA_UNITS) / 8;
constexpr int MOVE_UNITS_PER_SECOND = MOVE_UNITS_PER_FRAME * ArenaRenderUtils::FRAMES_PER_SECOND;
constexpr double MOVE_SPEED_PER_SECOND = static_cast<double>(MOVE_UNITS_PER_SECOND) / MIFUtils::ARENA_UNITS;

constexpr int8_t DIRECTION_NORTH = 0;
constexpr int8_t DIRECTION_EAST = 1;
constexpr int8_t DIRECTION_SOUTH = 2;
constexpr int8_t DIRECTION_WEST = 3;
constexpr int8_t DIRECTION_INDICES[] =
{
DIRECTION_NORTH,
DIRECTION_EAST,
DIRECTION_SOUTH,
DIRECTION_WEST
};
}

#endif
12 changes: 0 additions & 12 deletions OpenTESArena/src/Entities/CitizenUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
#include "../Assets/TextureUtils.h"
#include "../World/Coord.h"

class BinaryAssetLibrary;
class EntityChunkManager;
class EntityDefinition;
class LocationDefinition;
class Random;
class VoxelChunk;

enum class CardinalDirectionName;
enum class MapType;
Expand All @@ -25,16 +23,6 @@ namespace CitizenUtils
constexpr int CITIZENS_PER_CHUNK = 30;
constexpr int MAX_ACTIVE_CITIZENS = CITIZENS_PER_CHUNK * 9;

// How far away a citizen will consider idling around the player.
constexpr double IDLE_DISTANCE = 1.25;
constexpr double IDLE_DISTANCE_SQR = IDLE_DISTANCE * IDLE_DISTANCE;

// Walking speed of citizens.
constexpr double SPEED = 2.25;

// North/east/south/west.
constexpr int8_t DIRECTION_INDICES[] = { 0, 1, 2, 3 };

struct CitizenGenInfo
{
EntityDefID maleEntityDefID;
Expand Down
9 changes: 5 additions & 4 deletions OpenTESArena/src/Entities/EntityChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Jolt/Physics/Body/BodyCreationSettings.h"
#include "Jolt/Physics/Collision/Shape/CapsuleShape.h"

#include "ArenaCitizenUtils.h"
#include "EntityChunkManager.h"
#include "EntityDefinitionLibrary.h"
#include "EntityObservedResult.h"
Expand Down Expand Up @@ -508,7 +509,7 @@ void EntityChunkManager::updateCitizenStates(double dt, EntityChunk &entityChunk
int8_t &citizenDirIndex = this->citizenDirectionIndices.get(entityInst.citizenDirectionIndexID);
if (animInst.currentStateIndex == idleStateIndex)
{
const bool shouldChangeToWalking = !isPlayerWeaponSheathed || (distToPlayerSqr > CitizenUtils::IDLE_DISTANCE_SQR) || isPlayerMoving;
const bool shouldChangeToWalking = !isPlayerWeaponSheathed || (distToPlayerSqr > ArenaCitizenUtils::IDLE_DISTANCE_REAL_SQR) || isPlayerMoving;

// @todo: need to preserve their previous direction so they stay aligned with
// the center of the voxel. Basically need to store cardinal direction as internal state.
Expand All @@ -526,7 +527,7 @@ void EntityChunkManager::updateCitizenStates(double dt, EntityChunk &entityChunk
}
else if (animInst.currentStateIndex == walkStateIndex)
{
const bool shouldChangeToIdle = isPlayerWeaponSheathed && (distToPlayerSqr <= CitizenUtils::IDLE_DISTANCE_SQR) && !isPlayerMoving;
const bool shouldChangeToIdle = isPlayerWeaponSheathed && (distToPlayerSqr <= ArenaCitizenUtils::IDLE_DISTANCE_REAL_SQR) && !isPlayerMoving;
if (shouldChangeToIdle)
{
animInst.setStateIndex(*idleStateIndex);
Expand Down Expand Up @@ -583,7 +584,7 @@ void EntityChunkManager::updateCitizenStates(double dt, EntityChunk &entityChunk
const CardinalDirectionName curDirectionName = CardinalDirection::getDirectionName(entityDir);

// Shuffle citizen direction indices so they don't all switch to the same direction every time.
constexpr auto &dirIndices = CitizenUtils::DIRECTION_INDICES;
constexpr auto &dirIndices = ArenaCitizenUtils::DIRECTION_INDICES;
int8_t randomDirectionIndices[std::size(dirIndices)];
std::copy(std::begin(dirIndices), std::end(dirIndices), std::begin(randomDirectionIndices));
RandomUtils::shuffle<int8_t>(randomDirectionIndices, random);
Expand Down Expand Up @@ -621,7 +622,7 @@ void EntityChunkManager::updateCitizenStates(double dt, EntityChunk &entityChunk
}

// Integrate by delta time.
const VoxelDouble2 entityVelocity = entityDir * CitizenUtils::SPEED;
const VoxelDouble2 entityVelocity = entityDir * ArenaCitizenUtils::MOVE_SPEED_PER_SECOND;
entityCoord = ChunkUtils::recalculateCoord(entityCoord.chunk, entityCoord.point + (entityVelocity * dt));

const JPH::BodyID &physicsBodyID = entityInst.physicsBodyID;
Expand Down

0 comments on commit 328be49

Please sign in to comment.