The Ur-Quan Masters Home Page Welcome, Guest. Please login or register.
Did you miss your activation email?
June 25, 2024, 02:26:41 am
Home Help Search Login Register
News: Celebrating 30 years of Star Control 2 - The Ur-Quan Masters

+  The Ur-Quan Masters Discussion Forum
|-+  The Ur-Quan Masters Re-Release
| |-+  Technical Issues (Moderator: Death 999)
| | |-+  Poking the Source Part 2: Adding a trader
« previous next »
Pages: [1] Print
Author Topic: Poking the Source Part 2: Adding a trader  (Read 2472 times)
Zebranky food
Offline Offline

Gender: Male
Posts: 12

SC2 = great!

View Profile
Poking the Source Part 2: Adding a trader
« on: April 26, 2004, 10:58:32 pm »

This is a continuation of a part 1 – a post by (almost) the same name.

Now lets add a Melnorme trader to the system.  I'll call him Loneranger (just for naming constants).

In encount.h, there is an enumeration of several *_DEFINED constants.  I’ve added RK_LONERANGER_DEFINED.  Then I modified my entry in plandata.c to look like:

{{2000, 2000}, MAKE_STAR (DWARF_STAR, WHITE_BODY, -1), RK_LONERANGER_DEFINED, 0, 132}, /* Lonestar */

The following case is inserted into GenerateIP() in gendef.c:

     GenFunc = GenerateLonestar;

The following line is added near the bottom of encount.h:

extern void GenerateLoneranger (BYTE control);

The following game states are added to globdata.h, to store a pointer to info on the “battle group” containing the lone ranger.  Note that after this is done, you can't open old save games since adding more game state data changes the structure of the file slightly:


A new file called genlon.c is created, and its contents is below.  The GenerateLoneranger() function is called by GenerateIP() whenever we explore the RKVille system.  It "overrides" the default INIT_NPCs action, creating a "battle group" containing a trader.  (The underlying GenerateRandomIP() is still called after we're done our part).

#include "starcon.h"

static DWORD
GetLonerangerRef (void)
     BYTE b0, b1, b2, b3;
     return (MAKE_DWORD (MAKE_WORD (b0, b1), MAKE_WORD (b2, b3)));

static void
SetLonerangerRef (DWORD Ref)
     BYTE b0, b1, b2, b3;

     b0 = LOBYTE (LOWORD (Ref));
     b1 = HIBYTE (LOWORD (Ref));
     b2 = LOBYTE (HIWORD (Ref));
     b3 = HIBYTE (HIWORD (Ref));


GenerateLoneranger (BYTE control)
     switch (control)
           case INIT_NPCS:      //override the NPC generation; create the NPC if not already there
                 GLOBAL (BattleGroupRef) = GetLonerangerRef ();
                 if (GLOBAL (BattleGroupRef) == 0)
                       CloneShipFragment (MELNORME_SHIP,
                                   &GLOBAL (npc_built_ship_q), 0);
                       GLOBAL (BattleGroupRef) = PutGroupInfo (~0L, 1);
                       SetLonerangerRef (GLOBAL (BattleGroupRef));
                 GenerateRandomIP (INIT_NPCS);      //call the default
           default:      //generate other things as default
                 GenerateRandomIP (control);

For debugging, I added the following line in ExplorerSolarSys() of solarsys.c:

// enable for a debugging stoppoint on the custom system
if (CurStarDescPtr->Postfix == 132){
        CurStarDescPtr->Postfix = 132; // place breakpoint here


        CurStarDescPtr = FindStar (0, &universe, 1, 1);

Questions?  Complaints?  Better way?  Feel free to post!
« Last Edit: April 26, 2004, 11:01:36 pm by richardk » Logged
Pages: [1] Print 
« previous next »
Jump to:  

Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!