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/game/base/patrol.cc71
1 files changed, 44 insertions, 27 deletions
diff --git a/src/game/base/patrol.cc b/src/game/base/patrol.cc
index a50abea..c612d49 100644
--- a/src/game/base/patrol.cc
+++ b/src/game/base/patrol.cc
@@ -190,9 +190,13 @@ void Patrol::validate()
// spawn waypoint is dockable
(*patrol_waypoints.begin())->set_dock(true);
+ // spawn waypoint is current
+ patrol_waypoint_current = patrol_waypoints.begin();
+
con_debug << " " << label() << " patrol " << patrol_waypoints.size() << " " << aux::plural("waypoint", patrol_waypoints.size()) << " "
<< nbships << " ship " << aux::plural("type", nbships) << std::endl;
}
+
}
Patrol::WayPoint *Patrol::add_waypoint()
@@ -252,11 +256,15 @@ void Patrol::frame(const unsigned long elapsed)
if (zone()->keepalive_run()) {
// there are no members, verify if the spawn zone has players in it and create a new patrol
- patrol_waypoint_current = patrol_waypoints.begin();
+ if (patrol_waypoint_current == patrol_waypoints.end()) {
+ patrol_waypoint_current = patrol_waypoints.begin();
+ }
+
core::Entity *spawn = waypoint()->target();
if (spawn->has_flag(core::Entity::Dockable)) {
-
+
+ // create NPC members for every ship in the patrol's inventory
for (core::Inventory::Items::const_iterator it = inventory()->items().begin(); it != inventory()->items().end(); it++) {
core::Item *item = (*it);
@@ -307,6 +315,8 @@ void Patrol::frame(const unsigned long elapsed)
}
set_leader();
+
+ patrol_launch_timeout = core::server()->timestamp() + 15000 + (unsigned long) math::randomi(30000);
}
}
} else if (patrol_leader) {
@@ -318,7 +328,7 @@ void Patrol::frame(const unsigned long elapsed)
if (zone()->keepalive_run()) {
// verify everyone in the patrol is docked
- bool group_docked = true;
+ 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;
@@ -327,39 +337,41 @@ void Patrol::frame(const unsigned long elapsed)
// next waypoint
if (group_docked) {
+
if (patrol_launch_timeout > 0 ) {
+
+ // patrol was created, wait for it to launch
if (core::server()->timestamp() > patrol_launch_timeout) {
// launch everyone
for (Members::iterator mit = patrol_members.begin(); mit != patrol_members.end(); ++mit) {
NPC *member = (*mit);
- if (member->state() == core::Entity::Docked) {
- // buy cargo if requested
- if (waypoint()->dock() && waypoint()->cargo() && member->inventory()) {
+ // buy cargo if requested
+ if (waypoint()->dock() && waypoint()->cargo() && member->inventory()) {
+
+ // erase all cargo from inventory
+ for (core::Inventory::Items::iterator iit = member->inventory()->items().begin(); iit != member->inventory()->items().end(); ) {
- // erase all cargo from inventory
- for (core::Inventory::Items::iterator iit = member->inventory()->items().begin(); iit != member->inventory()->items().end(); ) {
-
- if ((*iit)->info()->type() == Cargo::infotype()) {
- member->inventory()->items().erase(iit++);
- } else {
- ++iit;
- }
-
+ if ((*iit)->info()->type() == Cargo::infotype()) {
+ member->inventory()->items().erase(iit++);
+ } else {
+ ++iit;
}
-
- member->inventory()->recalculate();
-
- core::Item *item = new core::Item(waypoint()->cargo());
- item->set_amount( (long)(member->inventory()->capacity_available() / waypoint()->cargo()->volume()));
- member->inventory()->add(item);
-
- member->inventory()->recalculate();
+
}
- member->launch();
+ member->inventory()->recalculate();
+
+ core::Item *item = new core::Item(waypoint()->cargo());
+ item->set_amount( (long)(member->inventory()->capacity_available() / waypoint()->cargo()->volume()));
+ member->inventory()->add(item);
+
+ member->inventory()->recalculate();
}
+
+ // launch member
+ member->launch();
}
patrol_waypoint_current++;
@@ -368,10 +380,15 @@ void Patrol::frame(const unsigned long elapsed)
}
patrol_leader->set_autopilot_target(waypoint()->target());
-
+ patrol_launch_timeout = 0;
}
+
} else {
- patrol_launch_timeout = core::server()->timestamp() + 15000 + (unsigned long) math::randomi(30000);
+ // reset patrol
+ for (Members::iterator mit = patrol_members.begin(); mit != patrol_members.end(); ++mit) {
+ NPC *member = (*mit);
+ member->die();
+ }
}
} else {
patrol_launch_timeout = 0;
@@ -384,7 +401,7 @@ void Patrol::frame(const unsigned long elapsed)
} else if ((patrol_leader->state() == core::Entity::Normal) || (patrol_leader->state() == core::Entity::ImpulseInitiate) || (patrol_leader->state() == core::Entity::Impulse)) {
- patrol_launch_timeout = 0;
+// patrol_launch_timeout = 0;
if (waypoint()->target()->zone() == patrol_leader->zone()) {