コード例 #1
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def delete_squad_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	# Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of '%s'" % groups['army'])
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	# More handles
	squad_dict		= the_line.the_world.squads()
	squads_lookup	= the_line.the_world.squads_lookup_from_army(the_army.id)
	
	# Can we find the squad?
	if groups['squad'].lower() not in squads_lookup:
		return order_block.fail(results, "there is no squad by the name of '%s' in '%s'" % (groups['squad'], the_army.name))
	else:
		the_squad = squad_dict[squads_lookup[groups['squad'].lower()]]
	
	# Default result
	results = order_block.default_line_results(the_line, "%s could not be deleted from %s because" % (the_squad.name, the_army.name))
	
	# Is the squad empty?
	if the_squad.amount > 0:
		return order_block.fail(results, "%s still has %s men in it" % (the_squad.name, the_squad.amount))
	
	results['queries'].extend(squad_f.make_delete_query(the_squad.id))
	results['results'].append("The squad '%s' was deleted" % the_squad.name)
	
	return order_block.success(results)
コード例 #2
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def rename_army_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	# Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of '%s'" % groups['army'])
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	# Default result
	results = order_block.default_line_results(the_line, "%s could not be renamed to %s because" % (the_army.name, groups['new_name']))
	
	# Lets check this army doesn't exist already
	if groups['new_name'].lower() in armies_lookup:
		return order_block.fail(results, "an army called %s already exists" % groups['new_name'])
	
	# Ensure they're not trying to make a garrison
	if "garrison" in groups['new_name'].lower():
		return order_block.fail(results, "it sounds like you are trying to make a garrison, these are created automatically")
	
	results['queries'].extend(army_f.make_rename_query(the_army.id, groups['new_name']))
	results['results'].append("%s renamed to %s" % (the_army.name, groups['new_name']))
	
	return order_block.success(results)
コード例 #3
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def delete_army_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	# Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of '%s'" % groups['army'])
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	# Default result
	results = order_block.default_line_results(the_line, "%s could not be deleted because" % (the_army.name))
	
	# More handles
	squad_dict		= the_line.the_world.squads()
	squads_lookup	= the_line.the_world.squads_lookup_from_army(the_army.id)# We're not gonna use this the normal way
	
	# Are the squads in it empty?
	for squad_name, squad_id in squads_lookup.items():
		results['queries'].extend(squad_f.make_delete_query(squad_id))
		
		if squad_dict[squad_id].amount > 0:
			return order_block.fail(results, "one of it's squads (%s) is not empty" % squad_dict[squad_id].name)
	
	results['queries'].extend(army_f.make_delete_query(the_army.id))
	results['results'].append("The army '%s' was deleted" % the_army.name)
	
	return order_block.success(results)
