diff options
Diffstat (limited to 'src/game/base/npc.cc')
| -rw-r--r-- | src/game/base/npc.cc | 44 | 
1 files changed, 40 insertions, 4 deletions
diff --git a/src/game/base/npc.cc b/src/game/base/npc.cc index ca2a1c2..bb716c9 100644 --- a/src/game/base/npc.cc +++ b/src/game/base/npc.cc @@ -65,6 +65,8 @@ NPC *NPC::add_wingman(Ship *leader)  		npc_slot->set_flag(core::Slot::Mounted);  	} +	npc->calculate_weapon_range(); +	  	npc->reset();  	return npc; @@ -77,6 +79,8 @@ NPC::NPC(const ShipModel *shipmodel) : Ship(0, shipmodel)  	npc_patrol = 0;  	npc_leader = 0; +	 +	npc_weapon_range = 0.0f;  }  NPC::~NPC() @@ -86,6 +90,38 @@ NPC::~NPC()  	}  } +void NPC::calculate_weapon_range() +{ +	npc_weapon_range = 0.0f; +	 +	if (!slots()) { +		return; +	} +	 +	for (core::Slots::const_iterator it = slots()->begin(); it != slots()->end(); it++) { +		core::Slot *slot = (*it); +		 +		if (!slot->has_flag(core::Slot::Mounted)) { +			continue; +				 +		} else if (!slot->item() || (slot->item()->info()->type() != Weapon::infotype())) { +			continue; +				 +		} else { +			const Weapon *weapon = static_cast<const Weapon *>(slot->item()->info()); +				 +			if ((weapon->subtype() != Weapon::Cannon) && (weapon->subtype() != Weapon::Turret) ) { +				continue; +			} +			const float r = weapon->projectile_range(); +			 +			if (r > npc_weapon_range) { +				npc_weapon_range = r; +			} +		} +	} +} +  void NPC::set_mood(const Mood mood)  {  	npc_mood = mood; @@ -107,6 +143,9 @@ Ship *NPC::target_closest_enemy()  	Ship *current_enemy = 0;  	float current_distance = 0.0f; +	if (!npc_weapon_range) { +		return 0; +	}  	for (core::Zone::Content::iterator zit = zone()->content().begin(); zit != zone()->content().end(); ++zit) {  		if (((*zit)->moduletype() == ship_enttype) && ((*zit) != this)) { @@ -149,11 +188,8 @@ Ship *NPC::target_closest_enemy()  		}  	} -	// FIXME calculate weaposn range, arbitrarily set to 10 km -	const float weapons_range = COMBAT_DISTANCE; -	  	// set aim -	if ((state() == Normal) && current_enemy && (current_distance <= weapons_range)) { +	if ((state() == Normal) && current_enemy && (current_distance <= radius() + npc_weapon_range)) {  		// activate weapons  		set_target_controlflag(core::EntityControlable::ControlFlagFire);  		// rudimentary aim currention  | 
