Пример #1
0
// -----------------------------------------------------------------------
// handle the resurrection spell
// -----------------------------------------------------------------------
bool t_resurrection_spell::left_click( t_screen_point const& point )
{
	t_map_point_2d         map_point;
	t_combat_creature_list creatures;
	bool                   defender = get_caster()->belongs_to_defender();
	
	creatures = get_targets( point );
	if (creatures.empty())
		return false;

	eliminate_duplicates( creatures );
	if (creatures.size() == 1)
	{
		resurrect( creatures.front().get() );
		return true;
	}
	
	t_combat_creature_list::iterator index;
	t_combat_creature_ptr            creature;
	t_handler                        handler;
	t_window*                        window = t_window::get_modal_window();

	m_menu = new t_scroll_menu( window );
	for (index = creatures.begin(); index != creatures.end(); index++)
	{
		creature = *index;
		handler = add_argument( bound_handler( *this, &t_resurrection_spell::resurrect ),
			                    creature );
		m_menu->add_item( get_text( creature ), handler );
	}
	m_menu->open( get_mouse_position( window ) );
	m_battlefield.get_window()->set_help_balloon_text( "" );
	return true;
}
Пример #2
0
/*
  forward a MAVLink message to the right port. This also
  automatically learns the route for the sender if it is not
  already known.
  
  This returns true if the message should be processed locally

  Theory of MAVLink routing:

  When a flight controller receives a message it should process it
  locally if any of these conditions hold:

    1a) the message has no target_system field

    1b) the message has a target_system of zero

    1c) the message has the flight controllers target system and has no
       target_component field

    1d) the message has the flight controllers target system and has
       the flight controllers target_component 

    1e) the message has the flight controllers target system and the
        flight controller has not seen any messages on any of its links
        from a system that has the messages
        target_system/target_component combination

  When a flight controller receives a message it should forward it
  onto another different link if any of these conditions hold for that
  link: 

    2a) the message has no target_system field

    2b) the message has a target_system of zero

    2c) the message does not have the flight controllers target_system
        and the flight controller has seen a message from the messages
        target_system on the link

    2d) the message has the flight controllers target_system and has a
        target_component field and the flight controllers has seen a
        message from the target_system/target_component combination on
        the link

Note: This proposal assumes that ground stations will not send command
packets to a non-broadcast destination (sysid/compid combination)
until they have received at least one package from that destination
over the link. This is essential to prevent a flight controller from
acting on a message that is not meant for it. For example, a PARAM_SET
cannot be sent to a specific sysid/compid combination until the GCS
has seen a packet from that sysid/compid combination on the link. 

The GCS must also reset what sysid/compid combinations it has seen on
a link when it sees a SYSTEM_TIME message with a decrease in
time_boot_ms from a particular sysid/compid. That is essential to
detect a reset of the flight controller, which implies a reset of its
routing table.

*/
bool MAVLink_routing::check_and_forward(mavlink_channel_t in_channel, const mavlink_message_t* msg)
{
    // learn new routes
    learn_route(in_channel, msg);

    if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT) {
        // heartbeat needs special handling
        handle_heartbeat(in_channel, msg);
        return true;
    }

    // extract the targets for this packet
    int16_t target_system = -1;
    int16_t target_component = -1;
    get_targets(msg, target_system, target_component);

    bool broadcast_system = (target_system == 0 || target_system == -1);
    bool broadcast_component = (target_component == 0 || target_component == -1);
    bool match_system = broadcast_system || (target_system == mavlink_system.sysid);
    bool match_component = match_system && (broadcast_component || 
                                            (target_component == mavlink_system.compid));
    bool process_locally = match_system && match_component;

    if (process_locally && !broadcast_system && !broadcast_component) {
        // nothing more to do - it can only be for us
        return true;
    }

    // forward on any channels matching the targets
    bool forwarded = false;
    for (uint8_t i=0; i<num_routes; i++) {
        if (broadcast_system || (target_system == routes[i].sysid &&
                                 (broadcast_component || 
                                  target_component == routes[i].compid))) {
            if (in_channel != routes[i].channel) {
                if (comm_get_txspace(routes[i].channel) >= 
                    ((uint16_t)msg->len) + MAVLINK_NUM_NON_PAYLOAD_BYTES) {
#if ROUTING_DEBUG
                    ::printf("fwd msg %u from chan %u on chan %u sysid=%u compid=%u\n",
                             msg->msgid,
                             (unsigned)in_channel,
                             (unsigned)routes[i].channel,
                             (unsigned)target_system,
                             (unsigned)target_component);
#endif
                    _mavlink_resend_uart(routes[i].channel, msg);
                }
                forwarded = true;
            }
        }
    }
    if (!forwarded && match_system) {
        process_locally = true;
    }

    return process_locally;
}
Пример #3
0
// -----------------------------------------------------------------------
// handle the resurrection spell
// -----------------------------------------------------------------------
bool t_resurrection_spell::can_cast( t_screen_point const& point ) const
{
	t_map_point_2d         map_point;

	if (!m_battlefield.cell_hit_test( point, map_point ))
		return false;
	if (!m_battlefield.can_see_cell( *get_caster(), map_point ))
		return false;
	return !get_targets( point ).empty();
}
Пример #4
0
int fwparam_sysfs_get_targets(struct list_head *list)
{
	struct dirent *dent;
	DIR *dirfd;
	int rc = 0;

	/* ibft only has one instance */
	get_targets(list, IBFT_SYSFS_ROOT, IBFT_SUBSYS);
	/*
	 * We could have multiple iscsi llds and each lld could have
	 * multiple targets/ethernet ports
	 */
	dirfd = opendir(ISCSI_LLD_ROOT);
	if (!dirfd) {
		rc = ISCSI_ERR_SYSFS_LOOKUP;
		goto done;
	}

	while ((dent = readdir(dirfd))) {
		char lld_root[FILENAMESZ];

		memset(&lld_root, 0 , FILENAMESZ);
		if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
			continue;

		if (strncmp(dent->d_name, ISCSI_LLD_SUBSYS_PREFIX, 10))
			continue;

		snprintf(lld_root, FILENAMESZ, ISCSI_LLD_ROOT"%s/",
			 dent->d_name);
		get_targets(list, lld_root, dent->d_name);
	}
	closedir(dirfd);
done:
	if (!rc && list_empty(list))
		rc = ISCSI_ERR_NO_OBJS_FOUND;
	if (rc)
		fw_free_targets(list);
	return rc;
}
Пример #5
0
static unsigned char mavlink_get_route(unsigned char ch, mavlink_message_t *msg)
{
    int target_sys, target_comp;
    unsigned char i, route = active_channel_mask;

    /* if the message wasn't generated by us
     * mask out source channel 
     * and learn the route */
    if (ch != 255) {
        route &= ~(1 << ch);
        mavlink_learn_route(ch, msg);
    }

    /* heartbeats goes to all channels except origin */
    if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT)
        return route;

    get_targets(msg, &target_sys, &target_comp);

    /* its for us - don't route */
    if ((target_sys == config.mav.osd_sysid) && (target_comp == MAV_COMP_ID_OSD))
        return 0;

    /* broadcast message - route to all active ports*/
    if (target_sys <= 0)
        return route;

    /* selective routing - try match sysid and compid */
    route = 0;
    for (i = 0; i < total_routes; i++) {
        if (target_sys == routes[i].sysid &&
                    (target_comp <= 0 || target_comp == routes[i].compid) &&
                    routes[i].ch != ch) {
            route |= 1 << routes[i].ch;
        }
    }
    if (route)
        return route;

    /* try forwarding to any route that match the sysid */
    route = 0;
    for (i = 0; i < total_routes; i++) {
        if (target_sys == routes[i].sysid && routes[i].ch != ch) {
            route |= 1 << routes[i].ch;
        }
    }
    return route;
}
Пример #6
0
static unsigned char mavlink_get_route(unsigned char ch, mavlink_message_t *msg)
{
    int target_sys, target_comp;
    unsigned char i;
    
    unsigned char route = active_channel_mask;

    /* if the message wasn't generated by us, mask out source channel */
    if (ch != 255) {
        route &= ~(1 << ch);
        mavlink_learn_route(ch, msg);
    }

    /* heartbeats goes to all channels except origin */
    if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT)
        return route;

    get_targets(msg, &target_sys, &target_comp);

    /* destination is us - done */
    if ((target_sys == osd_sysid) && (target_comp == MAV_COMP_ID_ALCEOSD))
        return 0;

    route = 0;
    for (i = 0; i < total_routes; i++) {
        if ((target_sys <= 0) || (target_sys == routes[i].sysid &&
                                  (target_comp <= 0 ||
                                   target_comp == routes[i].compid))) {
            if (routes[i].ch != ch) {
                route |= 1 << routes[i].ch;
#ifdef ROUTING_DEBUG
            /*printf("fwd msg %u from chan %u to chan %u sysid=%d compid=%d\n",
                     msg->msgid,
                     (unsigned)ch,
                     (unsigned)routes[i].ch,
                     (int)target_sys,
                     (int)target_comp);*/
#endif
            }
        }
    }
    return route;
}
Пример #7
0
t_mouse_window* t_resurrection_spell::mouse_move( t_screen_point const& point,
										          std::string& help_text )
{
	t_map_point_2d         map_point;
	t_combat_creature_list creatures;
	t_mouse_window*        result;
	t_combat_creature*     caster = get_caster();
	t_combat_creature*     target = 0;
	t_battlefield&		   battlefield = m_battlefield;
	
	result = m_battlefield.get_blocked_cursor();
	if (!battlefield.cell_hit_test( point, map_point ))
		return result;

	creatures = get_targets( point );
	if (creatures.empty())
	{
		t_battlefield_cell& cell = battlefield.get_cell( map_point );
		bool                defender = caster->belongs_to_defender();

		battlefield.select_target( 0 );
		creatures = battlefield.get_creatures_with_casualties( point, true, true );
		if (creatures.empty())
			target = battlefield.creature_hit_test( point );
		else
			target = creatures.front().get();
		if (target == 0)
			return result;
		result = m_battlefield.get_spell_cannot_cast_cursor();
		can_cast_on( target, &help_text);
		return result;
	}
	target = creatures.front().get();
	m_battlefield.select_target( target );
	help_text = get_text( target );
	return get_spell_cursor();
}
Пример #8
0
 /// Default-construct a new instance of a \a target_distribution_policy.
 /// This policy will represent all devices on the current locality.
 ///
 target_distribution_policy()
   : targets_(get_targets()), num_partitions_(1), next_target_(0)
 {}
