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-11-04 21:42:11 +0000
committerStijn Buys <ingar@osirion.org>2013-11-04 21:42:11 +0000
commit7ce66c80d6f601c75560ecf113a0820b378c9374 (patch)
tree78eda547578c91355f4c0dc2d9ab9fc8db4fce83
parenta045ea4846861404ee26c0d077ea639c1987a8cb (diff)
Do not spawn patrols in zones without players,
apply faction colors to patrol ships.
-rw-r--r--src/game/base/game.cc2
-rw-r--r--src/game/base/patrol.cc145
-rw-r--r--src/game/base/patrol.h16
3 files changed, 104 insertions, 59 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 0bdf2cc..b3fb415 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -2197,7 +2197,7 @@ bool Game::load_zone(core::Zone *zone)
if (!faction) {
zoneini.unknown_error("unknown faction '" + strval + "'");
} else {
- faction->apply(patrol);
+ patrol->set_faction(faction);
}
} else {
zoneini.unknown_key();
diff --git a/src/game/base/patrol.cc b/src/game/base/patrol.cc
index 27bb6a3..52944de 100644
--- a/src/game/base/patrol.cc
+++ b/src/game/base/patrol.cc
@@ -4,11 +4,12 @@
the terms of the GNU General Public License version 2
*/
+#include "core/gameserver.h"
#include "base/patrol.h"
#include "base/game.h"
namespace game {
-
+
/* --- WayPoint atrol ------------------------------------------------------ */
Patrol::WayPoint::WayPoint() {
@@ -57,9 +58,13 @@ Patrol::Patrol() : core::Entity()
patrol_leader = 0;
+ patrol_faction = 0;
+
patrol_profile = NPC::ProfilePatrol;
patrol_waypoint_current == patrol_waypoints.end();
+
+ patrol_launch_timeout = 0;
}
@@ -89,6 +94,15 @@ void Patrol::set_profile(const NPC::Profile profile)
patrol_profile = profile;
}
+void Patrol::set_faction(Faction *faction)
+{
+ patrol_faction = faction;
+
+ if (patrol_faction) {
+ patrol_faction->apply(this);
+ }
+}
+
void Patrol::validate()
{
int waypoint_counter = 1;
@@ -233,77 +247,94 @@ void Patrol::frame(const unsigned long elapsed)
}
if (patrol_members.size() == 0) {
- // there are no members, verify if the spawn zone has players in it and create a new patrol
-
- patrol_waypoint_current = patrol_waypoints.begin();
- core::Entity *spawn = waypoint()->target();
+ if (zone()->keepalive_run()) {
+ // there are no members, verify if the spawn zone has players in it and create a new patrol
- if (spawn->has_flag(core::Entity::Dockable)) {
-
- 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()) {
- continue;
- }
-
- // find shipmodel
- ShipModel *shipmodel = ShipModel::find(item->info()->label());
- if (!shipmodel) {
- continue;
- }
-
- // add NPC
- NPC *npc = new NPC(patrol_profile, shipmodel);
+ patrol_waypoint_current = patrol_waypoints.begin();
+ core::Entity *spawn = waypoint()->target();
- // set NPC name
- if (shipmodel->npc_name().size()) {
- npc->set_name(shipmodel->npc_name());
- }
-
- // patrol ships are not dockable
- if (npc->has_flag(core::Entity::Dockable)) {
- unset_flag(core::Entity::Dockable);
- // delete menus
- for (Menus::iterator mit = npc->menus().begin(); mit != npc->menus().end(); mit++) {
- delete (*mit);
- (*mit) = 0;
+ if (spawn->has_flag(core::Entity::Dockable)) {
+
+ 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()) {
+ continue;
+ }
+
+ // find shipmodel
+ ShipModel *shipmodel = ShipModel::find(item->info()->label());
+ if (!shipmodel) {
+ continue;
}
- npc->menus().clear();
+
+ // add NPC
+ NPC *npc = new NPC(patrol_profile, shipmodel);
+
+ // set NPC name
+ if (shipmodel->npc_name().size()) {
+ npc->set_name(shipmodel->npc_name());
+ }
+
+ // set NPC color
+ if (faction()) {
+ faction()->apply(npc);
+ }
+
+ // patrol ships are not dockable
+ if (npc->has_flag(core::Entity::Dockable)) {
+ unset_flag(core::Entity::Dockable);
+ // delete menus
+ for (Menus::iterator mit = npc->menus().begin(); mit != npc->menus().end(); mit++) {
+ delete (*mit);
+ (*mit) = 0;
+ }
+ npc->menus().clear();
+ }
+
+ // dock npc at spawn
+ npc->set_zone(spawn->zone());
+ npc->set_dock(spawn);
+
+ // add NPC to patrol
+ add_member(npc);
}
- // dock npc at spawn
- npc->set_zone(spawn->zone());
- npc->set_dock(spawn);
-
- // add NPC to patrol
- add_member(npc);
+ set_leader();
}
-
- set_leader();
}
-
} else if (patrol_leader) {
if (patrol_leader->state() == core::Entity::Docked) {
if (patrol_leader->dock() == waypoint()->target()) {
- // verify everyone in the patrol is docked
- bool group_docked = true;
- for (Members::iterator it = patrol_members.begin(); it != patrol_members.end(); ++it) {
- if ((*it)->state() != core::Entity::Docked) {
- group_docked = false;
+ if (zone()->keepalive_run()) {
+
+ // verify everyone in the patrol is docked
+ bool group_docked = true;
+ for (Members::iterator it = patrol_members.begin(); it != patrol_members.end(); ++it) {
+ if ((*it)->state() != core::Entity::Docked) {
+ group_docked = false;
+ }
}
- }
-
- // next waypoint
- if (group_docked) {
- patrol_waypoint_current++;
- if (patrol_waypoint_current == patrol_waypoints.end()) {
- patrol_waypoint_current = patrol_waypoints.begin();
+
+ // next waypoint
+ if (group_docked) {
+ if (patrol_launch_timeout > 0 ) {
+ if (core::server()->timestamp() > patrol_launch_timeout) {
+ patrol_waypoint_current++;
+ if (patrol_waypoint_current == patrol_waypoints.end()) {
+ patrol_waypoint_current = patrol_waypoints.begin();
+ }
+ patrol_leader->set_autopilot_target(waypoint()->target());
+ }
+ } else {
+ patrol_launch_timeout = core::server()->timestamp() + 15000 + (unsigned long) math::randomi(15000);
+ }
+ } else {
+ patrol_launch_timeout = 0;
}
- patrol_leader->set_autopilot_target(waypoint()->target());
}
} else {
diff --git a/src/game/base/patrol.h b/src/game/base/patrol.h
index a747a89..debd0e4 100644
--- a/src/game/base/patrol.h
+++ b/src/game/base/patrol.h
@@ -84,16 +84,26 @@ public:
return patrol_profile;
}
- inline WayPoint * waypoint() {
+ inline WayPoint * waypoint() const {
if (patrol_waypoint_current == patrol_waypoints.end()) {
return 0;
} else {
return (*patrol_waypoint_current);
}
}
+
+ inline NPC *leader() const {
+ return patrol_leader;
+ }
+
+ inline Faction *faction() const {
+ return patrol_faction;
+ }
void set_profile(const NPC::Profile profile);
+ void set_faction(Faction *faction);
+
WayPoint *add_waypoint();
virtual void validate();
@@ -116,6 +126,10 @@ private:
NPC::Profile patrol_profile;
NPC *patrol_leader;
+
+ unsigned long patrol_launch_timeout;
+
+ Faction *patrol_faction;
};
} // namespace game