diff options
author | Stijn Buys <ingar@osirion.org> | 2013-11-05 16:42:01 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-11-05 16:42:01 +0000 |
commit | 058f40a2e6dfd7e3498e7506c3ca82606f9b792e (patch) | |
tree | e4920eefb4c3fa1073d6604845724c4f56c23d26 /src/game/base/patrol.cc | |
parent | 9a16c4b433bba4837bc98a90b446aa0726f0d447 (diff) |
Have NPCs get cargo.
Diffstat (limited to 'src/game/base/patrol.cc')
-rw-r--r-- | src/game/base/patrol.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/game/base/patrol.cc b/src/game/base/patrol.cc index 4ad16df..a50abea 100644 --- a/src/game/base/patrol.cc +++ b/src/game/base/patrol.cc @@ -14,11 +14,13 @@ namespace game { Patrol::WayPoint::WayPoint() { waypoint_target = 0; + waypoint_cargo = 0; waypoint_dock = false; } Patrol::WayPoint::~WayPoint() { waypoint_target = 0; + waypoint_cargo = 0; } void Patrol::WayPoint::set_target_label(const std::string &label) @@ -36,9 +38,9 @@ void Patrol::WayPoint::set_dock(const bool dock) waypoint_dock = dock; } -void Patrol::WayPoint::set_buy_label(const std::string &label) +void Patrol::WayPoint::set_cargo(Cargo *cargo) { - waypoint_buy_label.assign(label); + waypoint_cargo = cargo; } /* --- Patrol ------------------------------------------------------ */ @@ -327,11 +329,46 @@ void Patrol::frame(const unsigned long elapsed) if (group_docked) { if (patrol_launch_timeout > 0 ) { 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()) { + + // 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; + } + + } + + 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(); + } + } + 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(30000); |