Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-01-06 16:42:04 +0000
committerStijn Buys <ingar@osirion.org>2013-01-06 16:42:04 +0000
commitfdbfbbaf4fdee153fd087cba65305b0756550bbb (patch)
tree37d3e768fd3ac4463c253b5b950bab4abd8a69fa /src/client/targets.cc
parentcf8ab544bcb394e71486a616d7e1efc35d0a26a0 (diff)
Added engine functions to target controlables only, bound to the 'X' key by default.
Diffstat (limited to 'src/client/targets.cc')
-rw-r--r--src/client/targets.cc153
1 files changed, 146 insertions, 7 deletions
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()