1 //Copyright Paul Reiche, Fred Ford. 1992-2002
2
3 /*
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "starmap.h"
20 #include "gamestr.h"
21 #include "globdata.h"
22 #include "libs/gfxlib.h"
23
24
25 STAR_DESC *star_array;
26 STAR_DESC *CurStarDescPtr = 0;
27
28 STAR_DESC*
FindStar(STAR_DESC * LastSDPtr,POINT * puniverse,SIZE xbounds,SIZE ybounds)29 FindStar (STAR_DESC *LastSDPtr, POINT *puniverse, SIZE xbounds,
30 SIZE ybounds)
31 {
32 COORD min_y, max_y;
33 SIZE lo, hi;
34 STAR_DESC *BaseSDPtr;
35
36 if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)
37 {
38 BaseSDPtr = star_array;
39 hi = NUM_SOLAR_SYSTEMS - 1;
40 }
41 else
42 {
43 #define NUM_HYPER_VORTICES 15
44 BaseSDPtr = &star_array[NUM_SOLAR_SYSTEMS + 1];
45 hi = (NUM_HYPER_VORTICES + 1) - 1;
46 }
47
48 if (LastSDPtr == NULL)
49 lo = 0;
50 else if ((lo = LastSDPtr - BaseSDPtr + 1) > hi)
51 return (0);
52 else
53 hi = lo;
54
55 if (ybounds <= 0)
56 min_y = max_y = puniverse->y;
57 else
58 {
59 min_y = puniverse->y - ybounds;
60 max_y = puniverse->y + ybounds;
61 }
62
63 while (lo < hi)
64 {
65 SIZE mid;
66
67 mid = (lo + hi) >> 1;
68 if (BaseSDPtr[mid].star_pt.y >= min_y)
69 hi = mid - 1;
70 else
71 lo = mid + 1;
72 }
73
74 LastSDPtr = &BaseSDPtr[lo];
75 if (ybounds < 0 || LastSDPtr->star_pt.y <= max_y)
76 {
77 COORD min_x, max_x;
78
79 if (xbounds <= 0)
80 min_x = max_x = puniverse->x;
81 else
82 {
83 min_x = puniverse->x - xbounds;
84 max_x = puniverse->x + xbounds;
85 }
86
87 do
88 {
89 if ((ybounds < 0 || LastSDPtr->star_pt.y >= min_y)
90 && (xbounds < 0
91 || (LastSDPtr->star_pt.x >= min_x
92 && LastSDPtr->star_pt.x <= max_x))
93 )
94 return (LastSDPtr);
95 } while ((++LastSDPtr)->star_pt.y <= max_y);
96 }
97
98 return (0);
99 }
100
101 void
GetClusterName(const STAR_DESC * pSD,UNICODE buf[])102 GetClusterName (const STAR_DESC *pSD, UNICODE buf[])
103 {
104 UNICODE *pBuf, *pStr;
105
106 pBuf = buf;
107 if (pSD->Prefix)
108 {
109 pStr = GAME_STRING (STAR_NUMBER_BASE + pSD->Prefix - 1);
110 if (pStr)
111 {
112 while ((*pBuf++ = *pStr++))
113 ;
114 pBuf[-1] = ' ';
115 }
116 }
117 if ((pStr = GAME_STRING (pSD->Postfix)) == 0)
118 *pBuf = '\0';
119 else
120 {
121 while ((*pBuf++ = *pStr++))
122 ;
123 }
124 }
125
126