aiming cone attacks like fire-breath in any direction
Posted: Tue Mar 01, 2011 8:42 pm
Being able to aim cone attacks in any direction is a beautiful thing! No longer will you need to choose one of eight directions if you follow these simple steps
First, define a new function in "src/fov/fov.h"Second, download the attachment "fov.c-append" and append it to "src/fov/fov.c".
Third, define it's usage in "src/fov.c"and don't forget to define the Lua binding in "fovlib" at the end of the file "src/fov.c":After this, you can call "calc_beam_any_angle" wherever you wish in lua! For example, for cone attacks, change line 136 in "game/engines/default/engine/Target.lua" fromtoand that should do it! Oh, except for the graphics...

First, define a new function in "src/fov/fov.h"
Code: Select all
void fov_beam_any_angle(fov_settings_type *settings, void *map, void *source,
int source_x, int source_y, unsigned radius,
float dir_angle, float beam_angle
);
Third, define it's usage in "src/fov.c"
Code: Select all
static int lua_fov_calc_beam_any_angle(lua_State *L)
{
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int w = luaL_checknumber(L, 3);
int h = luaL_checknumber(L, 4);
int radius = luaL_checknumber(L, 5);
float dir_angle = luaL_checknumber(L, 6);
float beam_angle = luaL_checknumber(L, 7);
struct lua_fov fov;
if (lua_isuserdata(L, 10))
{
fov.cache = (struct lua_fovcache*)auxiliar_checkclass(L, "fov{cache}", 10);
fov.cache_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}
else
{
lua_pop(L, 1);
fov.cache_ref = LUA_NOREF;
fov.cache = NULL;
}
fov.L = L;
fov.apply_ref = luaL_ref(L, LUA_REGISTRYINDEX);
fov.opaque_ref = luaL_ref(L, LUA_REGISTRYINDEX);
fov.cache = NULL;
fov.w = w;
fov.h = h;
fov_settings_init(&(fov.fov_settings));
fov_settings_set_opacity_test_function(&(fov.fov_settings), map_opaque);
fov_settings_set_apply_lighting_function(&(fov.fov_settings), map_seen);
fov_beam_any_angle(&(fov.fov_settings), &fov, NULL, x, y, radius+1, dir_angle, beam_angle);
map_seen(&fov, x, y, 0, 0, radius, NULL);
fov_settings_free(&(fov.fov_settings));
luaL_unref(L, LUA_REGISTRYINDEX, fov.apply_ref);
luaL_unref(L, LUA_REGISTRYINDEX, fov.opaque_ref);
if (fov.cache_ref != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, fov.cache_ref);
return 0;
}
Code: Select all
{"calc_beam_any_angle", lua_fov_calc_beam_any_angle},
Code: Select all
initial_dir,
Code: Select all
math.deg(math.atan2(self.target.y - self.source_actor.y, self.target.x - self.source_actor.x))