From 2218c7094ad6dc40b200274ebffdc9fb4c1a8e0c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 9 Nov 2013 20:15:06 +0000 Subject: Removed shipmodel npcname support, made Patrols load NPC types instead of ship models, replaces patrol [ship] subsection with a [npc] subsection. --- src/game/base/game.cc | 81 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 14 deletions(-) (limited to 'src/game/base/game.cc') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index f2db00c..46151f9 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -1833,6 +1833,7 @@ bool Game::load_zone(core::Zone *zone) Patrol *patrol = 0; Patrol::WayPoint *patrol_waypoint = 0; + NPCType *patrol_npctype = 0; bool b; long l; @@ -1897,18 +1898,31 @@ bool Game::load_zone(core::Zone *zone) patrol->set_zone(zone); patrol_waypoint = 0; + patrol_npctype = 0; } else if (zoneini.got_section("waypoint")) { patrol_waypoint = 0; + patrol_npctype = 0; - if (!entity || !patrol) { + if (!entity || !patrol || (patrol != entity)) { zoneini.unknown_error("waypoint definition without patrol"); } else if ((entity->moduletype() != patrol_enttype)) { zoneini.unknown_error("waypoint definition for invalid entity type"); } else { patrol_waypoint = patrol->add_waypoint(); } - + } else if (zoneini.got_section("npc")) { + patrol_waypoint = 0; + patrol_npctype = 0; + + if (!entity || !patrol || (patrol != entity)) { + zoneini.unknown_error("npc definition without patrol"); + } else if ((entity->moduletype() != patrol_enttype)) { + zoneini.unknown_error("npc definition for invalid entity type"); + } else { + patrol_npctype = patrol->add_npctype(); + } + } else if (zoneini.got_section("planet")) { planet = new Planet(); entity = planet; @@ -1951,7 +1965,7 @@ bool Game::load_zone(core::Zone *zone) if (!entity) { zoneini.unknown_error("ship definition without entity"); - } else if ((entity->moduletype() != planet_enttype) && (entity->moduletype() != station_enttype) && (entity->moduletype() != patrol_enttype)) { + } else if ((entity->moduletype() != planet_enttype) && (entity->moduletype() != station_enttype)) { zoneini.unknown_error("ship definition for invalid entity type"); } else { inventory = entity->inventory(); @@ -2104,7 +2118,7 @@ bool Game::load_zone(core::Zone *zone) } } else if (zoneini.in_section("waypoint")) { - if (!patrol_waypoint) { + if (!patrol || (patrol != entity) || !patrol_waypoint ) { continue; } else if (zoneini.got_key_string("target", strval)) { patrol_waypoint->set_target_label(strval); @@ -2122,6 +2136,52 @@ bool Game::load_zone(core::Zone *zone) } else { zoneini.unknown_key(); } + + } else if (zoneini.in_section("npc")) { + if (!patrol || (patrol != entity) || !patrol_npctype) { + continue; + } else if (zoneini.got_key_string("name", strval)) { + aux::strip_quotes(strval); + patrol_npctype->set_name(strval); + } else if (zoneini.got_key_long("amount", l)) { + patrol_npctype->set_amount(l); + } else if (zoneini.got_key_bool("merchant", b)) { + patrol_npctype->set_merchant(b); + } else if (zoneini.got_key_label("ship", strval)) { + ShipModel *shipmodel = ShipModel::find(strval); + if (!shipmodel) { + zoneini.unknown_error("unknown ship type '" + strval + "'"); + } else { + patrol_npctype->set_shipmodel(shipmodel); + } + } else if (zoneini.got_key_label("faction", strval)) { + Faction *faction = Faction::find(strval); + if (!faction) { + zoneini.unknown_error("unknown faction '" + strval + "'"); + } else { + patrol_npctype->set_faction(faction); + } + } else if (zoneini.got_key_label("cannon", strval)) { + Weapon *cannon = Weapon::find(strval); + if (!cannon) { + zoneini.unknown_error("unknown weapon type '" + strval + "'"); + } else if (cannon->subtype() != Weapon::Cannon) { + zoneini.unknown_error("weapon type '" + strval + "' is not a cannon"); + } else { + patrol_npctype->set_cannon(cannon); + } + } else if (zoneini.got_key_label("turret", strval)) { + Weapon *turret = Weapon::find(strval); + if (!turret) { + zoneini.unknown_error("unknown weapon type '" + strval + "'"); + } else if (turret->subtype() != Weapon::Turret) { + zoneini.unknown_error("weapon type '" + strval + "' is not a turret"); + } else { + patrol_npctype->set_turret(turret); + } + } else { + zoneini.unknown_key(); + } } else if (zoneini.in_section("planet")) { if (core::Parser::got_entity_key(zoneini, planet)) { @@ -2333,21 +2393,14 @@ bool Game::load_zone(core::Zone *zone) if (!item) { item = new core::Item(shipmodel); - if ((entity->moduletype() == patrol_enttype)) { - item->set_amount(1); - } else { - item->set_amount(-1); - } + item->set_amount(-1); item->set_price(shipmodel->price()); inventory->add(item); } } else { zoneini.unknown_error("unknown ship type '" + strval + "'"); } - } else if ((entity->moduletype() == patrol_enttype) && zoneini.got_key_long("amount", l)) { - if (item) { - item->set_amount(l); - } + } else if (zoneini.got_key_long("price", l)) { if (item) { item->set_price(l); @@ -2446,7 +2499,7 @@ bool Game::generate_entity_menus(core::Entity *entity) size_t nbweapon = 0; size_t nbships = 0; - for (core::Inventory::Items::const_iterator it = entity->inventory()->items().begin(); it != entity->inventory()->items().end(); it++) { + for (core::Inventory::Items::const_iterator it = entity->inventory()->items().begin(); it != entity->inventory()->items().end(); ++it) { core::Item *item = (*it); if (item->info()->type() == Cargo::infotype()) { -- cgit v1.2.3