From 82f0ac05f5da2d89c4a544ca22ff47e116e6dd97 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 10 Nov 2013 15:11:49 +0000 Subject: Introduced global variables for reputation hostile/friendly thresholds, do not allow players to dock at hostile bases, indicate target reputation in the hud target info widget. --- src/client/hud.cc | 80 ++++++++++++++++++------------------------- src/client/hudtargetstatus.cc | 25 ++++++++++---- src/client/targets.cc | 37 +++++++++++++++----- 3 files changed, 81 insertions(+), 61 deletions(-) (limited to 'src/client') diff --git a/src/client/hud.cc b/src/client/hud.cc index 1b2ddd8..1fabe10 100644 --- a/src/client/hud.cc +++ b/src/client/hud.cc @@ -6,6 +6,7 @@ #include "core/core.h" +#include "core/range.h" #include "client/client.h" #include "client/hud.h" #include "client/hudenginestatus.h" @@ -144,9 +145,9 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) } // reputation color - if (reputation > 50.0f) { + if (reputation >= core::range::reputation_friendly) { bitmap_color.assign(0.0f, 1.0f, 0.0f); // green - } else if (reputation < -50.0f) { + } else if (reputation <= core::range::reputation_hostile) { bitmap_color.assign(1.0f, 0.0f, 0.0f); // red } else { bitmap_color.assign(1.0f, 1.0f, 1.0f); // white @@ -156,9 +157,9 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) bitmap_material.assign("bitmaps/hud/offscreen_dockable"); // reputation color - if (reputation > 50.0f) { + if (reputation >= core::range::reputation_friendly) { bitmap_color.assign(0.0f, 1.0f, 0.0f); // green - } else if (reputation < -50.0f) { + } else if (reputation <= core::range::reputation_hostile) { bitmap_color.assign(1.0f, 0.0f, 0.0f); // red } else { bitmap_color.assign(1.0f, 1.0f, 1.0f); // white @@ -257,31 +258,24 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) } else { bitmap_material.assign("bitmaps/hud/target_default"); } - - // reputation color - if (reputation > 50.0f) { - bitmap_color.assign(0.0f, 1.0f, 0.0f); // green - } else if (reputation < -50.0f) { - bitmap_color.assign(1.0f, 0.0f, 0.0f); // red - } else { - bitmap_color.assign(1.0f, 1.0f, 1.0f); // white - } + bitmap_color.assign(1.0f, 1.0f, 1.0f); // white } else if (entity->has_flag(core::Entity::Dockable)) { bitmap_material.assign("bitmaps/hud/target_dockable"); - // reputation color - if (reputation > 50.0f) { - bitmap_color.assign(0.0f, 1.0f, 0.0f); // green - } else if (reputation < -50.0f) { - bitmap_color.assign(1.0f, 0.0f, 0.0f); // red - } else { - bitmap_color.assign(1.0f, 1.0f, 1.0f); // white - } - + bitmap_color.assign(1.0f, 1.0f, 1.0f); // white } else { bitmap_material.assign("bitmaps/hud/target_default"); - bitmap_color.assign(palette()->text()); + bitmap_color.assign(palette()->text()); // default text color + } + + // reputation color + if (reputation >= core::range::reputation_friendly) { + // friendly + bitmap_color.assign(0.0f, 1.0f, 0.0f); // green + } else if (reputation <= core::range::reputation_hostile) { + // hostile + bitmap_color.assign(1.0f, 0.0f, 0.0f); // red } if (entity == core::localplayer()->mission_target()) { @@ -309,24 +303,23 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) if (do_draw_label) { // draw name label + std::string label_color; std::string label_text; - if (controlable) { - if (controlable->owner()) { - label_text.append("^B"); - label_text.append(controlable->owner()->name()); - } else { - label_text.append("^N"); - label_text.append(entity->name()); - } + + if (controlable && controlable->owner()) { + label_color.assign("^B"); + } else if (entity->has_flag(core::Entity::Dockable)) { + label_color.assign("^B"); } else { - if (entity->has_flag(core::Entity::Dockable)) { - label_text.append("^B"); - label_text.append(entity->name()); - - } else { - label_text.append("^N"); - label_text.append(entity->name()); - } + label_color.assign("^N"); + } + + label_text.assign(label_color); + + if (controlable && controlable->owner()) { + label_text.append(controlable->owner()->name()); + } else { + label_text.append(entity->name()); } const ui::Font *label_font; @@ -343,14 +336,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) // draw distance label if (is_active_target) { std::ostringstream strdistance; - - if (controlable && controlable->owner()) { - strdistance << "^B"; - } else if (entity->has_flag(core::Entity::Dockable)) { - strdistance << "^B"; - } else { - strdistance << "^N"; - } + strdistance << label_color; float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius(); if (d > 0) { diff --git a/src/client/hudtargetstatus.cc b/src/client/hudtargetstatus.cc index 893d816..77fb60d 100644 --- a/src/client/hudtargetstatus.cc +++ b/src/client/hudtargetstatus.cc @@ -38,26 +38,39 @@ void HUDTargetStatus::draw() pos[1] += padding; math::Vector2f s(width() - 2.0f * padding, height() - 2.0f * padding); - + + // reputation color + std::string label_color; + const float reputation = core::localplayer()->reputation(target->faction()); + + if (reputation >= core::range::reputation_friendly) { + // friendly + label_color.assign("^2"); + } else if (reputation <= core::range::reputation_hostile) { + // hostile + label_color.assign("^1"); + } else { + label_color.assign("^B"); + } std::ostringstream targetinfostr; if (target->type() == core::Entity::Controlable) { const core::EntityControlable *target_controlable = static_cast(target); if (target_controlable->owner()) { - targetinfostr << "^B" << target_controlable->owner()->name() << "\n"; + targetinfostr << label_color << target_controlable->owner()->name() << "\n"; } else { - targetinfostr << "^B" << target->name() << "\n"; + targetinfostr << label_color << target->name() << "\n"; } if (target->info()) { - targetinfostr << "^B" << target->info()->name() << "\n"; + targetinfostr << "^N" << target->info()->name() << "\n"; } else { targetinfostr << "\n"; } } else { - targetinfostr << "^B" << target->name() << "\n"; + targetinfostr << label_color << target->name() << "\n"; if (target->info()) { core::game()->request_info(target->info()->id()); - targetinfostr << "^B" << target->info()->name() << "\n"; + targetinfostr << "^N" << target->info()->name() << "\n"; } else { targetinfostr << "\n"; } diff --git a/src/client/targets.cc b/src/client/targets.cc index 3c3b2b8..088d334 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -243,7 +243,13 @@ void func_target_controlable_next(std::string const &args) if (!current_target_id) { // first entity it = zone->content().begin(); - while ((it != zone->content().end()) && (((*it)->type() != core::Entity::Controlable) || !is_valid_hud_target((*it)))) { + while ( + (it != zone->content().end()) && ( + ((*it)->type() != core::Entity::Controlable) || + (math::distancesquared(core::localcontrol()->location(), (*it)->location()) > core::range::fxdistance * core::range::fxdistance) || + !is_valid_hud_target((*it)) + ) + ) { ++it; } @@ -268,12 +274,12 @@ void func_target_controlable_next(std::string const &args) if (it == zone->content().end()) { it = zone->content().begin(); } - while ( - !( - is_valid_hud_target((*it)) && + while (!( + is_valid_hud_target((*it)) && ((*it)->type() == core::Entity::Controlable) && ((static_cast((*it))->owner() || (math::distancesquared(core::localcontrol()->location(), (*it)->location()) < core::range::fxdistance * core::range::fxdistance))) - )) { + ) + ) { it++; if (it == zone->content().end()) it = zone->content().begin(); @@ -315,7 +321,13 @@ void func_target_controlable_prev(std::string const &args) if (!current_target_id) { // last entity rit = zone->content().rbegin(); - while ((rit != zone->content().rend()) && (((*rit)->type() != core::Entity::Controlable) || !is_valid_hud_target((*rit)))) { + while ( + (rit != zone->content().rend()) && ( + ((*rit)->type() != core::Entity::Controlable) || + (math::distancesquared(core::localcontrol()->location(), (*rit)->location()) > core::range::fxdistance * core::range::fxdistance) || + !is_valid_hud_target((*rit)) + ) + ) { ++rit; } @@ -340,7 +352,12 @@ void func_target_controlable_prev(std::string const &args) if (rit == zone->content().rend()) { rit = zone->content().rbegin(); } - while (!(((*rit)->type() == core::Entity::Controlable) && is_valid_hud_target((*rit))) ) { + while (!( + is_valid_hud_target((*rit)) && + ((*rit)->type() == core::Entity::Controlable) && + ((static_cast((*rit))->owner() || (math::distancesquared(core::localcontrol()->location(), (*rit)->location()) < core::range::fxdistance * core::range::fxdistance))) + ) + ) { ++rit; if (rit == zone->content().rend()) rit = zone->content().rbegin(); @@ -352,7 +369,11 @@ void func_target_controlable_prev(std::string const &args) } } - if ((rit != zone->content().rend()) && ((*rit)->type() == core::Entity::Controlable) && is_valid_hud_target((*rit))) { + if ((rit != zone->content().rend()) && + is_valid_hud_target((*rit)) && + ((*rit)->type() == core::Entity::Controlable) && + ((static_cast((*rit))->owner() || (math::distancesquared(core::localcontrol()->location(), (*rit)->location()) < core::range::fxdistance * core::range::fxdistance))) + ) { set_target((*rit)); } else { current_target = 0; -- cgit v1.2.3