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 p

⟦f4316e33e⟧ TextFile

    Length: 2614 (0xa36)
    Types: TextFile
    Names: »phaser.c«

Derivation

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

TextFile

static char sccsid[] = "@(#)phaser.c	1.1";

/*

	Copyright (c) 1986 	Chris Guthrie

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation.  No representations are made about the
suitability of this software for any purpose.  It is
provided "as is" without express or implied warranty.

*/

#include <X11/Xlib.h>
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include "defs.h"
#include "data.h"

phaser(p, course)
register struct player	*p;
unsigned char course;
{
    register int i;
    register struct player *j, *target;
    register struct phaser *mine;
    unsigned char dir;
    int range, trange;
    char buf[80];

    mine = &phasers[p->p_no];

    if (mine->ph_status != PHFREE) {
	warning(p, "Phasers have not recharged");
	return;
    }
    if (p->p_fuel < p->p_ship.s_phasercost) {
	warning(p, "Not enough fuel for phaser");
	return;
    }
    if (p->p_flags & PFREPAIR) {
	warning(p, "Can't fire while repairing");
	return;
    }
    if (p->p_flags & PFWEP) {
	warning(p, "Weapons overheated");
	return;
    }
    if (p->p_flags & PFCLOAK) {
	warning(p, "Cannot fire while cloaked");
	return;
    }

    p->p_fuel -= p->p_ship.s_phasercost;
    p->p_wtemp += p->p_ship.s_phasercost / 10;
    target = (struct player *) 0;
    mine->ph_dir = course;
    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
	if ((j->p_status != PALIVE) || (j == p))
	    continue;
	if ((!((j->p_swar | j->p_hostile) & p->p_team)) &&
	    (!((p->p_swar | p->p_hostile) & j->p_team)))
		continue;
	dir = (unsigned char) (atan2((double) (j->p_x - p->p_x),
	    (double) (p->p_y - j->p_y))
	    / 3.14159 * 128.);
	if (angdist(dir, course) < 5) {
	    trange = (int) hypot((double) (j->p_x - p->p_x),
		(double) (j->p_y - p->p_y));
	    if (target == 0) {
		target = j;
		range = trange;
	    }
	    else if (range > trange) {
		target = j;
		range = trange;
	    }
	}
    }
    if ((target == 0) || (range > p->p_ship.s_phasedist)) {
	mine->ph_fuse = 10;
	mine->ph_status = PHMISS;
	warning(p, "Phaser missed!!!");
    }
    else {
	mine->ph_fuse = 10;
	mine->ph_target = target->p_no;
	mine->ph_damage = (p->p_ship.s_phasedist - range) * p->p_ship.s_phaserdamage / p->p_ship.s_phasedist;
	mine->ph_status = PHHIT;
	(void) sprintf(buf, "Phaser hit %s for %d points",
	    target->p_name,
	    mine->ph_damage);
	warning(p, buf);
    }
    p->p_stats.st_phasers++;
}