rk
Zebranky food
Offline
Gender:
Posts: 12
SC2 = great!
|
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:
case RK_LONERANGER_DEFINED: GenFunc = GenerateLonestar; break;
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:
ADD_GAME_STATE (LONERANGER_GRPOFFS0, 8) ADD_GAME_STATE (LONERANGER_GRPOFFS1, 8) ADD_GAME_STATE (LONERANGER_GRPOFFS2, 8) ADD_GAME_STATE (LONERANGER_GRPOFFS3, 8)
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; b0 = GET_GAME_STATE (LONERANGER_GRPOFFS0); b1 = GET_GAME_STATE (LONERANGER_GRPOFFS1); b2 = GET_GAME_STATE (LONERANGER_GRPOFFS2); b3 = GET_GAME_STATE (LONERANGER_GRPOFFS3); 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));
SET_GAME_STATE (LONERANGER_GRPOFFS0, b0); SET_GAME_STATE (LONERANGER_GRPOFFS1, b1); SET_GAME_STATE (LONERANGER_GRPOFFS2, b2); SET_GAME_STATE (LONERANGER_GRPOFFS3, b3); }
void 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 break; default: //generate other things as default GenerateRandomIP (control); break; } }
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 };
after:
CurStarDescPtr = FindStar (0, &universe, 1, 1);
Questions? Complaints? Better way? Feel free to post!
|