コード例 #1
0
ファイル: worldgen.py プロジェクト: penny64/r3-tdw
def create_factions():
	_ownable_spots = [p for p in world_strategy.MAP['grid'].keys() if world_strategy.MAP['grid'][p]['is_ownable'] and not world_strategy.MAP['grid'][p]['owned_by']]
	
	for faction_name in ['Rogues', 'Terrorists']:
		_plot_pos = _ownable_spots.pop(0)
		_plot = world_strategy.MAP['grid'][_plot_pos]
		_squad = ai_squads.create_human_squad(faction_name, _plot_pos[0], _plot_pos[1])
		_plot['owned_by'] = faction_name
		
		if faction_name == 'Rogues':
			entities.register_event(_squad, 'raid', lambda e, **kwargs: world_strategy.news('Order: Squad %s is raiding %s, %s.' % (e['squad_id'], _plot_pos[0], _plot_pos[1]),
			                                                                                fore_color=(200, 40, 40)))
			entities.register_event(_squad, 'position_changed', lambda e, **kwargs: _handle_squad_position_update(e))
		
		for i in range(3):
			if faction_name == 'Rogues':
				if i == 0:
					_e = life.engineer(30 + i * 2, 7, 'Good Dude %i' % i, faction_name, is_player=True)
				else:
					continue
					#_e = life.turret(30, 7 + i * 2, 'Turret %i' % i, faction_name)
					#_e = life.engineer(30 + i * 2, 17, 'Good Dude %i' % i, faction_name)
			
			else:
				if random.randint(0, 1):
					#_e = life.sniper(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name)
					#_e = life.turret(10, 70 + i * 2, 'Turret', faction_name)
					#_e = life.engineer(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name)
					_e = life.grenadier(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name)
				
				else:
					_e = life.grenadier(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name)
					#_e = life.turret(10, 70 + i * 2, 'Turret', faction_name)
	
			ai_squads.register_with_squad(_e, _squad['squad_id'])
コード例 #2
0
ファイル: worldgen.py プロジェクト: penny64/r3-tdw
def _handle_squad_position_update(entity):
	if len(entity['movement']['path']['positions']) == 1:
		world_strategy.news('Alert: Squad %s is arriving at %s, %s.' % (entity['squad_id'],
		                                                                entity['movement']['path']['destination'][0],
		                                                                entity['movement']['path']['destination'][1]),
		                    fore_color=(200, 40, 40), back_color=(80, 0, 0))
	
	elif not len(entity['movement']['path']['positions']):
		_x, _y = movement.get_position(entity)
		_camp = world_strategy.MAP['grid'][_x, _y]
		
		if _camp['owned_by'] and not entity['faction'] == _camp['owned_by']:
			_defending_squads = []
			
			for squad_id in entities.get_entity_group('squads'):
				_squad = entities.get_entity(squad_id)
				
				if _squad['faction'] == _camp['owned_by']:
					_defending_squads.append(squad_id)
			
			world_strategy.unregister_input()
			world_strategy.world_action.start_battle(attacking_squads=[entity['_id']], defending_squads=_defending_squads)