-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplanets.c
68 lines (60 loc) · 1.57 KB
/
planets.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* planets.c
*
* Kevin P. Smith 2/21/89
*
* This file contains the galaxy definition as well as some support for
* determining when parts of the galactic map need to be redrawn.
*/
#include "copyright2.h"
#include <stdio.h>
#include <math.h>
#include "netrek.h"
/* Note: DETAIL * MUST * be a factor of GWIDTH. */
#define DETAIL 40 /* Size of redraw array */
#define PDIST 4500 /* Distance to turn on redraw flag */
#define SIZE (GWIDTH/DETAIL)
int redraws[DETAIL][DETAIL];
static int plinitialized = 0;
void
initPlanets()
{
int i, j, k;
int endi, endj;
struct planet *pl;
int offset = PDIST / SIZE + 1;
float dist;
for (i = 0; i < DETAIL; i++) {
for (j = 0; j < DETAIL; j++) {
redraws[i][j] = -1;
}
}
for (k = 0, pl = planets; k < MAXPLANETS; k++, pl++) {
endi = pl->pl_x / SIZE + offset + 1;
for (i = (pl->pl_x / SIZE) - offset; i < endi && i < DETAIL; i++) {
if (i < 0)
i = 0;
endj = pl->pl_y / SIZE + offset + 1;
for (j = (pl->pl_y / SIZE) - offset; j < endj && j < DETAIL; j++) {
dist = hypot((float) (pl->pl_x - (i * SIZE + SIZE / 2)),
(float) (pl->pl_y - (j * SIZE + SIZE / 2)));
if (dist <= PDIST) {
redraws[i][j] = k;
}
}
}
}
plinitialized = 1;
}
void
checkRedraw(x, y)
int x, y;
{
int i;
if (!plinitialized || x < 0 || y < 0 || x >= GWIDTH || y >= GWIDTH)
return;
i = redraws[x / SIZE][y / SIZE];
if (i == -1)
return;
planets[i].pl_flags |= PLREDRAW;
}