From b3866d28d9de1cce26e4d3d21db7c7141c2d60f1 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 22 Dec 2002 23:01:35 +0000 Subject: [PATCH] * fixed a segfault when the target seeker speed was zero. * factorized the seeker generation on fragbomb explosion. --- src/math.c | 9 +++++++-- src/weapons.c | 40 ++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/math.c b/src/math.c index 24bb71d..f2ae9ad 100644 --- a/src/math.c +++ b/src/math.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: math.c,v 1.1 2002/12/22 22:36:42 sam Exp $ + * $Id: math.c,v 1.2 2002/12/22 23:01:35 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +26,12 @@ int r00t( int a ) { int x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1; - /* Newton's method. Three iterations are more than enough. */ + if( a <= 0 ) + { + return 0; + } + + /* Newton's method. Three iterations would be more than enough. */ x = (x * x + a) / x / 2; x = (x * x + a) / x / 2; x = (x * x + a) / x / 2; diff --git a/src/weapons.c b/src/weapons.c index 6d512fd..71deaa3 100644 --- a/src/weapons.c +++ b/src/weapons.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: weapons.c,v 1.9 2002/12/22 22:36:42 sam Exp $ + * $Id: weapons.c,v 1.10 2002/12/22 23:01:35 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -170,28 +170,31 @@ void update_weapons( game *g, weapons *wp ) dy = ymin - wp->y[i]; /* Normalize and update speed */ - wp->vx[i] = (7 * wp->vx[i] - + (dx * 48) / r00t(dx*dx+dy*dy) ) / 8; - wp->vy[i] = (7 * wp->vy[i] - + (dy * 24) / r00t(dx*dx+dy*dy) ) / 8; + if( dx | dy ) + { + int norm = r00t( dx * dx + dy * dy ); + wp->vx[i] = (7 * wp->vx[i] + (dx * 48) / norm ) / 8; + wp->vy[i] = (7 * wp->vy[i] + (dy * 24) / norm ) / 8; + } break; + case WEAPON_FRAGBOMB: - /* If n was set to -1, the fragbomb exploded */ + /* If n was set to -1, the fragbomb just exploded */ if( wp->n[i] == -1 ) { - add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i], 24, 0, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i], -24, 0, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i], wp->y[i] + 24, 0, 24, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i], wp->y[i] - 24, 0, -24, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] + 8, 24, 8, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] + 8, -24, 8, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] - 8, 24, -8, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] - 8, -24, -8, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] + 16, 16, 16, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] + 16, -16, 16, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] - 16, 16, -16, WEAPON_SEEKER ); - add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] - 16, -16, -16, WEAPON_SEEKER ); + int coords[] = + { + 24, 0, -24, 0, 0, 24, 0, -24, + 24, 8, -24, 8, 24, -8, -24, -8, + 16, 16, -16, 16, 16, -16, -16, -16 + }; + + for( j = 0; j < 12; j++ ) + { + add_weapon( g, g->wp, wp->x[i] + coords[2*j], wp->y[i] + coords[2*j+1], coords[2*j], coords[2*j+1], WEAPON_SEEKER ); + } + wp->type[i] = WEAPON_NONE; } @@ -203,6 +206,7 @@ void update_weapons( game *g, weapons *wp ) wp->type[i] = WEAPON_NONE; } break; + case WEAPON_BEAM: wp->x[i] = (g->p->x + 2) << 4; wp->y[i] = g->p->y << 4;