diff --git a/sc2/src/uqm/element.h b/sc2/src/uqm/element.h index dd4134089..953cf86b7 100644 --- a/sc2/src/uqm/element.h +++ b/sc2/src/uqm/element.h @@ -172,7 +172,7 @@ struct element static inline BOOLEAN elementsOfSamePlayer (ELEMENT *ElementPtr0, ELEMENT *ElementPtr1) { - return ElementPtr0->playerNr == ElementPtr1->playerNr; + return ElementPtr0->playerNr == ElementPtr1->playerNr ? TRUE : FALSE; } extern QUEUE disp_q; diff --git a/sc2/src/uqm/planets/Makeinfo b/sc2/src/uqm/planets/Makeinfo index b5f3104d0..6ae142a0f 100644 --- a/sc2/src/uqm/planets/Makeinfo +++ b/sc2/src/uqm/planets/Makeinfo @@ -5,3 +5,4 @@ uqm_CFILES="calc.c cargo.c devices.c gentopo.c lander.c orbits.c uqm_HFILES="elemdata.h generate.h lander.h lifeform.h plandata.h planets.h scan.h solarsys.h sundata.h" +uqm_CXXFILES="pstarmap-modern.cpp" diff --git a/sc2/src/uqm/planets/generate.h b/sc2/src/uqm/planets/generate.h index 9942e8283..2b3bbb35f 100644 --- a/sc2/src/uqm/planets/generate.h +++ b/sc2/src/uqm/planets/generate.h @@ -17,8 +17,18 @@ #ifndef GENERATE_H #define GENERATE_H +#if defined(__cplusplus) +extern "C" { +#endif + +struct GenerateFunctions; + typedef struct GenerateFunctions GenerateFunctions; +#if defined(__cplusplus) +} +#endif + #include "types.h" #include "planets.h" #include "libs/compiler.h" diff --git a/sc2/src/uqm/planets/pstarmap-modern.cpp b/sc2/src/uqm/planets/pstarmap-modern.cpp new file mode 100644 index 000000000..b30e96118 --- /dev/null +++ b/sc2/src/uqm/planets/pstarmap-modern.cpp @@ -0,0 +1,71 @@ +//Copyright Paul Reiche, Fred Ford. 1992-2002 +//Edited by ADAM David Alan Martin. 2024 + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#include "../starmap.h" +#include "../menustat.h" +#include "../controls.h" +#include "../sis.h" +#include "../sounds.h" + + +extern "C" bool +DoStarSearch (MENU_STATE *pMS) +{ + TEXTENTRY_STATE tes; + STAR_SEARCH_STATE *pss; + bool success; + + pss = (STAR_SEARCH_STATE *) HMalloc (sizeof (*pss)); + if (!pss) + return FALSE; + pss->SortedStars= (int *) HMalloc( GetStarCount() * sizeof( int * ) ); + if (!pss->SortedStars) + { + HFree (pss); + return FALSE; + } + + DrawSISMessageEx ("", 0, 0, DSME_SETFR); + + pss->pMS = pMS; + pss->LastChangeTime = 0; + pss->Text[0] = '\0'; + pss->LastText[0] = '\0'; + pss->FirstIndex = -1; + SortStarsOnName (pss); + + // text entry setup + tes.Initialized = FALSE; + tes.BaseStr = pss->Text; + tes.MaxSize = sizeof (pss->Text); + tes.CursorPos = 0; + tes.CbParam = pss; + tes.ChangeCallback = OnStarNameChange; + tes.FrameCallback = OnStarNameFrame; + + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + SetDefaultMenuRepeatDelay (); + success = DoTextEntry (&tes); + + DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR); + + HFree (pss->SortedStars); + HFree (pss); + + return success; +} diff --git a/sc2/src/uqm/planets/pstarmap.c b/sc2/src/uqm/planets/pstarmap.c index 54cad3e10..3176ef8c9 100644 --- a/sc2/src/uqm/planets/pstarmap.c +++ b/sc2/src/uqm/planets/pstarmap.c @@ -797,29 +797,6 @@ UpdateFuelRequirement (void) DrawStatusMessage (buf); } -#define STAR_SEARCH_BUFSIZE 256 - -typedef struct starsearch_state -{ - // TODO: pMS field is probably not needed anymore - MENU_STATE *pMS; - UNICODE Text[STAR_SEARCH_BUFSIZE]; - UNICODE LastText[STAR_SEARCH_BUFSIZE]; - DWORD LastChangeTime; - int FirstIndex; - int CurIndex; - int LastIndex; - BOOLEAN SingleClust; - BOOLEAN SingleMatch; - UNICODE Buffer[STAR_SEARCH_BUFSIZE]; - const UNICODE *Prefix; - const UNICODE *Cluster; - int PrefixLen; - int ClusterLen; - int ClusterPos; - int *SortedStars; -} STAR_SEARCH_STATE; - static int compStarName (const void *ptr1, const void *ptr2) { @@ -843,7 +820,7 @@ compStarName (const void *ptr1, const void *ptr2) return 0; } -static void +void SortStarsOnName (STAR_SEARCH_STATE *pSS) { int i; @@ -1092,7 +1069,7 @@ MatchNextStar (STAR_SEARCH_STATE *pSS, BOOLEAN Reset) } } -static BOOLEAN +BOOLEAN OnStarNameChange (TEXTENTRY_STATE *pTES) { STAR_SEARCH_STATE *pSS = (STAR_SEARCH_STATE *) pTES->CbParam; @@ -1134,7 +1111,7 @@ OnStarNameChange (TEXTENTRY_STATE *pTES) return ret; } -static BOOLEAN +BOOLEAN OnStarNameFrame (TEXTENTRY_STATE *pTES) { STAR_SEARCH_STATE *pSS = (STAR_SEARCH_STATE *) pTES->CbParam; @@ -1167,53 +1144,6 @@ OnStarNameFrame (TEXTENTRY_STATE *pTES) return TRUE; } -static BOOLEAN -DoStarSearch (MENU_STATE *pMS) -{ - TEXTENTRY_STATE tes; - STAR_SEARCH_STATE *pss; - BOOLEAN success; - - pss = HMalloc (sizeof (*pss)); - if (!pss) - return FALSE; - pss->SortedStars= HMalloc( GetStarCount() * sizeof( int * ) ); - if (!pss->SortedStars) - { - HFree (pss); - return FALSE; - } - - DrawSISMessageEx ("", 0, 0, DSME_SETFR); - - pss->pMS = pMS; - pss->LastChangeTime = 0; - pss->Text[0] = '\0'; - pss->LastText[0] = '\0'; - pss->FirstIndex = -1; - SortStarsOnName (pss); - - // text entry setup - tes.Initialized = FALSE; - tes.BaseStr = pss->Text; - tes.MaxSize = sizeof (pss->Text); - tes.CursorPos = 0; - tes.CbParam = pss; - tes.ChangeCallback = OnStarNameChange; - tes.FrameCallback = OnStarNameFrame; - - SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); - SetDefaultMenuRepeatDelay (); - success = DoTextEntry (&tes); - - DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR); - - HFree (pss->SortedStars); - HFree (pss); - - return success; -} - static BOOLEAN DoMoveCursor (MENU_STATE *pMS) { diff --git a/sc2/src/uqm/starmap.h b/sc2/src/uqm/starmap.h index ee683b563..e7560889f 100644 --- a/sc2/src/uqm/starmap.h +++ b/sc2/src/uqm/starmap.h @@ -19,6 +19,8 @@ #include "libs/compiler.h" #include "planets/planets.h" +#include "uqm/menustat.h" +#include "uqm/controls.h" #if defined(__cplusplus) extern "C" { @@ -37,6 +39,38 @@ extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]); // Defined in plandata.c extern COUNT GetStarCount (void); + +// Star search functions + +#define STAR_SEARCH_BUFSIZE 256 + +typedef struct starsearch_state +{ + // TODO: pMS field is probably not needed anymore + MENU_STATE *pMS; + UNICODE Text[STAR_SEARCH_BUFSIZE]; + UNICODE LastText[STAR_SEARCH_BUFSIZE]; + DWORD LastChangeTime; + int FirstIndex; + int CurIndex; + int LastIndex; + BOOLEAN SingleClust; + BOOLEAN SingleMatch; + UNICODE Buffer[STAR_SEARCH_BUFSIZE]; + const UNICODE *Prefix; + const UNICODE *Cluster; + int PrefixLen; + int ClusterLen; + int ClusterPos; + int *SortedStars; +} STAR_SEARCH_STATE; + +bool DoStarSearch( MENU_STATE * ); +void SortStarsOnName( STAR_SEARCH_STATE * ); +BOOLEAN OnStarNameChange( TEXTENTRY_STATE * ); +BOOLEAN OnStarNameFrame ( TEXTENTRY_STATE *pTES ); + + #if defined(__cplusplus) } #endif