Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/patrol.cc')
-rw-r--r--src/game/base/patrol.cc173
1 files changed, 173 insertions, 0 deletions
diff --git a/src/game/base/patrol.cc b/src/game/base/patrol.cc
new file mode 100644
index 0000000..db13260
--- /dev/null
+++ b/src/game/base/patrol.cc
@@ -0,0 +1,173 @@
+/*
+ base/patrol.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "base/patrol.h"
+#include "base/game.h"
+
+namespace game {
+
+/* --- WayPoint atrol ------------------------------------------------------ */
+
+Patrol::WayPoint::WayPoint() {
+ waypoint_target = 0;
+ waypoint_dock = false;
+}
+
+Patrol::WayPoint::~WayPoint() {
+ waypoint_target = 0;
+}
+
+void Patrol::WayPoint::set_target_label(const std::string &label)
+{
+ waypoint_target_label.assign(label);
+}
+
+void Patrol::WayPoint::set_target(core::Entity *entity)
+{
+ waypoint_target = entity;
+}
+
+void Patrol::WayPoint::set_dock(const bool dock)
+{
+ waypoint_dock = dock;
+}
+
+void Patrol::WayPoint::set_buy_label(const std::string &label)
+{
+ waypoint_buy_label.assign(label);
+}
+
+/* --- Patrol ------------------------------------------------------ */
+
+Patrol::Patrol() : core::Entity()
+{
+ // this is a server-side only entity
+ set_serverside(true);
+
+ unset_flag(core::Entity::ShowOnMap);
+ set_flag(core::Entity::NonSolid);
+
+ entity_moduletypeid = patrol_enttype;
+
+ set_label("patrol");
+ set_radius(1.0f);
+
+ patrol_profile = NPC::ProfilePatrol;
+}
+
+
+Patrol::~Patrol()
+{
+ for (WayPoints::iterator it = patrol_waypoints.begin(); it != patrol_waypoints.end(); ++it) {
+ delete (*it);
+ (*it) = 0;
+ }
+ patrol_waypoints.clear();
+}
+
+void Patrol::set_profile(const NPC::Profile profile)
+{
+ patrol_profile = profile;
+}
+
+void Patrol::validate()
+{
+ int waypoint_counter = 1;
+
+ for (WayPoints::iterator it = patrol_waypoints.begin(); it != patrol_waypoints.end(); ++it) {
+ WayPoint *waypoint = (*it);
+
+ if (waypoint->target_label().size() == 0) {
+ con_warn << " Patrol '" << label() << "' WayPoint " << waypoint_counter << " has no target" << "'\n";
+ break;
+ }
+
+ std::string entitylabel;
+ std::string zonelabel;
+
+ core::Zone *targetzone = 0;
+
+ size_t pos = waypoint->target_label().find(':');
+ if ((pos == std::string::npos) || (pos < 1) || (pos >= (waypoint->target_label().size() - 1))) {
+ targetzone = zone();
+
+ zonelabel.assign(zone()->label());
+ entitylabel.assign(waypoint->target_label());
+ } else {
+ zonelabel.assign(waypoint->target_label().substr(0, pos));
+ entitylabel.assign(waypoint->target_label().substr(pos + 1, waypoint->target_label().size() - pos));
+
+ core::Zone::find(zonelabel);
+ if (!targetzone) {
+ con_warn << " Patrol '" << label() << "' waypoint " << waypoint_counter << " has invalid target zone '" << zonelabel << "'\n";
+ break;
+ }
+ }
+
+ core::Entity *targetentity = targetzone->find_entity(entitylabel);
+ if (!targetentity) {
+ con_warn << " Patrol '" << label() << "' waypoint " << waypoint_counter << " has unknown target '" << entitylabel << "' in zone '" << zonelabel << "'\n";
+ break;
+ }
+
+ if(waypoint->dock() && !targetentity->has_flag(core::Entity::Dockable)) {
+ con_warn << " Patrol '" << label() << "' waypoint " << waypoint_counter << " set to dock at non-doackable target '" << entitylabel << "' in zone '" << zonelabel << "'\n";
+ }
+
+ waypoint->set_target(targetentity);
+ }
+
+ // remove invalid waypoints
+ for (WayPoints::iterator it = patrol_waypoints.begin(); it != patrol_waypoints.end(); ) {
+ WayPoint *waypoint = (*it);
+
+ if (!waypoint->target()) {
+ delete waypoint;
+ (*it) = 0;
+
+ patrol_waypoints.erase(it++);
+ } else {
+ ++it;
+ }
+ }
+
+ size_t nbships = 0;
+ for (core::Inventory::Items::const_iterator it = inventory()->items().begin(); it != inventory()->items().end(); it++) {
+ core::Item *item = (*it);
+
+ if (item->info()->type() == ShipModel::infotype()) {
+ nbships++;
+ }
+ }
+
+ if (patrol_waypoints.size() == 0) {
+ con_warn << " Patrol '" << label() << "' without waypoints" << "\n";
+ die();
+
+ } else if (nbships == 0) {
+ con_warn << " Patrol '" << label() << "' without ship types" << "\n";
+ die();
+
+ } else {
+ con_debug << " " << label() << " patrol with " << patrol_waypoints.size() << "waypoints" << " and " << nbships << " ship " << aux::plural("type", nbships) << std::endl;
+ }
+}
+
+Patrol::WayPoint *Patrol::add_waypoint()
+{
+ WayPoint *waypoint = new WayPoint();
+
+ patrol_waypoints.push_back(waypoint);
+
+ return waypoint;
+}
+
+void Patrol::frame(const unsigned long elapsed)
+{
+
+}
+
+}