DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦639ee6244⟧ TextFile

    Length: 8055 (0x1f77)
    Types: TextFile
    Names: »minisubs.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/X/Xtrek/minisubs.c« 

TextFile

static char sccsid[] = "@(#)minisubs.c	1.1";
#include <X11/Xlib.h>
#include "defs.h"
#include "data.h"

extern long isin[], icos[];

cool_weapons(who)
register struct player	*who;
{
	who->p_wtemp -= PWEAPCOOL;
	if (who->p_wtemp < 0)
		who->p_wtemp = 0;
	if (who->p_flags & PFWEP) {
		if (--who->p_wtime <= 0)
			who->p_flags &= ~PFWEP;
	} else if (who->p_wtemp > 1000) {
		if (!(random() % 40)) {
			who->p_flags |= PFWEP;
			who->p_wtime = (random() % PWEAPLOCKVAR) + PWEAPLOCKMIN;
		}
	}
}

cool_engines(who)
register struct player	*who;
{
	who->p_etemp -= PENGCOOL;
	if (who->p_etemp < 0)
		who->p_etemp = 0;
	if (who->p_flags & PFENG) {
		if (--who->p_etime <= 0)
			who->p_flags &= ~PFENG;
	} else if (who->p_etemp > 1000) {
		if (!(random() % 40)) {
			who->p_flags |= PFENG;
			who->p_etime = (random() % PENGLOCKVAR) + PENGLOCKMIN;
			who->p_desspeed = 0;
		}
	}
}

add_fuel(who)
register struct player *who;
{
	if ((who->p_flags & PFORBIT) && (planets[who->p_planet].pl_flags & PLFUEL) &&
	    (!(planets[who->p_planet].pl_owner & (who->p_swar | who->p_hostile)))) {
		who->p_fuel += PREFUEL * 4 * who->p_ship.s_recharge;
	} else
		who->p_fuel += PREFUEL * who->p_ship.s_recharge;

	if (who->p_fuel > who->p_ship.s_maxfuel)
		who->p_fuel = who->p_ship.s_maxfuel;
	
	if (who->p_fuel < 0) {
		who->p_desspeed = 0;
		who->p_flags &= ~PFCLOAK;	/* should be cloak_off(). */
	}
}

repair_shields(who)
register struct player *who;
{
        if (who->p_shield < 100) {
          if ((who->p_flags & PFREPAIR) && (who->p_speed == 0)) {
            who->p_subshield += who->p_ship.s_repair * PREPAIR * 4;
            if ((who->p_flags & PFORBIT) &&
                (planets[who->p_planet].pl_flags & PLREPAIR) &&
                (!(planets[who->p_planet].pl_owner
                   & (who->p_swar | who->p_hostile)))) {
                who->p_subshield += who->p_ship.s_repair * PREPAIR * 4;
              }
          }
          else
            who->p_subshield += who->p_ship.s_repair * PREPAIR * 2;

          if (who->p_subshield / 1000) {
            who->p_shield += who->p_subshield / 1000;
            who->p_subshield %= 1000;
          }
          if (who->p_shield > 100) {
            who->p_shield = 100;
            who->p_subshield = 0;
          }
        }
}

repair_damage(who)
register struct player *who;
{
        if (who->p_damage && !(who->p_flags & PFSHIELD)) {
          if ((who->p_flags & PFREPAIR) && (who->p_speed == 0)) {
            who->p_subdamage += who->p_ship.s_repair * PREPAIR * 2;
            if ((who->p_flags & PFORBIT) &&
                (planets[who->p_planet].pl_flags & PLREPAIR) &&
                (!(planets[who->p_planet].pl_owner
                   & (who->p_swar | who->p_hostile)))) {
                who->p_subdamage += who->p_ship.s_repair * PREPAIR * 2;
              }
          }
          else
            who->p_subdamage += who->p_ship.s_repair * PREPAIR;
          if (who->p_subdamage / 1000) {
            who->p_damage -= who->p_subdamage / 1000;
            who->p_subdamage %= 1000;
          }
          if (who->p_damage < 0) {
            who->p_damage = 0;
            who->p_subdamage = 0;
          }
        }
}

cloak_charge(who)
register struct player *who;
{
        if (who->p_flags & PFCLOAK) {
          who->p_fuel -= who->p_ship.s_cloakcost * PCLOAKRATE;
        }
}

player_orbit(who)
register struct player *who;
{
        if (who->p_flags & PFORBIT) {
          who->p_dir += 2;
          who->p_desdir = who->p_dir;
          who->p_x = planets[who->p_planet].pl_x +
            ((ORBDIST * icos[(unsigned char) (who->p_dir - (unsigned char) 64)])
                                                >> TRIGSCALE);
          who->p_y = planets[who->p_planet].pl_y + 
            ((ORBDIST * isin[(unsigned char) (who->p_dir - (unsigned char) 64)])
                                                >> TRIGSCALE);
        }
}