Пример #9
0
void PlayerInst::use_weapon(GameState* gs, const GameAction& action) {
    WeaponEntry& wentry = weapon().weapon_entry();
    MTwist& mt = gs->rng();
    const int MAX_MELEE_HITS = 10;
    EffectiveStats& estats = effective_stats();
    if (!cooldowns().can_doaction()) {
        return;
    }

    Pos start(x, y);
    Pos actpos(action.action_x, action.action_y);

    if (wentry.uses_projectile && !equipment().has_projectile()) {
        return;
    }

    int cooldown = 0;

    if (equipment().has_projectile()) {
        const Projectile& projectile = equipment().projectile;
        ProjectileEntry& pentry = projectile.projectile_entry();
        item_id item = get_item_by_name(pentry.name.c_str());
        int weaprange = std::max(wentry.range, pentry.range);

        AttackStats weaponattack(weapon());

        bool wallbounce = false;
        int nbounces = 0;
        float movespeed = pentry.speed;

        cooldown = std::max(wentry.cooldown, pentry.cooldown);

        //XXX: Horrible hack REMOVE THIS LATER
        if (class_stats().class_type().name == "Archer"
                && pentry.weapon_class == "bows") {
            int xplevel = class_stats().xplevel;
            float movebonus = class_stats().xplevel / 4.0f;
            if (movebonus > 2) {
                movebonus = 2;
            }
            float cooldown_mult = 1.0f - (class_stats().xplevel - 1) / 20.0f;
            if (cooldown_mult <= 0.85) {
                cooldown_mult = 0.85;
            }
            cooldown *= cooldown_mult;
            movespeed += movebonus;
            if (xplevel >= 3 && core_stats().mp >= 5) {
                nbounces = 2;
                core_stats().mp -= 5;
            }
        }

        GameInst* bullet = new ProjectileInst(projectile,
                                              effective_atk_stats(mt, weaponattack), id, start, actpos,
                                              movespeed, weaprange, NONE, wallbounce, nbounces);
        gs->add_instance(bullet);
        equipment().use_ammo();
    } else {
        int weaprange = wentry.range + this->radius + TILE_SIZE / 2;
        float mag = distance_between(actpos, Pos(x, y));
        if (mag > weaprange) {
            float dx = actpos.x - x, dy = actpos.y - y;
            actpos = Pos(x + dx / mag * weaprange, y + dy / mag * weaprange);
        }

        GameInst* enemies[MAX_MELEE_HITS];

        int max_targets = std::min(MAX_MELEE_HITS, wentry.max_targets);

        int numhit = get_targets(gs, this, actpos.x, actpos.y, wentry.dmgradius,
                                 enemies, max_targets);

        if (numhit == 0) {
            return;
        }

        for (int i = 0; i < numhit; i++) {
            EnemyInst* e = (EnemyInst*)enemies[i];
            lua_hit_callback(gs->get_luastate(), wentry.on_hit_func, this, e);
            if (attack(gs, e, AttackStats(equipment().weapon))) {
                PlayerData& pc = gs->player_data();
                signal_killed_enemy();

                char buffstr[32];
                int amnt = round(
                               double(e->xpworth()) / pc.all_players().size());
                players_gain_xp(gs, amnt);
                snprintf(buffstr, 32, "%d XP", amnt);
                gs->add_instance(
                    new AnimatedInst(Pos(e->x - 5, e->y - 5), -1, 25,
                                     Posf(), Posf(), AnimatedInst::DEPTH, buffstr,
                                     Colour(255, 215, 11)));
            }
        }
        cooldown = wentry.cooldown;
    }

    cooldowns().reset_action_cooldown(cooldown * estats.cooldown_mult);

    reset_rest_cooldown();
}
Пример #10
0
/*
  forward a MAVLink message to the right port. This also
  automatically learns the route for the sender if it is not
  already known.
  
  This returns true if the message should be processed locally

  Theory of MAVLink routing:

  When a flight controller receives a message it should process it
  locally if any of these conditions hold:

    1a) the message has no target_system field

    1b) the message has a target_system of zero

    1c) the message has the flight controllers target system and has no
       target_component field

    1d) the message has the flight controllers target system and has
       the flight controllers target_component 

    1e) the message has the flight controllers target system and the
        flight controller has not seen any messages on any of its links
        from a system that has the messages
        target_system/target_component combination

  When a flight controller receives a message it should forward it
  onto another different link if any of these conditions hold for that
  link: 

    2a) the message has no target_system field

    2b) the message has a target_system of zero

    2c) the message does not have the flight controllers target_system
        and the flight controller has seen a message from the messages
        target_system on the link

    2d) the message has the flight controllers target_system and has a
        target_component field and the flight controllers has seen a
        message from the target_system/target_component combination on
        the link

Note: This proposal assumes that ground stations will not send command
packets to a non-broadcast destination (sysid/compid combination)
until they have received at least one package from that destination
over the link. This is essential to prevent a flight controller from
acting on a message that is not meant for it. For example, a PARAM_SET
cannot be sent to a specific sysid/compid combination until the GCS
has seen a packet from that sysid/compid combination on the link. 

The GCS must also reset what sysid/compid combinations it has seen on
a link when it sees a SYSTEM_TIME message with a decrease in
time_boot_ms from a particular sysid/compid. That is essential to
detect a reset of the flight controller, which implies a reset of its
routing table.

*/
bool MAVLink_routing::check_and_forward(mavlink_channel_t in_channel, const mavlink_message_t* msg)
{
    // handle the case of loopback of our own messages, due to
    // incorrect serial configuration.
    if (msg->sysid == mavlink_system.sysid && 
        msg->compid == mavlink_system.compid) {
        return true;
    }

    // learn new routes
    learn_route(in_channel, msg);

    if (msg->msgid == MAVLINK_MSG_ID_RADIO ||
        msg->msgid == MAVLINK_MSG_ID_RADIO_STATUS) {
        // don't forward RADIO packets
        return true;
    }
    
    if (msg->msgid == MAVLINK_MSG_ID_HEARTBEAT) {
        // heartbeat needs special handling
        handle_heartbeat(in_channel, msg);
        return true;
    }

    // extract the targets for this packet
    int16_t target_system = -1;
    int16_t target_component = -1;
    get_targets(msg, target_system, target_component);

    bool broadcast_system = (target_system == 0 || target_system == -1);
    bool broadcast_component = (target_component == 0 || target_component == -1);
    bool match_system = broadcast_system || (target_system == mavlink_system.sysid);
    bool match_component = match_system && (broadcast_component || 
                                            (target_component == mavlink_system.compid));
    bool process_locally = match_system && match_component;

    if (process_locally && !broadcast_system && !broadcast_component) {
        // nothing more to do - it can only be for us
        return true;
    }

    // forward on any channels matching the targets
    bool forwarded = false;
    bool sent_to_chan[MAVLINK_COMM_NUM_BUFFERS];
    memset(sent_to_chan, 0, sizeof(sent_to_chan));
    for (uint8_t i=0; i<num_routes; i++) {
        if (broadcast_system || (target_system == routes[i].sysid &&
                                 (broadcast_component || 
                                  target_component == routes[i].compid ||
                                  !match_system))) {
            if (in_channel != routes[i].channel && !sent_to_chan[routes[i].channel]) {
                if (comm_get_txspace(routes[i].channel) >= ((uint16_t)msg->len) +
                    GCS_MAVLINK::packet_overhead_chan(routes[i].channel)) {
#if ROUTING_DEBUG
                    ::printf("fwd msg %u from chan %u on chan %u sysid=%d compid=%d\n",
                             msg->msgid,
                             (unsigned)in_channel,
                             (unsigned)routes[i].channel,
                             (int)target_system,
                             (int)target_component);
#endif
                    _mavlink_resend_uart(routes[i].channel, msg);
                }
                sent_to_chan[routes[i].channel] = true;
                forwarded = true;
            }
        }
    }
    if (!forwarded && match_system) {
        process_locally = true;
    }

    return process_locally;
}