Changeset 46 for ttyvaders


Ignore:
Timestamp:
Dec 23, 2002, 12:01:35 AM (17 years ago)
Author:
Sam Hocevar
Message:
  • fixed a segfault when the target seeker speed was zero.
  • factorized the seeker generation on fragbomb explosion.
Location:
ttyvaders/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/src/math.c

    r44 r46  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: math.c,v 1.1 2002/12/22 22:36:42 sam Exp $
     6 *   $Id: math.c,v 1.2 2002/12/22 23:01:35 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    2727    int x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1;
    2828
    29     /* Newton's method. Three iterations are more than enough. */
     29    if( a <= 0 )
     30    {
     31        return 0;
     32    }
     33
     34    /* Newton's method. Three iterations would be more than enough. */
    3035    x = (x * x + a) / x / 2;
    3136    x = (x * x + a) / x / 2;
  • ttyvaders/trunk/src/weapons.c

    r44 r46  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: weapons.c,v 1.9 2002/12/22 22:36:42 sam Exp $
     6 *   $Id: weapons.c,v 1.10 2002/12/22 23:01:35 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    171171
    172172                /* Normalize and update speed */
    173                 wp->vx[i] = (7 * wp->vx[i]
    174                               + (dx * 48) / r00t(dx*dx+dy*dy) ) / 8;
    175                 wp->vy[i] = (7 * wp->vy[i]
    176                               + (dy * 24) / r00t(dx*dx+dy*dy) ) / 8;
    177 
    178                 break;
     173                if( dx | dy )
     174                {
     175                    int norm = r00t( dx * dx + dy * dy );
     176
     177                    wp->vx[i] = (7 * wp->vx[i] + (dx * 48) / norm ) / 8;
     178                    wp->vy[i] = (7 * wp->vy[i] + (dy * 24) / norm ) / 8;
     179                }
     180                break;
     181
    179182            case WEAPON_FRAGBOMB:
    180                 /* If n was set to -1, the fragbomb exploded */
     183                /* If n was set to -1, the fragbomb just exploded */
    181184                if( wp->n[i] == -1 )
    182185                {
    183                     add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i], 24, 0, WEAPON_SEEKER );
    184                     add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i], -24, 0, WEAPON_SEEKER );
    185                     add_weapon( g, g->wp, wp->x[i], wp->y[i] + 24, 0, 24, WEAPON_SEEKER );
    186                     add_weapon( g, g->wp, wp->x[i], wp->y[i] - 24, 0, -24, WEAPON_SEEKER );
    187                     add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] + 8, 24, 8, WEAPON_SEEKER );
    188                     add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] + 8, -24, 8, WEAPON_SEEKER );
    189                     add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] - 8, 24, -8, WEAPON_SEEKER );
    190                     add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] - 8, -24, -8, WEAPON_SEEKER );
    191                     add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] + 16, 16, 16, WEAPON_SEEKER );
    192                     add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] + 16, -16, 16, WEAPON_SEEKER );
    193                     add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] - 16, 16, -16, WEAPON_SEEKER );
    194                     add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] - 16, -16, -16, WEAPON_SEEKER );
     186                    int coords[] =
     187                    {
     188                        24,  0,   -24,  0,    0,  24,     0, -24,
     189                        24,  8,   -24,  8,   24,  -8,   -24,  -8,
     190                        16, 16,   -16, 16,   16, -16,   -16, -16
     191                    };
     192
     193                    for( j = 0; j < 12; j++ )
     194                    {
     195                        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 );
     196                    }
     197
    195198                    wp->type[i] = WEAPON_NONE;
    196199                }
     
    204207                }
    205208                break;
     209
    206210            case WEAPON_BEAM:
    207211                wp->x[i] = (g->p->x + 2) << 4;
Note: See TracChangeset for help on using the changeset viewer.