space_move(who)
register struct player *who;
{
	if (!(who->p_flags & PFORBIT)) {
          if (who->p_dir != who->p_desdir)
            changedir(who);

          /* Alter speed */
	  alter_speed(who);

          /* Charge for speed */
	  charge_speed(who);

	  /* Move them... */
          who->p_x += (who->p_speed * icos[who->p_dir] * WARP1) >> TRIGSCALE;
          who->p_y += (who->p_speed * isin[who->p_dir] * WARP1) >> TRIGSCALE;

          /* Bounce off the side of the galaxy */
          if (who->p_x < 0) {
            who->p_x = -who->p_x;
            if (who->p_dir == 192)
              who->p_dir = who->p_desdir = 64;
            else
              who->p_dir = who->p_desdir = 64 - (who->p_dir - 192);
          } else if (who->p_x > GWIDTH) {
            who->p_x = GWIDTH - (who->p_x - GWIDTH);
            if (who->p_dir == 64)
              who->p_dir = who->p_desdir = 192;
            else
              who->p_dir = who->p_desdir = 192 - (who->p_dir - 64);
          }
          if (who->p_y < 0) {
            who->p_y = -who->p_y;
            if (who->p_dir == 0)
              who->p_dir = who->p_desdir = 128;
            else
              who->p_dir = who->p_desdir = 128 - who->p_dir;
          } else if (who->p_y > GWIDTH) {
            who->p_y = GWIDTH - (who->p_y - GWIDTH);
            if (who->p_dir == 128)
              who->p_dir = who->p_desdir = 0;
            else
              who->p_dir = who->p_desdir = 0 - (who->p_dir - 128);
          }
	}
}

#define YRANGE ((GWIDTH)/5)
#define RRANGE ((GWIDTH)/10)

adjust_alert(who)
register struct player *who;
{
	register int	k;
	register int	dx, dy, dist;

        who->p_flags |= PFGREEN;
        who->p_flags &= ~(PFRED|PFYELLOW);
        for (k = 0; k < MAXPLAYER; k++) {
          if ((players[k].p_status != PALIVE) ||
              (!((who->p_swar | who->p_hostile) & players[k].p_team))) {
              continue;
	  } else {
            dx = who->p_x - players[k].p_x;
            dy = who->p_y - players[k].p_y;
            if (ABS(dx) > YRANGE || ABS(dy) > YRANGE)
              continue;
            dist = dx * dx + dy * dy;
            if (dist <  RRANGE * RRANGE) {
              who->p_flags |= PFRED;
              who->p_flags &= ~(PFGREEN|PFYELLOW);
            } else if ((dist <  YRANGE * YRANGE) &&
                     (!(who->p_flags & PFRED))) {
                     who->p_flags |= PFYELLOW;
                     who->p_flags &= ~(PFGREEN|PFRED);
	    }
          }
        }
}

alter_speed(who)
register struct player *who;
{
	register int	maxspeed;

          maxspeed = 10 - who->p_damage/10;
          if (who->p_speed > maxspeed && who->p_desspeed > maxspeed)
            who->p_desspeed = maxspeed;
          if (who->p_flags & PFENG)
            who->p_desspeed = 0;

          if (who->p_desspeed > who->p_speed) {
            who->p_subspeed += who->p_ship.s_accint * PACCELRATE;
          }
          if (who->p_desspeed < who->p_speed) {
            who->p_subspeed -= who->p_ship.s_decint * PACCELRATE;
          }
          if (who->p_subspeed / 1000) {
            who->p_speed += who->p_subspeed / 1000;
            who->p_subspeed /= 1000;
            if (who->p_speed < 0)
              who->p_speed = 0;
            if (who->p_speed > who->p_ship.s_maxspeed)
              who->p_speed = who->p_ship.s_maxspeed;
          }
}

charge_speed(who)
register struct player *who;
{
          who->p_fuel -= who->p_ship.s_warpcost * who->p_speed * PFUELRATE;
          who->p_etemp += who->p_speed * PFUELRATE;
}

changedir(sp)
struct player *sp;
{
    int ticks;

    if (sp->p_speed == 0) {
	sp->p_dir = sp->p_desdir;
	sp->p_subdir = 0;
    }
    else {
	sp->p_subdir += (sp->p_ship.s_turns * PTURNRATE) / (1 << sp->p_speed);
	ticks = sp->p_subdir / 1000;
	if (ticks) {
	    if (ticks > dirdiff(sp->p_dir, sp->p_desdir))
		sp->p_dir = sp->p_desdir;
	    else if ((unsigned char) (sp->p_dir - sp->p_desdir) > 127)
		sp->p_dir += ticks;
	    else 
		sp->p_dir -= ticks;
	    sp->p_subdir %= 1000;
	}
    }
}

dirdiff(a, b)
unsigned char a, b;
{
  unsigned char diff = ABS(a - b);
  return(diff > 128 ? 256 - diff : diff);
}