/* strek_random_subs.f -- translated by f2c (version of 19 December 1990  16:50:21).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Table of constant values */

static integer c__1 = 1;
static integer c__3 = 3;

/* Subroutine */ int strek_assess_damage__(d_pct__, damage, scan, tract, 
	phase, energy, seed)
real *d_pct__, *damage;
logical *scan, *tract, *phase;
real *energy, *seed;
{
    extern /* Subroutine */ int rand_();
    static integer j;


/*    ******************************************************************* 
*/
/*    *****                                                         ***** 
*/
/*    *****                STAR TREK VERSION 3.0                    ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****                     written by                          ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****                Justin S. Revenaugh                      ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****                       7/87                              ***** 
*/
/*    *****                                                         ***** 
*/
/*    *****        Massachussetts Institute of Technology           ***** 
*/
/*    *****  Department of Earth, Atmospheric and Planetary Science ***** 
*/
/*    *****                                                         ***** 
*/
/*    ******************************************************************* 
*/

/*    STREK_ASSESS_DAMAGE assesses enemy damage done to the player's */
/*    ship. If a damage percent reaches 100 (i.e. d_pct = 0.0) then */
/*    the associated function (if any) is deactivated. */



/*    adjust energy */

    /* Parameter adjustments */
    --d_pct__;

    /* Function Body */
    if (*damage > (float)0.) {
	*energy -= *damage / (float)10.;

/*    apply damage */

	for (j = 1; j <= 6; ++j) {
	    rand_(seed);
	    d_pct__[j] -= *seed * *damage * (float).0025;
	    if (d_pct__[j] < (float)0.) {
		d_pct__[j] = (float)0.;
	    }
/* L10: */
	}

/*    check for function loss */

	if (d_pct__[3] == (float)0.) {
	    *phase = FALSE_;
	}
	if (d_pct__[5] == (float)0.) {
	    *scan = FALSE_;
	}
	if (d_pct__[6] == (float)0.) {
	    *tract = FALSE_;
	}
	*damage = (float)0.;
    }
    return 0;
} /* strek_assess_damage__ */

/* Subroutine */ int strek_photon_damage__(distance, damage, seed, type)
real *distance, *damage, *seed;
integer *type;
{
    /* Builtin functions */
    double sqrt();

    /* Local variables */
    extern /* Subroutine */ int rand_();
    static real mult, t1;


/*    STREK_PHOTON_DAMAGE calculates the damage do to anyone's */
/*    photons hitting anyone. */

/*    version 1 */
/*                                -jsr 8/85 */


/*    using distance figure damage. Falls off as 1/sqrt(distance) */
/*    instead as 1/distance (which is physically correct, but destroys */
/*    game balance). Type is the rating of damage (mild - severe). */

    rand_(seed);
    if (*seed < (float).8) {
	mult = (float).8;
    } else {
	mult = *seed;
    }
    t1 = (float)100. / sqrt(sqrt(*distance) + (float)3.) * mult;
    *damage = t1 + *damage;
    if (t1 < (float)5.) {
	*type = 1;
    }
    if (t1 >= (float)5. && t1 < (float)15.) {
	*type = 2;
    }
    if (t1 >= (float)15.) {
	*type = 3;
    }
    return 0;
} /* strek_photon_damage__ */

/* Subroutine */ int strek_phaser_damage__(range, damage, seed, target)
real *range, *damage, *seed;
logical *target;
{
    /* Initialized data */

    static char message[80*3+1] = "Ship hit by enemy phaser fire.           \
                                                                            \
                                                                            \
                                               ";
    static char text[80+1] = "Repair parties report that the damage was     \
                                  ";
    static char dam_rating__[10*3+1] = "light     moderate  heavy     ";

    /* System generated locals */
    real r__1, r__2;

    /* Builtin functions */
    double sqrt();
    integer s_wsfi(), do_fio(), e_wsfi();

    /* Local variables */
    extern /* Subroutine */ int rand_();
    static integer type;
    static real t1, t2, t3, t4;
    extern /* Subroutine */ int strek_message__();

    /* Fortran I/O blocks */
    static icilist io___12 = { 0, message+160, 0, "(a42, a10)", 80, 1 };



/*    STREK_PHASER_DAMAGE computes klingon phaser damage */

/*    version 1 */
/*                                     -jsr 8/85 */


/*    figure damage */

    t4 = (float)0.;
    rand_(seed);
    if (*seed <= (float)80.) {
	rand_(seed);
/* Computing MAX */
	r__1 = (float)10., r__2 = sqrt(*range);
	t1 = dmax(r__1,r__2);
	t2 = (float)15. - t1 * (float).075;
	t3 = *seed * (float).2 + (float).8;
	t4 = dmax((float)0.,t2) * t3;
	*damage += t4;
    }

/*    write damage message */

    if (*target) {
	type = 1;
	if (t4 < (float)5.) {
	    type = 1;
	}
	if (t4 >= (float)5. && t4 < (float)15.) {
	    type = 2;
	}
	if (t4 >= (float)15.) {
	    type = 3;
	}
	s_wsfi(&io___12);
	do_fio(&c__1, text, 80L);
	do_fio(&c__1, dam_rating__ + (type - 1) * 10, 10L);
	e_wsfi();
	strek_message__(message, &c__3, 80L);
    }
    return 0;
} /* strek_phaser_damage__ */

/* Subroutine */ int strek_phaser_fire__(range, seed, damage, type)
real *range, *seed, *damage;
integer *type;
{
    /* System generated locals */
    real r__1, r__2;

    /* Builtin functions */
    double sqrt();

    /* Local variables */
    extern /* Subroutine */ int rand_();
    static real t1, t2, t3;


/*    STREK_PHASER_FIRE evaluates the damage done by the players */
/*    phasers to all other objects. */

/*    version 1 */
/*                                               - jsr 8/85 */


    rand_(seed);
    if (*seed <= (float)80.) {
	rand_(seed);
	t3 = *seed * (float).2 + (float).8;
/* Computing MAX */
	r__1 = (float)10., r__2 = sqrt(*range);
	t1 = dmax(r__1,r__2);
	t2 = (float)25. - t1 * (float).075;
	t2 = dmax((float)0.,t2) * t3;
	*damage += t2;
    }
    if (t2 < (float)5.) {
	*type = 1;
    }
    if (t2 >= (float)5. && t2 < (float)15.) {
	*type = 2;
    }
    if (t2 >= (float)15.) {
	*type = 3;
    }
    return 0;
} /* strek_phaser_fire__ */

