ticks
This commit is contained in:
@@ -12,7 +12,8 @@ Unit::Unit(int uId, int pId, const UnitConfig &cfg, int startX, int startY, floa
|
||||
buildCharges(cfg.buildCharges),
|
||||
state(UnitState::Idle), pathIndex(0), moveProgress(0.0f),
|
||||
targetTileX(startX), targetTileY(startY), attackFlashTimer(0.0f), rechargeTimer(0.0f),
|
||||
buildProgress(0.0f), buildDuration(0.0f), buildingImprovementId("")
|
||||
buildProgress(0.0f), buildDuration(0.0f), buildingImprovementId(""),
|
||||
movement_tick_duration(30.0f) // Default: 30 seconds per tick at 1x speed
|
||||
{
|
||||
QVector2D w = Pathfinder::hexToWorld(startX, startY);
|
||||
worldPos = QVector3D(w.x(), w.y(), groundZ);
|
||||
@@ -43,8 +44,8 @@ void Unit::performAttack(Unit &target)
|
||||
{
|
||||
if (!canAttack(target)) return;
|
||||
|
||||
attackFlashTimer = config.attackFlashDuration / 1000.0f; // Convert ms to seconds
|
||||
rechargeTimer = config.rechargeTime / 1000.0f; // Convert ms to seconds
|
||||
attackFlashTimer = config.attackFlashTicks * movement_tick_duration; // Convert ticks to seconds
|
||||
rechargeTimer = config.rechargeTicks * movement_tick_duration; // Convert ticks to seconds
|
||||
|
||||
target.takeDamage((float)config.attackDamage);
|
||||
|
||||
@@ -60,8 +61,8 @@ void Unit::performAttack(Unit &target)
|
||||
void Unit::takeDamage(float damage)
|
||||
{
|
||||
health = std::max(0.0f, health - damage);
|
||||
attackFlashTimer = 0.4f;
|
||||
rechargeTimer = config.rechargeTime / 1000.0f; // Reset recharge on taking damage
|
||||
attackFlashTimer = movement_tick_duration; // Flash lasts 1 tick
|
||||
rechargeTimer = config.rechargeTicks * movement_tick_duration; // Reset recharge to full duration
|
||||
}
|
||||
|
||||
float Unit::getTerrainHeight(float worldX, float worldY, Matrix2D<TerrainPoint> *mapPoints, int numPoints05)
|
||||
@@ -247,8 +248,10 @@ void Unit::update(float deltaTime, float tickDuration, float simSpeedMultiplier,
|
||||
}
|
||||
|
||||
// Update recharge timer (cooldown between attacks)
|
||||
// Recharge decays based on simulation ticks, not real-time multiplier
|
||||
if (rechargeTimer > 0.0f) {
|
||||
rechargeTimer = std::max(0.0f, rechargeTimer - deltaTime * simSpeedMultiplier);
|
||||
float tickDurationSec = deltaTime / movement_tick_duration;
|
||||
rechargeTimer = std::max(0.0f, rechargeTimer - tickDurationSec);
|
||||
}
|
||||
|
||||
if (state == UnitState::Building) {
|
||||
|
||||
Reference in New Issue
Block a user