Tuning of secondary/light color and armor
This commit is contained in:
parent
3168f7b5db
commit
e270d4749e
@ -76,17 +76,17 @@ void game::Vehicle::OnContact(const collision::ContactInfo& info)
|
||||
if (info.impulse < 1000.0f)
|
||||
return;
|
||||
|
||||
if (window_health_ > 0.0f)
|
||||
if (health_ > 0.0f)
|
||||
{
|
||||
window_health_ -= info.impulse;
|
||||
health_ -= info.impulse;
|
||||
|
||||
if (window_health_ <= 0.0f) // just broken
|
||||
if (health_ <= 0.0f) // just broken
|
||||
{
|
||||
PlaySound("breakwindow", 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if (window_health_ <= 0.0f)
|
||||
if (health_ <= 0.0f)
|
||||
{
|
||||
Deform(info.pos, -glm::normalize(info.normal) * 0.1f, 1.0f);
|
||||
}
|
||||
@ -343,7 +343,7 @@ void game::Vehicle::ProcessInput()
|
||||
|
||||
void game::Vehicle::UpdateCrash()
|
||||
{
|
||||
if (window_health_ <= 0.0f)
|
||||
if (health_ <= 0.0f)
|
||||
flags_ |= VF_BROKENWINDOWS;
|
||||
|
||||
if (no_crash_frames_)
|
||||
@ -592,6 +592,13 @@ void game::Vehicle::ApplyTuning(const VehicleTuning& tuning)
|
||||
}
|
||||
}
|
||||
|
||||
if (tuning_ctx_.colors[2] == 0) // secondary <- primary
|
||||
{
|
||||
tuning_ctx_.colors[2] = tuning_ctx_.colors[0];
|
||||
}
|
||||
|
||||
health_ = tuning_ctx_.health;
|
||||
|
||||
// (re)create physics
|
||||
physics_.reset();
|
||||
physics_ = std::make_unique<VehiclePhysics>(world_, root_.local, *this, *model_, tuning_ctx_);
|
||||
|
||||
@ -129,7 +129,7 @@ private:
|
||||
|
||||
VehicleInputFlags in_ = 0;
|
||||
|
||||
float window_health_ = 10000.0f;
|
||||
float health_ = 10000.0f;
|
||||
|
||||
float crash_intensity_ = 0.0f;
|
||||
size_t no_crash_frames_ = 0;
|
||||
|
||||
@ -12,6 +12,8 @@ static float game::VehicleTuningContext::* GetCtxVariablePointer(const std::stri
|
||||
return &game::VehicleTuningContext::engine_force;
|
||||
if (name == "braking_force")
|
||||
return &game::VehicleTuningContext::braking_force;
|
||||
if (name == "health")
|
||||
return &game::VehicleTuningContext::health;
|
||||
|
||||
throw std::runtime_error("tuning list: invalid variable " + name);
|
||||
}
|
||||
@ -69,7 +71,7 @@ static bool CheckWheelCond(const game::VehicleWheelTuningContext& wheel_ctx, con
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t ParseColor(uint32_t c)
|
||||
static uint32_t FlipColor(uint32_t c)
|
||||
{
|
||||
auto r = (c >> 16) & 0xFF;
|
||||
auto g = (c >> 8) & 0xFF;
|
||||
@ -77,6 +79,30 @@ static uint32_t ParseColor(uint32_t c)
|
||||
return 0xFF000000 | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
static uint32_t ParseColor(const std::string& color_str)
|
||||
{
|
||||
if (color_str == "none")
|
||||
return 0;
|
||||
|
||||
uint32_t color = 0;
|
||||
|
||||
for (const auto& c : color_str)
|
||||
{
|
||||
uint32_t v = 0;
|
||||
color <<= 4;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
color += c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
color += c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
color += c - 'A' + 10;
|
||||
|
||||
}
|
||||
|
||||
return FlipColor(color);
|
||||
}
|
||||
|
||||
static game::VehicleTuningFunction ParseTuningFunction(std::istringstream& iss)
|
||||
{
|
||||
std::string func_name;
|
||||
@ -98,12 +124,13 @@ static game::VehicleTuningFunction ParseTuningFunction(std::istringstream& iss)
|
||||
{
|
||||
size_t color_idx;
|
||||
uint32_t color;
|
||||
iss >> color_idx >> std::hex >> color >> std::dec;
|
||||
std::string color_str;
|
||||
iss >> color_idx >> color_str;
|
||||
|
||||
if (color_idx >= 4)
|
||||
throw std::runtime_error("tuning list: invalid color index");
|
||||
|
||||
color = ParseColor(color);
|
||||
color = ParseColor(color_str);
|
||||
|
||||
return [color_idx, color](game::VehicleTuningContext& ctx) {
|
||||
ctx.colors[color_idx] = color;
|
||||
|
||||
@ -34,6 +34,7 @@ struct VehicleTuningContext
|
||||
float mass;
|
||||
float engine_force;
|
||||
float braking_force;
|
||||
float health;
|
||||
std::vector<VehicleWheelTuningContext> wheels;
|
||||
};
|
||||
|
||||
|
||||
@ -168,7 +168,7 @@ void game::view::VehicleView::Draw(const DrawArgs& args)
|
||||
{
|
||||
// light
|
||||
auto light_pos = world_.CameraSweep(root_.GetGlobalPosition(), root_.matrix * glm::vec4(0.0f, 7.0f, 0.0f, 1.0f));
|
||||
args.dlist.AddLight(light_pos, glm::vec3(1.0f, 1.0f, 1.0f) * headlights_factor_, 5.0f);
|
||||
args.dlist.AddLight(light_pos, headlight_color_ * headlights_factor_, 5.0f);
|
||||
|
||||
// cones
|
||||
for (size_t i = 0; i < num_headlights; ++i)
|
||||
@ -244,7 +244,8 @@ bool game::view::VehicleView::ReadTuning(net::InMessage& msg)
|
||||
}
|
||||
|
||||
colors_[VCS_PRIMARY] = recv_colors[0]; // primary
|
||||
colors_[VCS_SECONDARY] = recv_colors[0]; // secondary
|
||||
colors_[VCS_SECONDARY] = recv_colors[2]; // secondary
|
||||
headlight_color_ = recv_colors[3];
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -411,7 +412,7 @@ void game::view::VehicleView::UpdateLights(float delta_t)
|
||||
MoveToward(orange_lights_factor_, (flags_ & VF_ORANGE_LIGHTS_ON) ? 1.0f : 0.0f, max_delta);
|
||||
MoveToward(reverse_light_factor_, (flags_ & VF_REVERSING) ? 1.0f : 0.0f, max_delta);
|
||||
|
||||
colors_[VCS_HEADLIGHTS] = glm::vec4(1.0f, 1.0f, 1.0f, headlights_factor_);
|
||||
colors_[VCS_HEADLIGHTS] = glm::vec4(headlight_color_, headlights_factor_);
|
||||
colors_[VCS_REAR_LIGHTS] = glm::vec4(1.0f, 1.0f, 1.0f, headlights_factor_ * 0.5f + braking_lights_factor_ * 1.0f);
|
||||
colors_[VCS_BRAKING_LIGHTS] = glm::vec4(1.0f, 1.0f, 1.0f, braking_lights_factor_);
|
||||
colors_[VCS_ORANGE_LIGHTS] = glm::vec4(1.0f, 1.0f, 1.0f, orange_lights_factor_);
|
||||
@ -420,8 +421,8 @@ void game::view::VehicleView::UpdateLights(float delta_t)
|
||||
if (headlights_factor_ < 0.01f)
|
||||
return;
|
||||
|
||||
float intensity = headlights_factor_ * 0.2f;
|
||||
headlight_cone_color_ = glm::vec4(intensity, intensity, intensity, 1.0f);
|
||||
float intensity = headlights_factor_ * 0.3f;
|
||||
headlight_cone_color_ = glm::vec4(headlight_color_ * intensity, 1.0f);
|
||||
|
||||
for (size_t i = 0; i < num_headlights; ++i)
|
||||
{
|
||||
|
||||
@ -74,6 +74,7 @@ private:
|
||||
std::shared_ptr<const assets::VehicleModel> model_;
|
||||
assets::Mesh mesh_;
|
||||
glm::vec4 colors_[SD_MAX_COLORS];
|
||||
glm::vec3 headlight_color_;
|
||||
|
||||
game::VehicleSyncState sync_;
|
||||
std::vector<VehicleWheelViewInfo> wheels_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user