121286Sdist /*
2*60857Sbostic * Copyright (c) 1980, 1993
3*60857Sbostic * The Regents of the University of California. All rights reserved.
434205Sbostic *
542606Sbostic * %sccs.include.redist.c%
621286Sdist */
721286Sdist
811685Smckusick #ifndef lint
9*60857Sbostic static char sccsid[] = "@(#)nova.c 8.1 (Berkeley) 05/31/93";
1034205Sbostic #endif /* not lint */
1111685Smckusick
1211685Smckusick # include "trek.h"
1311685Smckusick
1411685Smckusick /*
1511685Smckusick ** CAUSE A NOVA TO OCCUR
1611685Smckusick **
1711685Smckusick ** A nova occurs. It is the result of having a star hit with
1811685Smckusick ** a photon torpedo. There are several things which may happen.
1911685Smckusick ** The star may not be affected. It may go nova. It may turn
2011685Smckusick ** into a black hole. Any (yummy) it may go supernova.
2111685Smckusick **
2211685Smckusick ** Stars that go nova cause stars which surround them to undergo
2311685Smckusick ** the same probabilistic process. Klingons next to them are
2411685Smckusick ** destroyed. And if the starship is next to it, it gets zapped.
2511685Smckusick ** If the zap is too much, it gets destroyed.
2611685Smckusick */
2711685Smckusick
nova(x,y)2811685Smckusick nova(x, y)
2911685Smckusick int x, y;
3011685Smckusick {
3111685Smckusick register int i, j;
3211685Smckusick register int se;
3311685Smckusick
3411685Smckusick if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0)
3511685Smckusick return;
3611685Smckusick if (ranf(100) < 15)
3711685Smckusick {
3811685Smckusick printf("Spock: Star at %d,%d failed to nova.\n", x, y);
3911685Smckusick return;
4011685Smckusick }
4111685Smckusick if (ranf(100) < 5)
4211685Smckusick return (snova(x, y));
4311685Smckusick printf("Spock: Star at %d,%d gone nova\n", x, y);
4411685Smckusick
4511685Smckusick if (ranf(4) != 0)
4611685Smckusick Sect[x][y] = EMPTY;
4711685Smckusick else
4811685Smckusick {
4911685Smckusick Sect[x][y] = HOLE;
5012344Slayer Quad[Ship.quadx][Ship.quady].holes += 1;
5111685Smckusick }
5212344Slayer Quad[Ship.quadx][Ship.quady].stars -= 1;
5312344Slayer Game.kills += 1;
5411685Smckusick for (i = x - 1; i <= x + 1; i++)
5511685Smckusick {
5611685Smckusick if (i < 0 || i >= NSECTS)
5711685Smckusick continue;
5811685Smckusick for (j = y - 1; j <= y + 1; j++)
5911685Smckusick {
6011685Smckusick if (j < 0 || j >= NSECTS)
6111685Smckusick continue;
6211685Smckusick se = Sect[i][j];
6311685Smckusick switch (se)
6411685Smckusick {
6511685Smckusick
6611685Smckusick case EMPTY:
6711685Smckusick case HOLE:
6811685Smckusick break;
6911685Smckusick
7011685Smckusick case KLINGON:
7111685Smckusick killk(i, j);
7211685Smckusick break;
7311685Smckusick
7411685Smckusick case STAR:
7511685Smckusick nova(i, j);
7611685Smckusick break;
7711685Smckusick
7811685Smckusick case INHABIT:
7911685Smckusick kills(i, j, -1);
8011685Smckusick break;
8111685Smckusick
8211685Smckusick case BASE:
8311685Smckusick killb(i, j);
8412344Slayer Game.killb += 1;
8511685Smckusick break;
8611685Smckusick
8711685Smckusick case ENTERPRISE:
8811685Smckusick case QUEENE:
8911685Smckusick se = 2000;
9011685Smckusick if (Ship.shldup)
9111685Smckusick if (Ship.shield >= se)
9211685Smckusick {
9312344Slayer Ship.shield -= se;
9411685Smckusick se = 0;
9511685Smckusick }
9611685Smckusick else
9711685Smckusick {
9812344Slayer se -= Ship.shield;
9911685Smckusick Ship.shield = 0;
10011685Smckusick }
10112344Slayer Ship.energy -= se;
10211685Smckusick if (Ship.energy <= 0)
10311685Smckusick lose(L_SUICID);
10411685Smckusick break;
10511685Smckusick
10611685Smckusick default:
10711685Smckusick printf("Unknown object %c at %d,%d destroyed\n",
10811685Smckusick se, i, j);
10911685Smckusick Sect[i][j] = EMPTY;
11011685Smckusick break;
11111685Smckusick }
11211685Smckusick }
11311685Smckusick }
11411685Smckusick return;
11511685Smckusick }
116