From 1c9a974d65db676a61ae99e6e426e95671af056e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 5 Nov 2013 11:09:32 +0000 Subject: Completed support for the 'amount' key in patrol ship definitions. --- src/game/base/patrol.cc | 61 ++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'src/game/base/patrol.cc') diff --git a/src/game/base/patrol.cc b/src/game/base/patrol.cc index 52944de..48f687e 100644 --- a/src/game/base/patrol.cc +++ b/src/game/base/patrol.cc @@ -268,36 +268,40 @@ void Patrol::frame(const unsigned long elapsed) continue; } - // add NPC - NPC *npc = new NPC(patrol_profile, shipmodel); + const size_t nbships = 1 + math::randomi(item->amount()); + for (size_t i = 0; i < nbships; i++) { - // 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; + // 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); } - npc->menus().clear(); + + // 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(); @@ -330,7 +334,7 @@ void Patrol::frame(const unsigned long elapsed) patrol_leader->set_autopilot_target(waypoint()->target()); } } else { - patrol_launch_timeout = core::server()->timestamp() + 15000 + (unsigned long) math::randomi(15000); + patrol_launch_timeout = core::server()->timestamp() + 15000 + (unsigned long) math::randomi(30000); } } else { patrol_launch_timeout = 0; @@ -338,7 +342,6 @@ void Patrol::frame(const unsigned long elapsed) } } else { - patrol_leader->launch(); } -- cgit v1.2.3