Example #1
0
static int impl_unit_attack_equal(lua_State* L)
{
	const_attack_ptr ut1 = luaW_toweapon(L, 1);
	const_attack_ptr ut2 = luaW_toweapon(L, 2);
	lua_pushboolean(L, ut1 == ut2);
	return 1;
}
Example #2
0
static int impl_unit_attack_match(lua_State* L)
{
	const_attack_ptr atk = luaW_toweapon(L, 1);
	config cfg = luaW_checkconfig(L, 2);
	lua_pushboolean(L, atk->matches_filter(cfg));
	return 1;
}
static int impl_unit_attack_match(lua_State* L)
{
	const_attack_ptr atk = luaW_toweapon(L, 1);
	config cfg = luaW_checkconfig(L, 2);
	if(!atk) {
		return luaL_argerror(L, 1, "invalid attack");
	}
	lua_pushboolean(L, atk->matches_filter(cfg));
	return 1;
}
Example #4
0
static int impl_unit_attacks_set(lua_State* L)
{
	if(!lua_istable(L, 1)) {
		return luaW_type_error(L, 1, "unit attacks");
	}
	lua_rawgeti(L, 1, 0);
	const unit_type* ut = luaW_tounittype(L, -1);
	if(ut) {
		return luaL_argerror(L, 1, "unit type attack table is immutable");
	}

	unit& u = luaW_checkunit(L, -1);
	attack_ptr atk = lua_isnumber(L, 2) ? find_attack(&u, luaL_checkinteger(L, 2) - 1) : find_attack(&u, luaL_checkstring(L, 2));
	if(lua_isnumber(L, 2) && lua_tonumber(L, 2) - 1 > u.attacks().size()) {
		return luaL_argerror(L, 2, "attack can only be added at the end of the list");
	}

	if(lua_isnil(L, 3)) {
		// Delete the attack
		u.remove_attack(atk);
		return 0;
	}

	auto iter = get_attack_iter(u, atk), end = u.attacks().end();
	if(const_attack_ptr atk2 = luaW_toweapon(L, 3)) {
		if(iter == end) {
			atk = u.add_attack(end, *atk2);
		} else {
			iter.base()->reset(new attack_type(*atk2));
			atk = *iter.base();
		}
	} else {
		config cfg = luaW_checkconfig(L, 3);
		if(iter == end) {
			atk = u.add_attack(end, cfg);
		} else {
			iter.base()->reset(new attack_type(cfg));
			atk = *iter.base();
		}
	}
	if(!lua_isnumber(L, 2)) {
		atk->set_id(lua_tostring(L, 2));
	}
	return 0;
}