Esempio n. 1
0
void __fastcall GameScreenRClickEvent(Event *event)
{
    if (IsOutsideGameScreen(event->x, event->y) || bw::client_selection_group2[0] == nullptr)
        return;
    Unit *highest_ranked = bw::selection_rank_order[0];
    if (highest_ranked == nullptr || !CanControlUnit(highest_ranked))
        return;

    unsigned i;
    for (i = 0; i < Limits::Selection; i++)
    {
        Unit *unit = bw::client_selection_group[i];
        if (unit == nullptr)
            return;
        if (unit->DoesAcceptRClickCommands())
            break;
    }
    if (i == Limits::Selection)
        return;

    int x = event->x + *bw::screen_x;
    int y = event->y + *bw::screen_y;
    Unit *target = FindUnitAtPoint(x, y);
    if (target == highest_ranked && *bw::client_selection_count == 1)
    {
        if (~highest_ranked->flags & UnitStatus::Building)
            return;
        if (!highest_ranked->HasRally())
            return;
    }
    else if (target == nullptr)
    {
        for (i = 0; i < Limits::Selection; i++)
        {
            Unit *unit = bw::client_selection_group[i];
            if (unit == nullptr)
                return;
            if (unit->CanRClickGround())
                break;
        }
        if (i == Limits::Selection)
            return;
    }
    if (target == nullptr)
    {
        Sprite *fow = ShowCommandResponse(x, y, 0);
        if (fow)
            SendRightClickCommand(0, x, y, fow->index, *bw::is_queuing_command);
        else
            SendRightClickCommand(0, x, y, Unit::None, *bw::is_queuing_command);
    }
    else
    {
        ShowCommandResponse(x, y, target->sprite);
        SendRightClickCommand(target, x, y, Unit::None, *bw::is_queuing_command);
    }

    if (ShowRClickErrorIfNeeded(target) == 1)
        PlayYesSoundAnim(highest_ranked);
}
static inline CUnit* ParseUnit(lua_State* L, const char* caller, int index)
{
	CUnit* unit = unitHandler->GetUnit(luaL_checkint(L, index));

	if (unit == nullptr)
		return nullptr;
	if (!CanControlUnit(L, unit))
		return nullptr;

	return unit;
}
Esempio n. 3
0
static inline CUnit* ParseUnit(lua_State* L, const char* caller, int index)
{
	const int unitID = luaL_checkint(L, index);
	if ((unitID < 0) || (static_cast<size_t>(unitID) >= unitHandler->MaxUnits())) {
		luaL_error(L, "%s(): Bad unitID: %i\n", caller, unitID);
	}
	CUnit* unit = unitHandler->units[unitID];
	if (unit == NULL) {
		return NULL;
	}
	if (!CanControlUnit(L, unit)) {
		return NULL;
	}
	return unit;
}