Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/keyboard.cc7
-rw-r--r--src/client/targets.cc153
2 files changed, 150 insertions, 10 deletions
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index baef74c..d5a14ec 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -140,9 +140,10 @@ Keyboard::Keyboard()
add_key("u", SDLK_u, 'u');
key = add_key("v", SDLK_v, 'v', "view_next");
key->assign(Key::Shift, "view_prev");
-
- add_key("w", SDLK_w, 'w', "+afterburner");
- add_key("x", SDLK_x, 'x', "target_center");
+ add_key("w", SDLK_w, 'w', "+afterburner");
+ key = add_key("x", SDLK_x, 'x', "target_controlable_next");
+ key->assign(Key::Shift, "target_controlable_prev");
+ key->assign(Key::Ctrl, "target_center");
add_key("y", SDLK_y, 'y');
add_key("z", SDLK_z, 'z');
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 1e5b831..5ec1abe 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -134,13 +134,15 @@ void func_target_next(std::string const &args)
// first entity
it = zone->content().begin();
- while (!is_valid_hud_target((*it)) && it != zone->content().end())
+ while ((it != zone->content().end()) && !is_valid_hud_target((*it))) {
it++;
+ }
} else {
// current entity
- while (it != zone->content().end() && ((*it)->id() != current_target_id))
+ while ((it != zone->content().end()) && ((*it)->id() != current_target_id)) {
++it;
+ }
// next legal entity
if (it != zone->content().end())
@@ -160,7 +162,7 @@ void func_target_next(std::string const &args)
}
}
- if (it != zone->content().end()) {
+ if (it != zone->content().end() && is_valid_hud_target((*it))) {
set_target((*it));
} else {
current_target = 0;
@@ -187,12 +189,14 @@ void func_target_prev(std::string const &args)
if (!current_target_id) {
// last entity
rit = zone->content().rbegin();
- while (!is_valid_hud_target((*rit)) && rit != zone->content().rend())
- rit++;
+ while ((rit != zone->content().rend()) && !is_valid_hud_target((*rit))) {
+ ++rit;
+ }
} else {
// current entity
- while (rit != zone->content().rend() && ((*rit)->id() != current_target_id))
+ while ((rit != zone->content().rend()) && ((*rit)->id() != current_target_id)) {
++rit;
+ }
// previous legal entity
if (rit != zone->content().rend())
@@ -212,7 +216,7 @@ void func_target_prev(std::string const &args)
}
}
- if (rit != zone->content().rend()) {
+ if (rit != zone->content().rend() && is_valid_hud_target((*rit))) {
set_target((*rit));
} else {
current_target = 0;
@@ -220,6 +224,133 @@ void func_target_prev(std::string const &args)
}
}
+void func_target_controlable_next(std::string const &args)
+{
+ if (!core::localcontrol())
+ return;
+ core::Zone *zone = core::localcontrol()->zone();
+ if (!zone)
+ return;
+
+ if (!zone->content().size()) {
+ current_target = 0;
+ current_target_id = 0;
+ return;
+ }
+
+ core::Zone::Content::iterator it = zone->content().begin();
+
+ 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)))) {
+ ++it;
+ }
+
+ if (it == zone->content().end()) {
+ current_target = 0;
+ current_target_id = 0;
+ } else {
+ set_target((*it));
+ }
+
+ return;
+
+ } else {
+ // current entity
+ while (it != zone->content().end() && ((*it)->id() != current_target_id)) {
+ ++it;
+ }
+
+ // next legal entity
+ if (it != zone->content().end())
+ it++;
+ if (it == zone->content().end()) {
+ it = zone->content().begin();
+ }
+ while (!( ((*it)->type() == core::Entity::Controlable) && is_valid_hud_target((*it))) ) {
+ it++;
+ if (it == zone->content().end())
+ it = zone->content().begin();
+
+ if ((*it)->id() == current_target_id) {
+ current_target = (*it);
+ return;
+ }
+ }
+ }
+
+ if ((it != zone->content().end()) && ((*it)->type() == core::Entity::Controlable) && is_valid_hud_target((*it))) {
+ set_target((*it));
+ } else {
+ current_target = 0;
+ current_target_id = 0;
+ }
+}
+
+void func_target_controlable_prev(std::string const &args)
+{
+ if (!core::localcontrol())
+ return;
+ core::Zone *zone = core::localcontrol()->zone();
+ if (!zone)
+ return;
+
+ if (!zone->content().size()) {
+ current_target = 0;
+ current_target_id = 0;
+ return;
+ }
+
+ core::Zone::Content::reverse_iterator rit = zone->content().rbegin();
+ 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)))) {
+ ++rit;
+ }
+
+ if (rit == zone->content().rend()) {
+ current_target = 0;
+ current_target_id = 0;
+ } else {
+ set_target((*rit));
+ }
+
+ return;
+
+ } else {
+ // current entity
+ while (rit != zone->content().rend() && ((*rit)->id() != current_target_id)) {
+ ++rit;
+ }
+
+ // previous legal entity
+ if (rit != zone->content().rend())
+ ++rit;
+ if (rit == zone->content().rend()) {
+ rit = zone->content().rbegin();
+ }
+ while (!(((*rit)->type() == core::Entity::Controlable) && is_valid_hud_target((*rit))) ) {
+ ++rit;
+ if (rit == zone->content().rend())
+ rit = zone->content().rbegin();
+
+ if ((*rit)->id() == current_target_id) {
+ current_target = (*rit);
+ return;
+ }
+ }
+ }
+
+ if ((rit != zone->content().rend()) && ((*rit)->type() == core::Entity::Controlable) && is_valid_hud_target((*rit))) {
+ set_target((*rit));
+ } else {
+ current_target = 0;
+ current_target_id = 0;
+ }
+}
+
void func_target_none(std::string const &args)
{
current_target = 0;
@@ -282,6 +413,12 @@ void init()
core::Func::add("target_center", func_target_center);
func->set_info("select target near center");
+
+ func = core::Func::add("target_controlable_next", func_target_controlable_next);
+ func->set_info("select next controlable target");
+
+ core::Func::add("target_controlable_prev", func_target_controlable_prev);
+ func->set_info("select previous controlable target");
reset();
}
@@ -294,6 +431,8 @@ void shutdown()
core::Func::remove("target_prev");
core::Func::remove("target_none");
core::Func::remove("target_center");
+ core::Func::remove("target_controlable_next");
+ core::Func::remove("target_controlable_next");
}
const math::Vector3f & aim()