コード例 #4
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def move_squad_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	# Handles
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	the_team		= the_line.the_world.teams()[the_line.block.team]
	
	# Check we have an army to take from
	if groups['current_army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of %s" % (groups['current_army']))
	else:
		current_army = army_dict[armies_lookup[groups['current_army'].lower()]]
	
	# Check we have an army to send to
	if groups['new_army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of %s" % (groups['new_army']))
	else:
		new_army = army_dict[armies_lookup[groups['new_army'].lower()]]
	
	# Now to find squads
	squad_dict				= the_line.the_world.squads()
	current_squads_lookup	= the_line.the_world.squads_lookup_from_army(current_army.id)
	new_squads_lookup		= the_line.the_world.squads_lookup_from_army(new_army.id)
	
	# Check we have a squad to take from
	if groups['squad'].lower() not in current_squads_lookup:
		return order_block.fail(results, "there is no army by the squad of %s in %s" % (groups['squad'], groups['current_army']))
	else:
		current_squad = squad_dict[current_squads_lookup[groups['squad'].lower()]]
	
	# Does a squad of this name already exist in the other army?
	if groups['squad'].lower() in new_squads_lookup:
		return split_squad_order(the_line, {
			"first_army":	groups['current_army'],
			"second_army":	groups['new_army'],
			"first_squad":	groups['squad'],
			"second_squad":	groups['squad'],
			"amount":		current_squad.amount,
		})
	
	# Run it!
	results = order_block.default_line_results(the_line, "The squad %s from %s could not be moved to %s because" % (current_squad.name, current_army.name, new_army.name))
	
	results['queries'].append("-- Moving squad '%s' (ID:%d) from army '%s' (ID:%d) to army '%s' (ID:%d)" % (
		current_squad.name,
		current_squad.id,
		
		current_army.name,
		current_army.id,
		
		new_army.name,
		new_army.id,
	))
	results['queries'].extend(squad_f.make_squad_move_query(current_squad.id, new_army.id))
	results['results'] = ["%s moved from %s to %s" % (current_squad.name, current_army.name, new_army.name)]
	
	return order_block.success(results)
コード例 #5
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def create_army_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	the_team		= the_line.the_world.teams()[the_line.block.team]
	
	# # Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		# return order_block.fail(results, "could not find an army by the name of '%s'" % (groups['army']))
		pass
		the_army = None
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	x, y = int(groups['x']), int(groups['y'])
	
	# Check to see if the army exists
	if the_army == None:
		# Input a new army
		army_id = army_q.create_empty_army(the_line.the_world.cursor, groups['army'], the_line.block.team, groups['x'], groups['y'])
		
		# Update caches
		army_dict[army_id] = army_q.get_one_army(the_line.the_world.cursor, army_id)
		the_army = army_dict[army_id]
		the_line.the_world._armies_lookup_from_team[the_team.id][the_army.name.lower()] = army_id
	
	# Right, time to run recruitment
	results['results'].append("Created the army %s at %s" % (the_army.name, str((the_army.x, the_army.y))))
	results['line_cache'] = {"army":the_army.id}
	return order_block.success(results)
コード例 #6
0
ファイル: diplomacy_o.py プロジェクト: Teifion/Rob3
def specific_border_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	team_lookup	= the_line.the_world.teams_lookup(lower=True)
	team_dict = the_line.the_world.teams()
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	# Can we find the State?
	try:
		state = team.border_states.index(groups['state'])
	except Exception as e:
		if groups['state'].lower() == "default":
			return border_reset_order(the_line, groups)
		else:
			state = -1
			for i, s in enumerate(team.border_states):
				if s.lower() == groups['state'].lower():
					state = i
			
			if state == -1:
				return order_block.fail(results, "there is no border state of '%s'" % groups['state'])
	
	# Can we find the team?
	if groups['team'].lower() not in team_lookup:
		return order_block.fail(results, "there is no team by the name of '%s'" % groups['team'])
	else:
		target_team = team_lookup[groups['team'].lower()]
	
	# Make sure that it's in the database
	the_line.try_query("INSERT INTO team_relations (host, visitor) values (%d, %d);" % (the_team.id, target_team))
	
	results['queries'].extend(team_f.make_specific_borders(the_team.id, target_team, state))
	results['results'].append("Borders to %s set to %s" % (team_dict[target_team].name, team.border_states[state]))
	
	return order_block.success(results)
コード例 #7
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def rename_squad_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	# Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of '%s'" % groups['army'])
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	# More handles
	squad_dict		= the_line.the_world.squads()
	squads_lookup	= the_line.the_world.squads_lookup_from_army(the_army.id)
	
	# Can we find the army?
	if groups['squad'].lower() not in squads_lookup:
		return order_block.fail(results, "there is no squad by the name of '%s' in %s" % (groups['squad'], the_army.name))
	else:
		the_squad = squad_dict[squads_lookup[groups['squad'].lower()]]
	
	results['queries'].extend(squad_f.make_rename_query(the_squad.id, groups['new_name']))
	results['results'].append("%s renamed to %s" % (the_squad.name, groups['new_name']))
	
	return order_block.success(results)
コード例 #8
0
ファイル: diplomacy_o.py プロジェクト: Teifion/Rob3
def specific_tax_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	team_lookup	= the_line.the_world.teams_lookup(lower=True)
	team_dict = the_line.the_world.teams()
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	# Can we find the Rate?
	try:
		rate = int(groups['rate'])
	except Exception as e:
		return order_block.fail(results, "unable to interpret the number of  '%s'" % groups['rate'])
	
	# Can we find the team?
	if groups['team'].lower() not in team_lookup:
		return order_block.fail(results, "there is no team by the name of '%s'" % groups['team'])
	else:
		target_team = team_lookup[groups['team'].lower()]
	
	# Make sure that it's in the database
	the_line.try_query("INSERT INTO team_relations (host, visitor) values (%d, %d);" % (the_team.id, target_team))
	
	results['queries'].extend(team_f.make_specific_taxes(the_team.id, target_team, rate))
	results['results'].append("taxes to %s set to %s%%" % (team_dict[target_team].name, rate))
	
	return order_block.success(results)
コード例 #9
0
ファイル: unknown_o.py プロジェクト: Teifion/Rob3
def todo_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	results['input_response'] = None
	results['results'] = [the_line.content]
	results['success'] = True
	results['debug'] = []
	return results
コード例 #10
0
ファイル: trade_o.py プロジェクト: Teifion/Rob3
def send_tech(the_line, tech_id, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	teams_lookup	= the_line.the_world.teams_lookup(lower=True)
	
	techs_lookup	= the_line.the_world.techs_lookup()
	tech_dict		= the_line.the_world.techs()
	
	team_dict		= the_line.the_world.teams()
	
	the_team		= team_dict[the_line.block.team]
	the_tech		= tech_dict[tech_id]
	
	# Can we find the team?
	if groups['team_name'].lower() not in teams_lookup:
		return order_block.fail(results, "there is no team by the name of '%s'" % groups['team_name'])
	else:
		target_team = team_dict[teams_lookup[groups['team_name'].lower()]]
	
	# Limits of how many you can send a turn
	if the_team.research_sent >= 2:
		return order_block.fail(results, "%s could not be sent to %s because you have already sent the maximum number of spells/techs this turn" % (the_tech.name, target_team.name))
	
	# Is the item tradable?
	if not the_tech.tradable:
		return order_block.fail(results, "%s could not be sent to %s because it is not tradable" % (the_tech.name, target_team.name))
	
	# Do you have a high enough level?
	if the_team.tech_levels.get(tech_id, 0) <= target_team.tech_levels.get(tech_id, 0):
		return order_block.fail(results, "%s could not be sent to %s" % (the_tech.name, target_team.name))
	
	# Do they have a too high a level of it?
	if target_team.tech_levels.get(tech_id, 0) >= 5:
		return order_block.fail(results, "%s could not be sent to %s" % (the_tech.name, target_team.name))
	
	#	EXECUTION
	#------------------------
	# Check that there's an entry in the database for it
	if target_team.tech_levels.get(tech_id, 0) == 0:
		if target_team.tech_points.get(tech_id, 0) == 0:
			the_line.try_query(tech_f.check_row_exists(team_id=target_team.id, tech_id=the_tech.id))
	
	# Queries
	results['foreign_queries'][target_team.id] = tech_f.trade_query(target_team.id, tech_id)
	
	# Apply change to our copy of the world
	target_team.tech_levels[tech_id] = target_team.tech_levels.get(tech_id, 0) + 1
	target_team.tech_points[tech_id] = 0
	
	# Result
	results['results'].append("%s was sent to %s" % (the_tech.name, target_team.name))
	results['foreign_results'][target_team.id] = ["%s was sent from %s" % (the_tech.name, the_team.name)]
	
	# Update sending limits
	the_team.research_sent += 1
	
	return order_block.success(results)
コード例 #11
0
ファイル: command_o.py プロジェクト: Teifion/Rob3
def enable_overbudget_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	the_team.overbudget = ["Materials"]
	results['results'] = ["Overbudget checks disabled"]
	
	return order_block.success(results)
コード例 #12
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def select_army_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	armies_lookup = the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	# Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of '%s'" % groups['army'])
	else:
		army_id = armies_lookup[groups['army'].lower()]
	
	results['results'].append("Selected '%s'" % (groups['army']))
	results['line_cache'] = {"army":army_id}
	return order_block.success(results)
コード例 #13
0
ファイル: trade_o.py プロジェクト: Teifion/Rob3
def boolean_trade_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	resources_lookup	= resource_list.data_dict_n_l
	resource_dict		= resource_list.data_dict
	teams_lookup		= the_line.the_world.teams_lookup(lower=True)
	
	team_dict			= the_line.the_world.teams()
	the_team			= the_line.the_world.teams()[the_line.block.team]
	
	# Can we find the resource?
	if groups['item_name'].lower() not in resources_lookup:
		raise Exception("Unable to find %s in resource_list.data_dict_n_l.\n\nresource_list.data_dict_n_l = %s" % (groups['item_name'].lower(), resources_lookup))
	else:
		the_resource = resource_dict[resources_lookup[groups['item_name'].lower()]]
	
	# Can we find the team?
	if groups['team_name'].lower() not in teams_lookup:
		return order_block.fail(results, "there is no team by the name of '%s'" % groups['team_name'])
	else:
		target_team = team_dict[teams_lookup[groups['team_name'].lower()]]
	
	# Is it tradable?:
	if not the_resource.tradable:
		raise Exception("%s is not a tradable resource yet is still matched for trade_o.discrete_trade_order" % the_resource.name)
	
	# Is there a path there?
	path_found = path_f.find_trade_route(the_line.the_world.cursor,
		the_team.id, target_team.id, the_world=the_line.the_world)
	
	if path_found == (-1, -1):
		return order_block.fail(results, "%s could not be sent to %s because no trade route between you could be found" % (the_resource.name, target_team.name))
	
	# Can you afford it?
	if the_team.resources.get(the_resource.name, 0) < 1:
		results['cost'] = res_dict.Res_dict("%s:1" % the_resource.name)
		return order_block.fail_cost(results)
	
	#	EXECUTION
	#------------------------
	# Apply cost
	target_team.resources.set(the_resource.id, 1)
	
	# Result
	results['results'].append("%s was sent to %s" % (the_resource.name, target_team.name))
	results['foreign_results'][target_team.id] = ["%s was sent from %s" % (the_resource.name, the_team.name)]
	results['foreign_costs'][target_team.id] = res_dict.Res_dict("%s:-1" % the_resource.name)
	
	return order_block.success(results)
コード例 #14
0
ファイル: diplomacy_o.py プロジェクト: Teifion/Rob3
def default_tax_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	# Can we find the Rate?
	try:
		rate = int(groups['rate'])
	except Exception as e:
		return order_block.fail(results, "unable to interpret the number of  '%s'" % groups['rate'])
	
	results['queries'].extend(team_f.make_default_taxes(the_team.id, rate))
	results['results'].append("Taxes now default to %s%%" % (rate))
	
	return order_block.success(results)
コード例 #15
0
ファイル: trade_o.py プロジェクト: Teifion/Rob3
def tech_trade_order(the_line, groups, debug=False):
	spells_lookup	= the_line.the_world.spells_lookup(lower=True)
	techs_lookup	= the_line.the_world.techs_lookup(lower=True)
	
	# Tech
	if groups['item_name'].lower() in techs_lookup:
		return send_tech(the_line, techs_lookup[groups['item_name'].lower()], groups)
	
	# Spell
	if groups['item_name'].lower() in spells_lookup:
		return send_spell(the_line, spells_lookup[groups['item_name'].lower()], groups)
		
	# Failure!
	results = order_block.default_line_results(the_line)
	return order_block.fail(results, "there is no spell or tech by the name of '%s'" % groups['item_name'])
コード例 #16
0
ファイル: command_o.py プロジェクト: Teifion/Rob3
def assume_points_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	if not the_line.block.msn_order:
		return order_block.fail(results, "Command not valid in live mode")
	
	if groups['resource'].lower() not in resource_list.data_dict_n_l:
		return order_block.fail(results, "The resource '%s' could not be found" % groups['resource'])
	
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	the_team.resources.set(groups['resource'], float(groups['amount']))
	results['results'] = ["Your amount of %s has now been set to %s for this batch of orders" % (groups['resource'], groups['amount'])]
	
	return order_block.success(results)
コード例 #17
0
ファイル: operative_o.py プロジェクト: Teifion/Rob3
def reinforce_cell(the_line, groups, debug=False):
    results = order_block.default_line_results(the_line)

    operative_dict = the_line.the_world.operatives()
    operative_lookup = the_line.the_world.operatives_lookup(lower=True)

    the_team = the_line.the_world.teams()[the_line.block.team]

    # DB checks
    # ------------------------
    # Can we find the building?
    if groups["name"].lower() not in operative_lookup:
        return order_block.fail(results, "there is no cell by the name of '%s'" % groups["name"])

    the_op = operative_dict[operative_lookup[groups["name"].lower()]]

    # If it's ours then we can reinforce it
    if the_op.team != the_team.id:
        return order_block.fail(results, "the cell named '%s' is not yours" % groups["name"])

    amount = int(groups["size"])

    # Get cost
    try:
        results["cost"] = operative_rules.get_reinforce_cost(the_op, amount)
    except Exception as e:
        return order_block.fail(results, e.args[0])

        # Check affordability
    affordability = the_team.resources.affordable(results["cost"])[0]

    if not affordability:
        return order_block.fail_cost(results)

        # 	EXECUTION
        # ------------------------
        # Queries
    results["queries"].append("-- Operatives %s reinforce by %s for team:%d" % (groups["name"], amount, the_team.id))
    results["queries"].extend(operative_f.reinforce_query(the_op.id, amount))

    # Apply cost
    the_team.resources -= results["cost"].discrete()

    # Results
    results["results"].append("%s reinforced by %d" % (groups["name"], amount))

    return order_block.success(results)
コード例 #18
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def relocate_army_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	army_dict		= the_line.the_world.armies()
	armies_lookup	= the_line.the_world.armies_lookup_from_team(the_line.block.team)
	
	new_location = (int(groups['x']), int(groups['y']))
	
	# Can we find the army?
	if groups['army'].lower() not in armies_lookup:
		return order_block.fail(results, "there is no army by the name of '%s'" % groups['army'])
	else:
		the_army = army_dict[armies_lookup[groups['army'].lower()]]
	
	results['queries'].extend(army_f.make_relocation_query(the_army.id, new_location))
	results['results'] = ["%s relocated to %s" % (the_army.name, str(new_location))]
	return order_block.success(results)
コード例 #19
0
ファイル: diplomacy_o.py プロジェクト: Teifion/Rob3
def tax_reset_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)

	team_lookup	= the_line.the_world.teams_lookup(lower=True)
	team_dict = the_line.the_world.teams()
	the_team = the_line.the_world.teams()[the_line.block.team]

	# Can we find the team?
	if groups['team'].lower() not in team_lookup:
		return order_block.fail(results, "there is no team by the name of '%s'" % groups['team'])
	else:
		target_team = team_lookup[groups['team'].lower()]

	results['queries'].extend(team_f.specific_taxes_reset(the_team.id, target_team))
	results['results'].append("taxes to %s now set to default" % (team_dict[target_team].name))

	return order_block.success(results)
コード例 #20
0
ファイル: trade_o.py プロジェクト: Teifion/Rob3
def supply_change_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	city_dict		= the_line.the_world.cities()
	cities_lookup	= the_line.the_world.cities_lookup(lower=True)
	
	# _find_city
	if groups['city'].lower() not in cities_lookup:
		if debug:
			results['debug'].append("Failed at _find_city")
		return order_block.fail(results, "there is no city by the name of '%s'" % groups['city'])
	else:
		the_city = city_dict[cities_lookup[groups['city'].lower()]]
	
	# _ownership
	if the_city.team != the_line.block.team:
		if debug:
			results['debug'].append("Failed at _ownership")
		return order_block.fail(results, "%s is not your city" % the_city.name)
	
	# _find_res
	resource_id = -1
	for i, r in enumerate(sad_rules.res_list):
		if r.lower() == groups['res_item'].lower():
			resource_id = i
	
	if resource_id < 0:
		if debug:
			results['debug'].append("Failed at _find_res")
		return order_block.fail(results, "%s is not a valid resource" % groups['res_item'])
	
	# Queries
	results['queries'].append("-- Supply change for %s to %s for team:%d, city:%d" % (
		the_city.name, sad_rules.res_list[resource_id], the_line.block.team, the_city.id))
	results['queries'].extend(trade_f.make_supply_change_query(the_city.id, resource_id))
	
	# Result
	results['results'].append("%s is now producing %s" % (the_city.name, sad_rules.res_list[resource_id]))
	
	# Update city points
	the_city.supply_good = resource_id
	
	return order_block.success(results)
コード例 #21
0
ファイル: operative_o.py プロジェクト: Teifion/Rob3
def move_cell(the_line, groups, debug=False):
    results = order_block.default_line_results(the_line)

    city_dict = the_line.the_world.cities()
    cities_lookup = the_line.the_world.cities_lookup(lower=True)

    operative_dict = the_line.the_world.operatives()
    operative_lookup = the_line.the_world.operatives_lookup(lower=True)

    the_team = the_line.the_world.teams()[the_line.block.team]

    # DB checks
    # ------------------------
    # Can we find the building?
    if groups["name"].lower() not in operative_lookup:
        return order_block.fail(results, "there is no cell by the name of '%s'" % groups["name"])

    the_op = operative_dict[operative_lookup[groups["name"].lower()]]

    # If it's ours then we can reinforce it
    if the_op.team != the_team.id:
        return order_block.fail(results, "the cell named '%s' is not yours" % groups["name"])

        # Now we want the city
    if groups["city"].lower() not in cities_lookup:
        return order_block.fail(results, "there is no city by the name of '%s'" % groups["city"])
    else:
        the_city = city_dict[cities_lookup[groups["city"].lower()]]

        # Is this a dead city?
    if the_city.dead > 0:
        return order_block.fail(results, "there is no living city by the name of '%s'" % groups["city"])

        # 	EXECUTION
        # ------------------------
        # Queries
    results["queries"].append("-- Operatives %s move to %s for team:%d" % (groups["name"], the_city.name, the_team.id))
    results["queries"].extend(operative_f.move_operative_query(the_op.id, the_city.id))

    # Results
    results["results"].append("%s moved to %s" % (groups["name"], the_city.name))

    return order_block.success(results)
コード例 #22
0
ファイル: command_o.py プロジェクト: Teifion/Rob3
def assume_supply_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	if not the_line.block.msn_order:
		return order_block.fail(results, "Command not valid in live mode")
	
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	res_name = groups['supply']
	if res_name.lower() not in resource_list.data_dict_n_l:
		return order_block.fail(results, "Supply not found in the list of supplies")
	
	# Force correct case
	res_name = resource_list.data_dict[resource_list.data_dict_n_l[res_name.lower()]]
	
	the_team.resources.set(res_name.name, 1)
	
	results['results'] = ["All subsequent orders will assume you have traded for a supply of %s" % groups['supply']]
	
	return order_block.success(results)
コード例 #23
0
ファイル: diplomacy_o.py プロジェクト: Teifion/Rob3
def default_border_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	# Can we find the State?
	try:
		state = team.border_states.index(groups['state'])
	except Exception as e:
		state = -1
		for i, s in enumerate(team.border_states):
			if s.lower() == groups['state'].lower():
				state = i
		
		if state == -1:
			return order_block.fail(results, "there is no border state of '%s'" % groups['state'])
	
	results['queries'].extend(team_f.make_default_borders(the_team.id, state))
	results['results'].append("Borders now default to %s" % (team.border_states[state]))
	
	return order_block.success(results)
コード例 #24
0
ファイル: military_o.py プロジェクト: Teifion/Rob3
def select_squad_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	# Check we have an army to select from
	army_id = -1
	if "army" in the_line.block.line_cache:
		army_id = the_line.block.line_cache["army"]
	
	if army_id < 1:
		return order_block.fail(results, "No army has been selected so no squad can be found")
	
	# Cache it for the next line
	results['line_cache'] = {"army":army_id}
	
	the_army		= the_line.the_world.armies()[army_id]
	squad_dict		= the_line.the_world.squads()
	squads_lookup	= the_line.the_world.squads_lookup_from_army(army_id)
	
	# Can we find the squad?
	if groups['squad'].lower() not in squads_lookup:
		return order_block.fail(results, "there is no squad by the name of '%s' in %s" % (groups['squad'], the_army.name))
	else:
		the_squad = squad_dict[squads_lookup[groups['squad'].lower()]]
	
	# Check amount
	try:
		amount = int(groups['amount'])
	except Exception as e:
		return order_block.fail(results, "the amount '%s' could not be converted into a number" % groups['amount'])
	
	if amount < 0:
		groups['amount'] = str(-amount)
		return disband_squad_order(the_line, groups, debug=debug)
	
	# Right, time to run recruitment
	results = _recruit(the_line, the_squad, the_army, amount, debug)
	results['line_cache'] = {"army":army_id}
	return results
コード例 #25
0
ファイル: founding_o.py プロジェクト: Teifion/Rob3
def founding_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	all_cities				= the_line.the_world.cities()
	city_dict				= the_line.the_world.cities_from_team(the_line.block.team)
	cities_lookup			= the_line.the_world.cities_lookup(lower=True)
	
	the_team				= the_line.the_world.teams()[the_line.block.team]
	team_dict				= the_line.the_world.teams()
	
	dead_city = -1
	
	# Handles
	new_city_name = groups['city_name']
	supply_list_s = groups['city_list']
	size = int(groups['size'].replace(',', ''))
	if groups['city_type'] != None:
		city_type = groups['city_type'].lower().strip()
	else:
		city_type = None
	
	is_port, is_nomadic = False, False
	
	if city_type == "port":
		is_port = True
	elif city_type == "nomadic":
		is_nomadic = True
	
	# Get the location from the string
	try:
		x, y = groups['location'].split(',')
		x = int(x.strip())
		y = int(y.strip())
		terrain = mapper_q.get_terrain(the_line.the_world.cursor, x, y)
		
	except Exception as e:
		return order_block.fail(results, "%s was not founded because trying to read the location produced an error: %s" % (groups['city_name'], e.args[0]))
	
	# Rule checks
	#------------------------
	results = order_block.default_line_results(the_line, "%s could not be founded at %s because" % (new_city_name, str((x, y))))
	
	# You can't build on water!
	if map_data.terrain[terrain] in ('water', 'lake', 'XYZ_1', 'XYZ_2', 'XYZ_3'):
		return order_block.fail(results, "you cannot build on that terrain (%s)" % map_data.terrain[terrain])
	
	# Does it already exist?
	if new_city_name.lower() in cities_lookup:
		existing_city = all_cities[cities_lookup[new_city_name.lower()]]
		
		try:
			if not existing_city.dead:
				return order_block.fail(results, "%s already exists (controlled by %s)" % (new_city_name, team_dict[existing_city.team].name))
			else:
				# Currently all dead cities need a GM to act
				return order_block.fail(results, "%s already exists as a dead city, contact Teifion to to fix it (ID:%d)" % (new_city_name, cities_lookup[new_city_name.lower()]))
				
				
				if all_cities[cities_lookup[new_city_name.lower()]].team == the_team.id:
					dead_city = cities_lookup[new_city_name.lower()]
				else:
					return order_block.fail(results, "%s already exists as a dead city, contact Teifion to to fix it (ID:%d)" % (new_city_name, cities_lookup[new_city_name.lower()]))
		except Exception as e:
			print(new_city_name.lower())
			raise
	
	# Is it allowed to be a port?
	if is_port:
		if map_data.terrain[terrain] != "shore":
			is_port = False
			if mapper_q.get_terrain(the_line.the_world.cursor, x-10, y-10) == 0: is_port = True
			if mapper_q.get_terrain(the_line.the_world.cursor, x-10, y) == 0: is_port = True
			if mapper_q.get_terrain(the_line.the_world.cursor, x-10, y+10) == 0: is_port = True
			
			if mapper_q.get_terrain(the_line.the_world.cursor, x, y-10) == 0: is_port = True
			if mapper_q.get_terrain(the_line.the_world.cursor, x, y+10) == 0: is_port = True
			
			if mapper_q.get_terrain(the_line.the_world.cursor, x+10, y-10) == 0: is_port = True
			if mapper_q.get_terrain(the_line.the_world.cursor, x+10, y) == 0: is_port = True
			if mapper_q.get_terrain(the_line.the_world.cursor, x+10, y+10) == 0: is_port = True
		
		if not is_port:
			return order_block.fail(results, "%s that is not next to the sea" % str((x, y)))
	
	# Supply list
	supply_dict_raw = {}
	if supply_list_s != None:
		supply_list_s = supply_list_s.split(",")
		for s in supply_list_s:
			sls = s.lower().strip()
			if sls in cities_lookup:
				supply_dict_raw[cities_lookup[sls]] = 9999999
	else:
		for c in city_dict.keys():
			supply_dict_raw[c] = 9999999
	
	# print("")
	# print(supply_dict_raw)
	
	if debug:
		results['debug'].append("First pass:"******"City ID %d was not in city_dict" % c)
			return order_block.fail(results, "One or more of the cities used as a source were not valid (ID: %d)" % c)

		the_city = city_dict[c]
		if the_city.dead > 0: continue
		
		if new_city_continent != path_f.get_continent(the_line.the_world.cursor, (the_city.x, the_city.y)):
			if not is_port or not the_city.port:
				if len(supply_dict_raw) == 1:
					if debug:
						results['debug'].append("Continent of target: %s" % new_city_continent)
						results['debug'].append("Continent of supply: %s" % path_f.get_continent(the_line.the_world.cursor, (the_city.x, the_city.y)))
						
					if not the_city.port and not is_port:
						return order_block.fail(results, "the city you supplied is on another contintent and neither this city nor the new one are a port")
					elif not the_city.port:
						return order_block.fail(results, "the city you supplied is on another contintent and the existing city is not a port")
					elif not is_port:
						return order_block.fail(results, "the city you supplied is on another contintent and the new city is not a port")
					else:
						raise Exception("No handle")	
				
				if not is_port:
					if debug:
						results['debug'].append("Skipped %s due to the new city being on another landmass and not a port" % (city_dict[c].name))
				elif not the_city.port:
					if debug:
						results['debug'].append("Skipped %s due to it not being a port" % (city_dict[c].name))
				
				# We need both to be a port if they're on different landmasses
				continue
			
			path_data = path_f.path(the_line.the_world.cursor, [(the_city.x, the_city.y), (x, y)],
				move_speed="Sailing", move_type="Sail")
			supply_dict[c] = path_data.time_cost
			if debug:
				results['debug'].append("Added %s to dict with %s (sailing)" % (city_dict[c].name, int(path_data.time_cost)))
			
		else:# Same continent
			path_data = path_f.path(the_line.the_world.cursor, [(the_city.x, the_city.y), (x, y)],
				move_speed="Colonists", move_type="Colonists")
			supply_dict[c] = path_data.time_cost
			if debug:
				results['debug'].append("Added %s to dict with %s (walking)" % (city_dict[c].name, int(path_data.time_cost)))
		
		# Work out if it's in range
		if supply_dict[c] > 182:# 6 months
			if debug:
				results['debug'].append("Removed %s from dict with, it took %s" % (city_dict[c].name, int(supply_dict[c])))
			del(supply_dict[c])
	
	if debug:
		results['debug'].append("\nCities in range:")
		for k, v in supply_dict.items():
			results['debug'].append("%s has %s to offer (travel time %s)" % (city_dict[k].name, city_dict[k].population, int(v)))
		
		# results['debug'].append("")
	
	cities_changed = True
	while cities_changed:
		if len(supply_dict) < 1:
			if groups['city_list'] == None:
				return order_block.fail(results, "the cities able to reach the new location were too far away or not large enough")
			else:
				return order_block.fail(results, "the cities able to reach the new location from the list provided were too far away or not large enough")
		
		cities_to_delete	= []
		cities_changed		= False
		
		city_count			= len(supply_dict)
		amount_per_city		= math.ceil(size/city_count)
		
		for c in supply_dict.keys():
			# Check the city size
			if city_dict[c].population < amount_per_city:
				# if debug: print("deleted %s (%s) pop:%s < %s" % (c, city_dict[c].name, supply_dict[c], amount_per_city))
				cities_to_delete.append(c)
				cities_changed = True
		
		for c in cities_to_delete:
			del(supply_dict[c])
	
	# Get cost
	results['cost'] = res_dict.Res_dict("Materials:%s" % (size/1000))
	
	# Check affordability
	affordability = the_team.resources.affordable(results['cost'])[0]
	
	if not affordability and "Materials" not in the_team.overbudget:
		return order_block.fail_cost(results)
	
	#	EXECUTION
	#------------------------
	# Queries
	results['queries'].append("-- Founding %s at %s for team:%d" % (new_city_name, str((x, y)), the_team.id))
	if dead_city > 1: results['queries'].extend(city_f.make_remove_dead_city_query(dead_city))
	results['queries'].extend(city_f.make_founding_query(
		the_team.id, new_city_name, (x, y), is_port, is_nomadic, size, supply_dict.keys())
	)
	
	# Apply cost
	for c in supply_dict.keys():
		city_dict[c].population -= (size/len(supply_dict))
	
	the_team.resources -= results['cost'].discrete()
	
	# Result
	results['results'].append("%s was successfully founded at %s at a size of %s" % (new_city_name, str((x, y)), size))
	
	return order_block.success(results)
コード例 #26
0
ファイル: relocation_o.py プロジェクト: Teifion/Rob3
def relocation_order(the_line, groups, debug=False):
    results = order_block.default_line_results(the_line)

    city_dict = the_line.the_world.cities_from_team(the_line.block.team)
    cities_lookup = the_line.the_world.cities_lookup(lower=True)

    all_cities = the_line.the_world.cities()
    city_dict = the_line.the_world.cities_from_team(the_line.block.team)
    the_team = the_line.the_world.teams()[the_line.block.team]

    groups["from_city"] = groups["from_city"].strip()
    groups["to_city"] = groups["to_city"].strip()

    # Can we find the city?
    if groups["from_city"].lower() not in cities_lookup:
        return order_block.fail(results, "there is no city by the name of '%s'" % groups["from_city"])
    else:
        from_city = all_cities[cities_lookup[groups["from_city"].lower()]]

    if groups["to_city"].lower() not in cities_lookup:
        return order_block.fail(results, "there is no city by the name of '%s'" % groups["to_city"])
    else:
        to_city = all_cities[cities_lookup[groups["to_city"].lower()]]

        # Target
    try:
        amount = int(groups["amount"].replace(",", ""))
    except Exception as e:
        return order_block.fail(
            results, "there was an error trying to interpret the number '%s'. error: %s" % (groups["amount"], e.args[0])
        )

        # Type
    if groups["type"].lower() == "civilians":
        move_type = "Civilians"
    elif groups["type"].lower() == "slaves":
        move_type = "Slaves"

        # Default result
    results = order_block.default_line_results(
        the_line, "%s %s could not be moved from %s to %s because" % (amount, move_type, from_city.name, to_city.name)
    )

    # Strip out all cities too far away, you can only travel for 12 months
    from_loc = (from_city.x, from_city.y)
    to_loc = (to_city.x, to_city.y)
    journey = path_f.path(
        cursor=the_line.the_world.cursor, waypoints=[from_loc, to_loc], move_speed="Colonists", move_type="Colonists"
    )

    # _journey.time_cost
    if journey.time_cost > 365:
        if debug:
            results["debug"].append("Failed at _journey.time_cost")
        return order_block.fail(
            results, "the time required to move between them is too long (%d days)" % journey.time_cost
        )

        # Cost
    results["cost"] = res_dict.Res_dict("Materials:%s" % (amount / 1000))

    # Check affordability
    affordability = the_team.resources.affordable(results["cost"])[0]
    if not affordability:
        return order_block.fail_cost(results)

        # Are we going overseas?
        # if mapper_f.get_tile_continent(from_loc) != mapper_f.get_tile_continent(to_loc):
        # 	transport_capacity = team_f.team_sea_transport_capacity(block.team)
        # 	trips_allowed = math.floor(365/float(journey_time))
        #
        # 	if (amount > transport_capacity) and (amount*2 > transport_capacity * trips_allowed):
        # 		results	= "%s could not be relocated from %s to %s amount of overseas transport available is too small" % (amount, the_from_city.city_name, the_to_city.city_name)
        # 		return results, queries, order_cost

        # _city_size
    if move_type == "Civilians":
        if from_city.population < amount:
            if debug:
                results["debug"].append("Failed at _city_size_civilians")
                results["debug"].append("Population: %s" % from_city.population)
                results["debug"].append("Slaves: %s" % from_city.slaves)
                results["debug"].append("Amount: %s" % amount)
            return order_block.fail(results, "the city is not big enough to send that many civilians")

        from_city.population -= amount
        to_city.population += amount
    elif move_type == "Slaves":
        if from_city.slaves < amount:
            if debug:
                results["debug"].append("Failed at _city_size_slaves")
                results["debug"].append("Population: %s" % from_city.population)
                results["debug"].append("Slaves: %s" % from_city.slaves)
                results["debug"].append("Amount: %s" % amount)
            return order_block.fail(results, "the city is not big enough to send that many slaves")

        from_city.slaves -= amount
        to_city.slaves += amount

    results["queries"].extend(city_f.make_relocation_query(from_city.id, to_city.id, amount, move_type))
    results["results"].append(
        "%s %s were successfully moved from %s to %s" % (amount, move_type, from_city.name, to_city.name)
    )

    # Apply cost
    the_team.resources -= results["cost"].discrete()

    return order_block.success(results)
コード例 #27
0
ファイル: migration_o.py プロジェクト: Teifion/Rob3
def migration_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	city_dict		= the_line.the_world.cities_from_team(the_line.block.team)
	cities_lookup	= the_line.the_world.cities_lookup(lower=True)
	
	# Can we find the city?
	if groups['city'].lower() not in cities_lookup:
		return order_block.fail(results, "there is no city by the name of '%s'" % groups['city'])
	else:
		the_city = city_dict[cities_lookup[groups['city'].lower()]]
	
	the_team = the_line.the_world.teams()[the_line.block.team]
	
	# Target
	try:
		target = (int(groups['x']), int(groups['y']))
	except Exception as e:
		return order_block.fail(results, "%s was not moved because trying to read the target location produced an error: %s" % (groups['city_name'], e.args[0]))
	
	# Default result
	results = order_block.default_line_results(the_line, "%s could not be moved to %s because" % (the_city.name, str(target)))
	
	# First we check it's on the same continent, if it's not you can't migrate there
	our_continent		= path_f.get_continent(the_line.the_world.cursor, (the_city.x, the_city.y))
	target_continent	= path_f.get_continent(the_line.the_world.cursor, target)
	
	# Before we path, lets check that they can walk there
	if our_continent != target_continent:
		if target_continent == None:# or target_continent == -1:
			return order_block.fail(results, "the target is the ocean")
		else:
			return order_block.fail(results, "the target is on a different island")
	
	terrain = mapper_q.get_terrain(the_line.the_world.cursor, target[0], target[1])
	if map_data.terrain[terrain] in ('lake', 'XYZ_1', 'XYZ_2', 'XYZ_3'):
		return order_block.fail(results, "you cannot migrate to that terrain (%s)" % map_data.terrain[terrain])
	
	# Pathing time!
	journey = path_f.path(
		cursor=the_line.the_world.cursor,
		waypoints=[(the_city.x, the_city.y), target],
		move_speed="Nomads",
		move_type="Nomads")
	
	# Does this take more than a year?
	travel_time = journey.time_cost
	actual_target = target
	
	current_time = 0
	if journey.time_cost > 365:
		for s in journey.steps:
			if current_time + s['time_cost'] <= 365:
				actual_target = s['tile']
				current_time += s['time_cost']
		
		travel_time = current_time
	
	if actual_target != target:
		results['results'].append("%s migrated to %s, to migrate to %s will take another %s days" % (the_city.name, str(actual_target), str(target), (journey.time_cost - travel_time)))
	else:
		results['results'].append("%s migrated to %s" % (the_city.name, str(target)))
	
	# Get the query to make it happen
	results['queries'].extend(city_f.make_migration_query(the_city.id, actual_target, travel_time))
	
	return order_block.success(results)
コード例 #28
0
ファイル: construction_o.py プロジェクト: Teifion/Rob3
def building_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	building_dict			= the_line.the_world.buildings()
	city_dict				= the_line.the_world.cities()
	
	buildings_lookup		= the_line.the_world.buildings_lookup(lower=True)
	buildings_requirements	= the_line.the_world.building_requirements()
	cities_lookup			= the_line.the_world.cities_lookup(lower=True)
	
	the_team				= the_line.the_world.teams()[the_line.block.team]
	
	# DB checks
	#------------------------
	# _find_building
	if groups['building'].lower() not in buildings_lookup:
		if debug:
			results['debug'].append("Failed at _find_building")
		return order_block.fail(results, "there is no building by the name of '%s'" % groups['building'])
	else:
		the_building = building_dict[buildings_lookup[groups['building'].lower()]]
	
	# _find_city
	if groups['city'].lower() not in cities_lookup:
		if debug:
			results['debug'].append("Failed at _find_city")
		return order_block.fail(results, "there is no city by the name of '%s'" % groups['city'])
	else:
		the_city = city_dict[cities_lookup[groups['city'].lower()]]
	
	# _dead_city
	if the_city.dead > 0:
		if debug:
			results['debug'].append("Failed at _dead_city")
		return order_block.fail(results, "there is no living city by the name of '%s' (found id of %d)" % (groups['city'], the_city.id))
	
	# if the_line.the_world._cities[974].buildings != {'0':None}:
	# 	print(the_line.content, the_line.block.team, the_line.block.title_name)
	
	# if the_city.id == 974:
	# 	print("")
	# 	print(the_line.content)
	# 	
	# 	# for k, v in city_dict.items():
	# 	# 	if not v.dead:
	# 	# 		print(v.name, v.buildings)
	# 	
	# 	print("XXYYZZ")
	# 	the_line.the_world.cursor.execute("ROLLBACK")
	# 	the_line.the_world.cursor.execute("ROLLBACK")
	# 	exit()
	
	# Rule checks
	#------------------------
	results = order_block.default_line_results(the_line, "%s could not be built at %s because" % (the_building.name, the_city.name))
	
	# _swamp
	if the_city.terrain == map_data.terrain.index("swamp"):
		if the_building.wall or the_building.name == "Castle":
			if debug:
				results['debug'].append("Failed at _swamp")
			return order_block.fail(results, "%s is on a swamp" % the_city.name)
	
	# _ownership
	if the_city.team != the_line.block.team:
		if debug:
			results['debug'].append("Failed at _ownership")
		return order_block.fail(results, "%s is not your city" % the_city.name)
	
	# _nomadic
	if the_city.nomadic:
		if debug:
			results['debug'].append("Failed at _nomadic")
		return order_block.fail(results, "%s is nomadic" % the_city.name)
	
	amount		= the_city.buildings_amount.get(the_building.id, 0)
	completion	= the_city.buildings.get(the_building.id, 0)
	
	# _wall_points
	if the_building.wall and the_city.wall_points_used >= 1:
		if debug:
			results['debug'].append("Failed at _wall_points")
		return order_block.fail(results, "%s is already constructing a wall this year" % the_city.name)
	
	# _economy_points
	if the_building.economy and the_city.economy_points_used >= 1:
		if debug:
			results['debug'].append("Failed at _economy_points")
		return order_block.fail(results, "%s is already constructing an economic building this year" % the_city.name)
	
	# _building_points
	if not the_building.wall and not the_building.economy and the_city.building_points_used >= 1:
		if debug:
			results['debug'].append("Failed at _building_points")
		return order_block.fail(results, "%s is already constructing a building this year" % the_city.name)
	
	# _build_limit
	if completion == 0 and the_building.limit_per_city > 0:
		instances = amount
		
		# Is it used for an upgrade?
		if the_building.id in buildings_requirements:
			
			for b in buildings_requirements[the_building.id]:
				if b in the_city.buildings_amount:
					instances += the_city.buildings_amount[b]
				
				if b in the_city.buildings and the_city.buildings[b] > 0:
					instances += 1
		
		if instances >= the_building.limit_per_city:
			if debug:
				results['debug'].append("Failed at _build_limit")
			
			return order_block.fail(results, "you have reached the limit allowed in one city")
	
	# _upgrade_requirements
	if completion == 0 and the_building.upgrades > -1:
		if the_city.buildings_amount.get(the_building.upgrades, 0) < 1:
			if debug:
				results['debug'].append("Failed at _upgrade_requirements")
				results['debug'].append("Required {building} (id: {id})".format(
					building=building_dict[the_building.upgrades].name,
					id=the_building.upgrades)
				)
				results['debug'].append("the_city.buildings_amount: %s" % str(the_city.buildings_amount))
				results['debug'].append("the_city.buildings: %s" % str(the_city.buildings))
			
			return order_block.fail(results, "the required building (%s) is not complete there" % building_dict[the_building.upgrades].name)
	
	# Get cost
	results['cost'] = res_dict.Res_dict(the_building.cost_per_turn)
	if completion == 0:
		results['cost'] += res_dict.Res_dict(the_building.cost_up_front)
	
	# Check affordability
	affordability = the_team.resources.affordable(results['cost'])[0]
	
	if not affordability:
		if debug:
			results['debug'].append("Failed at _affordability")
			results['debug'].append("Cost: %s" % str(results['cost']))
			results['debug'].append("Team resources: %s" % str(the_team.resources))
		return order_block.fail_cost(results)
	
	#	EXECUTION
	#------------------------
	# Check we've got a DB row ready to update
	if completion == 0 and amount == 0:
		the_line.try_query(building_f.check_row_exists(building_id=the_building.id, city_id=the_city.id))
	
	# Completion
	if the_team.resources.get("Stone") > 0:
		new_completion = completion + 100
	else:
		new_completion = completion + 50
	
	new_completion = min(new_completion, the_building.build_time)
	
	# Completion percentage
	completion_percentage = int(100 * (new_completion/the_building.build_time))
	completion_percentage = min(completion_percentage, 100)
	
	# Queries
	results['queries'].append("-- Building %s at %s for team:%d" % (the_building.name, the_city.name, the_team.id))
	results['queries'].extend(building_f.completion_query(the_city, the_building, new_completion))
	
	# Apply cost
	the_team.resources -= results['cost'].discrete()
	
	# Result
	results['results'].append("%s is %s%% of the way through it's %s" % (the_city.name, completion_percentage, the_building.name))
	
	# Update city points
	if the_building.wall:	the_city.wall_points_used += 1
	else:					the_city.building_points_used += 1	
	
	return order_block.success(results)
コード例 #29
0
ファイル: construction_o.py プロジェクト: Teifion/Rob3
def wonder_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	wonder_dict				= the_line.the_world.wonders()
	city_dict				= the_line.the_world.cities()
	
	cities_lookup			= the_line.the_world.cities_lookup(lower=True)
	
	the_team				= the_line.the_world.teams()[the_line.block.team]
	
	# DB checks
	#------------------------
	# Can we find the city?
	if groups['assist_city'].lower() not in cities_lookup:
		return order_block.fail(results, "there is no city by the name of '%s'" % groups['wonder_city'])
	else:
		assist_city = city_dict[cities_lookup[groups['assist_city'].lower()]]
	
	# Can we find the city?
	if groups['wonder_city'].lower() not in cities_lookup:
		return order_block.fail(results, "there is no city by the name of '%s'" % groups['wonder_city'])
	else:
		wonder_city = city_dict[cities_lookup[groups['wonder_city'].lower()]]
	
	# Rule checks
	#------------------------
	results = order_block.default_line_results(the_line, "%s could not be assist %s because" % (assist_city.name, wonder_city.name))
	
	# Our cities?
	if assist_city.team != the_team.id:
		return order_block.fail(results, "%s is not your city" % assist_city.name)
	
	if wonder_city.team != the_team.id:
		return order_block.fail(results, "%s is not your city" % wonder_city.name)
	
	# Nomads can't help build
	if assist_city.nomadic:
		return order_block.fail(results, "%s is nomadic" % assist_city.name)
	
	# Dead cities can't build
	if assist_city.dead > 0:
		return order_block.fail(results, "%s is dead" % assist_city.name)
	
	if wonder_city.dead > 0:
		return order_block.fail(results, "%s is dead" % wonder_city.name)
	
	# Check for the wonder
	the_wonder = None
	for w, tw in wonder_dict.items():
		if tw.city == wonder_city.id:
			the_wonder = tw
	
	# Was a wonder found?
	if the_wonder == None:
		return order_block.fail(results, "there is no wonder in %s" % wonder_city.name)
	
	# Is the wonder already completed
	if the_wonder.completed:
		return order_block.fail(results, "%s has already completed it's wonder" % wonder_city.name)
	
	# Does the city have any points left?
	if assist_city.wall_points_used >= 1:
		return order_block.fail(results, "%s has used up it's wall construction point already" % assist_city.name)
	
	if assist_city.building_points_used >= 1:
		return order_block.fail(results, "%s has used up it's normal construction point already" % assist_city.name)
	
	# Get build rate
	build_rate = city_rules.wonder_build_rate(assist_city, wonder_city)
	if the_team.resources.get("Stone") < 1:
		build_rate *= 0.5
	
	if build_rate < 1:
		return order_block.fail(results, "%s is too small or too far away to assist" % assist_city.name)
	
	# Cost
	if the_wonder.completion + build_rate > the_wonder.point_cost:
		build_rate = the_wonder.point_cost - the_wonder.completion
	
	material_per_point = the_wonder.material_cost/the_wonder.point_cost
	results['cost'] = res_dict.Res_dict("Materials:%s" % (material_per_point*build_rate))
	
	# Check affordability
	affordability = the_team.resources.affordable(results['cost'])[0]
	if not affordability:
		return order_block.fail_cost(results)
	
	
	# INSERTION/UPDATE
	#------------------------
	# First queries are cost
	the_wonder.completion += build_rate
	if the_wonder.completion >= the_wonder.point_cost:
		the_wonder.completed = True
	
	results['queries'].append("-- Wonder %s assisting %s for team:%d" % (assist_city.name, wonder_city.name, the_team.id))
	results['queries'].extend(wonder_f.completion_query(the_wonder.id, the_wonder.completion))
	
	# Work out results
	if the_wonder.completion >= the_wonder.point_cost:
		results['results'].append("%s assisted %s with %s construction points, the wonder is now complete" % (assist_city.name, wonder_city.name, build_rate))
	else:
		results['results'].append("%s assisted %s with %s construction points" % (assist_city.name, wonder_city.name, build_rate))
	
	# Apply cost
	the_team.resources -= results['cost'].discrete()
		
	# Update city points
	assist_city.wall_points_used		+= 1
	assist_city.building_points_used	+= 1	
	
	return order_block.success(results)
コード例 #30
0
ファイル: command_o.py プロジェクト: Teifion/Rob3
def path_order(the_line, groups, debug=False):
	results = order_block.default_line_results(the_line)
	
	if not the_line.block.msn_order:
		return order_block.fail(results, "Command not valid in live mode")
	
	groups['waypoints'] = groups['waypoints'].strip()
	
	the_path = groups['waypoints'].replace(": ", "").replace(".", ",")
	path_split = [x.strip() for x in the_path.split(',')]
	waypoints = []
	
	for p in path_split:
		if waypoints == []:				waypoints.append([])
		elif len(waypoints[-1]) == 2:	waypoints.append([])
		
		try:
			waypoints[-1].append(int(p))
		except Exception:
			return order_block.fail(results, "the coordinates you sent could not be converted")
	
	# Get times
	infantry_time = path_f.path(
		cursor=the_line.the_world.cursor,
		waypoints=waypoints,
		move_speed="Marching",
		move_type="Medium foot"
	).time_cost
	
	cavalry_time = path_f.path(
		cursor=the_line.the_world.cursor,
		waypoints=waypoints,
		move_speed="Riding",
		move_type="Medium cav"
	).time_cost
	
	airship_time = path_f.path(
		cursor=the_line.the_world.cursor,
		waypoints=waypoints,
		move_speed="Sailing",
		move_type="Air"
	).time_cost
	
	ship_time = path_f.path(
		cursor=the_line.the_world.cursor,
		waypoints=waypoints,
		move_speed="Sailing",
		move_type="Sail"
	).time_cost
	
	colonist_time = path_f.path(
		cursor=the_line.the_world.cursor,
		waypoints=waypoints,
		move_speed="Colonists",
		move_type="Colonists"
	).time_cost
	
	# Print results
	results['results'] = ["""Time taken to travel from %s to %s is:
%s days as infantry
%s days as cavalry
%s days as airships
%s days as ships
%s days as colonists""" % (waypoints[0], waypoints[-1],
		round(infantry_time),
		round(cavalry_time),
		round(airship_time),
		round(ship_time),
		round(colonist_time),
	)]
	
	return order_block.success(results)