Skip to content
Snippets Groups Projects
Commit 13502579 authored by dg's avatar dg
Browse files

Fix some core lua code, maybe remove some random rare crash

Nerf flurry somewhat


git-svn-id: http://svn.net-core.org/repos/t-engine4@2494 51575b47-30f0-44d4-a5cc-537603b46e54
parent 751fe073
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,7 @@ newTalent{
if math.floor(core.fov.distance(self.x, self.y, x, y)) > 1 then return nil end
-- First attack with offhand
local speed, hit = self:attackTargetWith(target, offweapon.combat, nil, self:combatTalentWeaponDamage(t, 0.7, 1.7))
local speed, hit = self:attackTargetWith(target, offweapon.combat, nil, self:combatTalentWeaponDamage(t, 0.7, 1.5))
-- Second attack with mainhand
if hit then
......@@ -142,7 +142,7 @@ newTalent{
end
-- Attack after the stun, to benefit from backstabs
self:attackTargetWith(target, weapon.combat, nil, self:combatTalentWeaponDamage(t, 0.7, 1.7))
self:attackTargetWith(target, weapon.combat, nil, self:combatTalentWeaponDamage(t, 0.7, 1.5))
end
return true
......@@ -150,9 +150,9 @@ newTalent{
info = function(self, t)
return ([[Hit with your offhand weapon for %d%% damage. If the attack hits, the target is stunned for %d turns and you hit it with your mainhand weapon doing %d%% damage.
Stun chance increase with your Dexterity stat.]])
:format(100 * self:combatTalentWeaponDamage(t, 0.7, 1.7),
:format(100 * self:combatTalentWeaponDamage(t, 0.7, 1.5),
2 + self:getTalentLevel(t),
100 * self:combatTalentWeaponDamage(t, 0.7, 1.7))
100 * self:combatTalentWeaponDamage(t, 0.7, 1.5))
end,
}
......@@ -178,14 +178,14 @@ newTalent{
local x, y, target = self:getTarget(tg)
if not x or not y or not target then return nil end
if math.floor(core.fov.distance(self.x, self.y, x, y)) > 1 then return nil end
self:attackTarget(target, nil, self:combatTalentWeaponDamage(t, 0.5, 1.4), true)
self:attackTarget(target, nil, self:combatTalentWeaponDamage(t, 0.5, 1.4), true)
self:attackTarget(target, nil, self:combatTalentWeaponDamage(t, 0.5, 1.4), true)
self:attackTarget(target, nil, self:combatTalentWeaponDamage(t, 0.4, 1.0), true)
self:attackTarget(target, nil, self:combatTalentWeaponDamage(t, 0.4, 1.0), true)
self:attackTarget(target, nil, self:combatTalentWeaponDamage(t, 0.4, 1.0), true)
return true
end,
info = function(self, t)
return ([[Lashes out with a flurry of blows, hitting your target three times with each weapon for %d%% damage.]]):format(100 * self:combatTalentWeaponDamage(t, 0.5, 1.4))
return ([[Lashes out with a flurry of blows, hitting your target three times with each weapon for %d%% damage.]]):format(100 * self:combatTalentWeaponDamage(t, 0.4, 1.0))
end,
}
......
......@@ -18,6 +18,11 @@ newoption {
value = "VM_Type",
description = "Links libraries relative to the application path for redistribution",
}
newoption {
trigger = "luaassert",
value = "VM_Type",
description = "Enable lua asserts to debug lua C code",
}
_OPTIONS.lua = _OPTIONS.lua or "default"
......@@ -69,6 +74,7 @@ configuration "Debug"
flags { "Symbols" }
buildoptions { "-ggdb" }
targetdir "bin/Debug"
if _OPTIONS.luaassert then defines {"LUA_USE_APICHECK"} end
configuration "Release"
defines { "NDEBUG=1" }
......
......@@ -2371,5 +2371,7 @@ int luaopen_core(lua_State *L)
luaL_openlib(L, "rng", rnglib, 0);
luaL_openlib(L, "line", linelib, 0);
luaL_openlib(L, "fs", fslib, 0);
lua_pop(L, 8);
return 1;
}
......@@ -450,5 +450,6 @@ int luaopen_fov(lua_State *L)
{
auxiliar_newclass(L, "fov{cache}", fovcache_reg);
luaL_openlib(L, "core.fov", fovlib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -2253,6 +2253,7 @@ int luaopen_lpeg (lua_State *L) {
lua_pushliteral(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -4);
lua_pop(L, 2);
return 1;
}
......@@ -198,6 +198,7 @@ static struct luaL_reg md5lib[] = {
int luaopen_md5_core (lua_State *L) {
luaL_openlib(L, "md5.core", md5lib, 0);
set_info (L);
lua_pop(L, 1);
return 1;
}
......@@ -226,5 +226,6 @@ int luaopen_profiler(lua_State *L) {
lua_pushliteral (L, "_VERSION");
lua_pushliteral (L, "2.0.1");
lua_settable (L, -3);
lua_pop(L, 1);
return 1;
}
......@@ -117,5 +117,6 @@ LUASOCKET_API int luaopen_socket_core(lua_State *L) {
int i;
base_open(L);
for (i = 0; mod[i].name; i++) mod[i].func(L);
lua_pop(L, 2);
return 1;
}
......@@ -43,7 +43,7 @@ static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
static void qpsetup(UC *qpclass, UC *qpunbase);
static void qpquote(UC c, luaL_Buffer *buffer);
static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
static size_t qpencode(UC c, UC *input, size_t size,
static size_t qpencode(UC c, UC *input, size_t size,
const char *marker, luaL_Buffer *buffer);
static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer);
......@@ -91,6 +91,7 @@ MIME_API int luaopen_mime_core(lua_State *L)
/* initialize lookup tables */
qpsetup(qpclass, qpunbase);
b64setup(b64unbase);
lua_pop(L, 1);
return 1;
}
......@@ -100,9 +101,9 @@ MIME_API int luaopen_mime_core(lua_State *L)
/*-------------------------------------------------------------------------*\
* Incrementaly breaks a string into lines. The string can have CRLF breaks.
* A, n = wrp(l, B, length)
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
\*-------------------------------------------------------------------------*/
static int mime_global_wrp(lua_State *L)
{
......@@ -120,7 +121,7 @@ static int mime_global_wrp(lua_State *L)
else lua_pushnil(L);
lua_pushnumber(L, length);
return 2;
}
}
luaL_buffinit(L, &buffer);
while (input < last) {
switch (*input) {
......@@ -147,9 +148,9 @@ static int mime_global_wrp(lua_State *L)
}
/*-------------------------------------------------------------------------*\
* Fill base64 decode map.
* Fill base64 decode map.
\*-------------------------------------------------------------------------*/
static void b64setup(UC *b64unbase)
static void b64setup(UC *b64unbase)
{
int i;
for (i = 0; i <= 255; i++) b64unbase[i] = (UC) 255;
......@@ -158,11 +159,11 @@ static void b64setup(UC *b64unbase)
}
/*-------------------------------------------------------------------------*\
* Acumulates bytes in input buffer until 3 bytes are available.
* Acumulates bytes in input buffer until 3 bytes are available.
* Translate the 3 bytes into Base64 form and append to buffer.
* Returns new number of bytes in buffer.
\*-------------------------------------------------------------------------*/
static size_t b64encode(UC c, UC *input, size_t size,
static size_t b64encode(UC c, UC *input, size_t size,
luaL_Buffer *buffer)
{
input[size++] = c;
......@@ -171,7 +172,7 @@ static size_t b64encode(UC c, UC *input, size_t size,
unsigned long value = 0;
value += input[0]; value <<= 8;
value += input[1]; value <<= 8;
value += input[2];
value += input[2];
code[3] = b64base[value & 0x3f]; value >>= 6;
code[2] = b64base[value & 0x3f]; value >>= 6;
code[1] = b64base[value & 0x3f]; value >>= 6;
......@@ -183,11 +184,11 @@ static size_t b64encode(UC c, UC *input, size_t size,
}
/*-------------------------------------------------------------------------*\
* Encodes the Base64 last 1 or 2 bytes and adds padding '='
* Encodes the Base64 last 1 or 2 bytes and adds padding '='
* Result, if any, is appended to buffer.
* Returns 0.
\*-------------------------------------------------------------------------*/
static size_t b64pad(const UC *input, size_t size,
static size_t b64pad(const UC *input, size_t size,
luaL_Buffer *buffer)
{
unsigned long value = 0;
......@@ -200,7 +201,7 @@ static size_t b64pad(const UC *input, size_t size,
luaL_addlstring(buffer, (char *) code, 4);
break;
case 2:
value = input[0]; value <<= 8;
value = input[0]; value <<= 8;
value |= input[1]; value <<= 2;
code[2] = b64base[value & 0x3f]; value >>= 6;
code[1] = b64base[value & 0x3f]; value >>= 6;
......@@ -214,11 +215,11 @@ static size_t b64pad(const UC *input, size_t size,
}
/*-------------------------------------------------------------------------*\
* Acumulates bytes in input buffer until 4 bytes are available.
* Acumulates bytes in input buffer until 4 bytes are available.
* Translate the 4 bytes from Base64 form and append to buffer.
* Returns new number of bytes in buffer.
\*-------------------------------------------------------------------------*/
static size_t b64decode(UC c, UC *input, size_t size,
static size_t b64decode(UC c, UC *input, size_t size,
luaL_Buffer *buffer)
{
/* ignore invalid characters */
......@@ -236,7 +237,7 @@ static size_t b64decode(UC c, UC *input, size_t size,
decoded[1] = (UC) (value & 0xff); value >>= 8;
decoded[0] = (UC) value;
/* take care of paddding */
valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3;
valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3;
luaL_addlstring(buffer, (char *) decoded, valid);
return 0;
/* need more data */
......@@ -248,7 +249,7 @@ static size_t b64decode(UC c, UC *input, size_t size,
* A, B = b64(C, D)
* A is the encoded version of the largest prefix of C .. D that is
* divisible by 3. B has the remaining bytes of C .. D, *without* encoding.
* The easiest thing would be to concatenate the two strings and
* The easiest thing would be to concatenate the two strings and
* encode the result, but we can't afford that or Lua would dupplicate
* every chunk we received.
\*-------------------------------------------------------------------------*/
......@@ -267,7 +268,7 @@ static int mime_global_b64(lua_State *L)
}
/* process first part of the input */
luaL_buffinit(L, &buffer);
while (input < last)
while (input < last)
asize = b64encode(*input++, atom, asize, &buffer);
input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
/* if second part is nil, we are done */
......@@ -280,7 +281,7 @@ static int mime_global_b64(lua_State *L)
}
/* otherwise process the second part */
last = input + isize;
while (input < last)
while (input < last)
asize = b64encode(*input++, atom, asize, &buffer);
luaL_pushresult(&buffer);
lua_pushlstring(L, (char *) atom, asize);
......@@ -308,7 +309,7 @@ static int mime_global_unb64(lua_State *L)
}
/* process first part of the input */
luaL_buffinit(L, &buffer);
while (input < last)
while (input < last)
asize = b64decode(*input++, atom, asize, &buffer);
input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
/* if second is nil, we are done */
......@@ -320,7 +321,7 @@ static int mime_global_unb64(lua_State *L)
}
/* otherwise, process the rest of the input */
last = input + isize;
while (input < last)
while (input < last)
asize = b64decode(*input++, atom, asize, &buffer);
luaL_pushresult(&buffer);
lua_pushlstring(L, (char *) atom, asize);
......@@ -336,7 +337,7 @@ static int mime_global_unb64(lua_State *L)
* 9 and 32 can be plain, unless in the end of a line, where must be =XX
* encoded lines must be no longer than 76 not counting CRLF
* soft line-break are =CRLF
* To encode one byte, we need to see the next two.
* To encode one byte, we need to see the next two.
* Worst case is when we see a space, and wonder if a CRLF is comming
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*\
......@@ -349,7 +350,7 @@ static void qpsetup(UC *qpclass, UC *qpunbase)
for (i = 0; i < 256; i++) qpclass[i] = QP_QUOTED;
for (i = 33; i <= 60; i++) qpclass[i] = QP_PLAIN;
for (i = 62; i <= 126; i++) qpclass[i] = QP_PLAIN;
qpclass['\t'] = QP_IF_LAST;
qpclass['\t'] = QP_IF_LAST;
qpclass[' '] = QP_IF_LAST;
qpclass['\r'] = QP_CR;
for (i = 0; i < 256; i++) qpunbase[i] = 255;
......@@ -375,9 +376,9 @@ static void qpquote(UC c, luaL_Buffer *buffer)
/*-------------------------------------------------------------------------*\
* Accumulate characters until we are sure about how to deal with them.
* Once we are sure, output to the buffer, in the correct form.
* Once we are sure, output to the buffer, in the correct form.
\*-------------------------------------------------------------------------*/
static size_t qpencode(UC c, UC *input, size_t size,
static size_t qpencode(UC c, UC *input, size_t size,
const char *marker, luaL_Buffer *buffer)
{
input[size++] = c;
......@@ -418,7 +419,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
}
/*-------------------------------------------------------------------------*\
* Deal with the final characters
* Deal with the final characters
\*-------------------------------------------------------------------------*/
static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
{
......@@ -435,8 +436,8 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
* Incrementally converts a string to quoted-printable
* A, B = qp(C, D, marker)
* Marker is the text to be used to replace CRLF sequences found in A.
* A is the encoded version of the largest prefix of C .. D that
* can be encoded without doubts.
* A is the encoded version of the largest prefix of C .. D that
* can be encoded without doubts.
* B has the remaining bytes of C .. D, *without* encoding.
\*-------------------------------------------------------------------------*/
static int mime_global_qp(lua_State *L)
......@@ -478,7 +479,7 @@ static int mime_global_qp(lua_State *L)
/*-------------------------------------------------------------------------*\
* Accumulate characters until we are sure about how to deal with them.
* Once we are sure, output the to the buffer, in the correct form.
* Once we are sure, output the to the buffer, in the correct form.
\*-------------------------------------------------------------------------*/
static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
int d;
......@@ -486,8 +487,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
/* deal with all characters we can deal */
switch (input[0]) {
/* if we have an escape character */
case '=':
if (size < 3) return size;
case '=':
if (size < 3) return size;
/* eliminate soft line break */
if (input[1] == '\r' && input[2] == '\n') return 0;
/* decode quoted representation */
......@@ -497,7 +498,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
else luaL_putchar(buffer, (c << 4) + d);
return 0;
case '\r':
if (size < 2) return size;
if (size < 2) return size;
if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2);
return 0;
default:
......@@ -510,8 +511,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
/*-------------------------------------------------------------------------*\
* Incrementally decodes a string in quoted-printable
* A, B = qp(C, D)
* A is the decoded version of the largest prefix of C .. D that
* can be decoded without doubts.
* A is the decoded version of the largest prefix of C .. D that
* can be decoded without doubts.
* B has the remaining bytes of C .. D, *without* decoding.
\*-------------------------------------------------------------------------*/
static int mime_global_unqp(lua_State *L)
......@@ -538,7 +539,7 @@ static int mime_global_unqp(lua_State *L)
if (!(*lua_tostring(L, -1))) lua_pushnil(L);
lua_pushnil(L);
return 2;
}
}
/* otherwise process rest of input */
last = input + isize;
while (input < last)
......@@ -551,9 +552,9 @@ static int mime_global_unqp(lua_State *L)
/*-------------------------------------------------------------------------*\
* Incrementally breaks a quoted-printed string into lines
* A, n = qpwrp(l, B, length)
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
* There are two complications: lines can't be broken in the middle
* of an encoded =XX, and there might be line breaks already
\*-------------------------------------------------------------------------*/
......@@ -586,11 +587,11 @@ static int mime_global_qpwrp(lua_State *L)
if (left <= 3) {
left = length;
luaL_addstring(&buffer, EQCRLF);
}
}
luaL_putchar(&buffer, *input);
left--;
break;
default:
default:
if (left <= 1) {
left = length;
luaL_addstring(&buffer, EQCRLF);
......@@ -618,7 +619,7 @@ static int mime_global_qpwrp(lua_State *L)
* last is the previous character
\*-------------------------------------------------------------------------*/
#define eolcandidate(c) (c == '\r' || c == '\n')
static int eolprocess(int c, int last, const char *marker,
static int eolprocess(int c, int last, const char *marker,
luaL_Buffer *buffer)
{
if (eolcandidate(c)) {
......@@ -636,10 +637,10 @@ static int eolprocess(int c, int last, const char *marker,
}
/*-------------------------------------------------------------------------*\
* Converts a string to uniform EOL convention.
* Converts a string to uniform EOL convention.
* A, n = eol(o, B, marker)
* A is the converted version of the largest prefix of B that can be
* converted unambiguously. 'o' is the context returned by the previous
* converted unambiguously. 'o' is the context returned by the previous
* call. 'n' is the new context.
\*-------------------------------------------------------------------------*/
static int mime_global_eol(lua_State *L)
......@@ -666,18 +667,18 @@ static int mime_global_eol(lua_State *L)
}
/*-------------------------------------------------------------------------*\
* Takes one byte and stuff it if needed.
* Takes one byte and stuff it if needed.
\*-------------------------------------------------------------------------*/
static size_t dot(int c, size_t state, luaL_Buffer *buffer)
{
luaL_putchar(buffer, c);
switch (c) {
case '\r':
case '\r':
return 1;
case '\n':
return (state == 1)? 2: 0;
case '.':
if (state == 2)
case '\n':
return (state == 1)? 2: 0;
case '.':
if (state == 2)
luaL_putchar(buffer, '.');
default:
return 0;
......@@ -702,7 +703,7 @@ static int mime_global_dot(lua_State *L)
}
/* process all input */
luaL_buffinit(L, &buffer);
while (input < last)
while (input < last)
state = dot(*input++, state, &buffer);
luaL_pushresult(&buffer);
lua_pushnumber(L, state);
......
......@@ -535,6 +535,7 @@ int luaopen_lxp (lua_State *L) {
luaL_openlib (L, NULL, lxp_meths, 0);
luaL_openlib (L, "lxp", lxp_funcs, 0);
set_info (L);
lua_pop(L, 2);
return 1;
}
......@@ -84,6 +84,7 @@ static int traceback (lua_State *L) {
int docall (lua_State *L, int narg, int nret)
{
// printf("<===%d\n", lua_gettop(L));
int status;
int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */
......@@ -92,6 +93,7 @@ int docall (lua_State *L, int narg, int nret)
lua_remove(L, base); /* remove traceback function */
/* force a complete garbage collection in case of errors */
if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
// printf(">===%d\n", lua_gettop(L));
return status;
}
......@@ -260,7 +262,7 @@ void on_tick()
lua_rawgeti(L, LUA_REGISTRYINDEX, current_game);
docall(L, 1, 1);
tickPaused = lua_toboolean(L, -1);
// lua_pop(L, 1);
lua_pop(L, 1);
}
/* Gather our frames per second */
......
......@@ -1128,5 +1128,6 @@ int luaopen_map(lua_State *L)
auxiliar_newclass(L, "core{map}", map_reg);
auxiliar_newclass(L, "core{mapobj}", map_object_reg);
luaL_openlib(L, "core.map", maplib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -228,5 +228,6 @@ int luaopen_sound(lua_State *L)
auxiliar_newclass(L, "core{music}", music_reg);
auxiliar_newclass(L, "core{sound}", sound_reg);
luaL_openlib(L, "core.sound", soundlib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -392,5 +392,6 @@ int luaopen_noise(lua_State *L)
{
auxiliar_newclass(L, "noise{core}", noise_reg);
luaL_openlib(L, "core.noise", noiselib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -263,6 +263,7 @@ static int particles_emit(lua_State *L)
getparticulefield(L, "av", &(p->av));
getparticulefield(L, "aa", &(p->aa));
}
lua_pop(L, 1);
}
p->ox = p->x;
p->oy = p->y;
......@@ -385,8 +386,6 @@ static int particles_update(lua_State *L)
int i, j;
bool alive = FALSE;
glBindTexture(GL_TEXTURE_2D, ps->texture);
for (w = 0; w < ps->nb; w++)
{
particle_type *p = &ps->particles[w];
......@@ -456,5 +455,6 @@ int luaopen_particles(lua_State *L)
lua_pushstring(L, "ETERNAL");
lua_pushnumber(L, PARTICLE_ETERNAL);
lua_settable(L, -3);
lua_pop(L, 1);
return 1;
}
......@@ -450,5 +450,6 @@ int luaopen_gas(lua_State *L)
{
auxiliar_newclass(L, "core{gas}", gas_reg);
luaL_openlib(L, "core.gas", gaslib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -433,5 +433,6 @@ int luaopen_serial(lua_State *L)
{
auxiliar_newclass(L, "core{serial}", serial_reg);
luaL_openlib(L, "core.serial", seriallib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -306,5 +306,6 @@ int luaopen_shaders(lua_State *L)
auxiliar_newclass(L, "gl{program}", program_reg);
luaL_openlib(L, "core.shader", shaderlib, 0);
lua_pop(L, 1);
return 1;
}
......@@ -324,6 +324,7 @@ static const struct luaL_reg thislib[] = {
LUALIB_API int luaopen_struct (lua_State *L) {
luaL_register(L, "struct", thislib);
lua_pop(L, 1);
return 1;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment