aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sword2/anims.cpp103
-rw-r--r--sword2/anims.h10
-rw-r--r--sword2/build_display.cpp65
-rw-r--r--sword2/build_display.h2
-rw-r--r--sword2/console.cpp2
-rw-r--r--sword2/controls.cpp16
-rw-r--r--sword2/credits.h2
-rw-r--r--sword2/debug.cpp8
-rw-r--r--sword2/defs.h8
-rw-r--r--sword2/events.cpp176
-rw-r--r--sword2/events.h3
-rw-r--r--sword2/function.cpp138
-rw-r--r--sword2/icons.cpp11
-rw-r--r--sword2/interpreter.cpp409
-rw-r--r--sword2/layers.cpp16
-rw-r--r--sword2/layers.h6
-rw-r--r--sword2/logic.cpp53
-rw-r--r--sword2/logic.h171
-rw-r--r--sword2/mouse.cpp91
-rw-r--r--sword2/mouse.h3
-rw-r--r--sword2/object.h6
-rw-r--r--sword2/protocol.cpp2
-rw-r--r--sword2/resman.cpp5
-rw-r--r--sword2/router.cpp4
-rw-r--r--sword2/save_rest.cpp30
-rw-r--r--sword2/scroll.cpp13
-rw-r--r--sword2/sound.cpp48
-rw-r--r--sword2/sound.h3
-rw-r--r--sword2/speech.cpp105
-rw-r--r--sword2/startup.cpp13
-rw-r--r--sword2/sword2.cpp12
-rw-r--r--sword2/sync.cpp21
-rw-r--r--sword2/walker.cpp147
-rw-r--r--sword2/walker.h7
34 files changed, 863 insertions, 846 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp
index 49e51ba243..a48da08a5a 100644
--- a/sword2/anims.cpp
+++ b/sword2/anims.cpp
@@ -33,7 +33,8 @@
#include "bs2/defs.h"
#include "bs2/header.h"
#include "bs2/interpreter.h"
-#include "bs2/maketext.h" // for makeTextSprite used by FN_play_sequence ultimately
+#include "bs2/logic.h"
+#include "bs2/maketext.h" // for makeTextSprite used by fnPlaySequence ultimately
#include "bs2/object.h"
#include "bs2/protocol.h"
#include "bs2/resman.h"
@@ -49,7 +50,7 @@ static uint32 smackerLeadOut = 0;
int32 Animate(int32 *params, uint8 reverse_flag);
int32 Mega_table_animate(int32 *params, uint8 reverse_flag);
-int32 FN_anim(int32 *params) {
+int32 Logic::fnAnim(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 resource id of animation file
@@ -58,7 +59,7 @@ int32 FN_anim(int32 *params) {
return Animate(params, 0);
}
-int32 FN_reverse_anim(int32 *params) {
+int32 Logic::fnReverseAnim(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 resource id of animation file
@@ -67,7 +68,7 @@ int32 FN_reverse_anim(int32 *params) {
return Animate(params, 1);
}
-int32 FN_mega_table_anim(int32 *params) {
+int32 Logic::fnMegaTableAnim(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -77,7 +78,7 @@ int32 FN_mega_table_anim(int32 *params) {
return Mega_table_animate(params, 0);
}
-int32 FN_reverse_mega_table_anim(int32 *params) {
+int32 Logic::fnReverseMegaTableAnim(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -133,19 +134,19 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
// switch off the sprite
// don't animate - just continue
// script next cycle
- FN_no_sprite(params + 1);
+ fnNoSprite(params + 1);
return IR_STOP;
}
} else {
// Not a valid resource number. Switch off
// the sprite. Don't animate - just continue
// script next cycle.
- FN_no_sprite(params + 1);
+ fnNoSprite(params + 1);
return IR_STOP;
}
// switch on the sprite
- FN_sort_sprite(params + 1);
+ fnSortSprite(params + 1);
}
#endif
@@ -245,7 +246,7 @@ int32 Mega_table_animate(int32 *params, uint8 reverse_flag) {
pars[2] = anim_table[ob_mega->current_dir];
}
- // set up the rest of the parameters for FN_anim()
+ // set up the rest of the parameters for fnAnim()
pars[0] = params[0];
pars[1] = params[1];
@@ -256,7 +257,7 @@ int32 Mega_table_animate(int32 *params, uint8 reverse_flag) {
return Animate(pars, reverse_flag);
}
-int32 FN_set_frame(int32 *params) {
+int32 Logic::fnSetFrame(int32 *params) {
// params: 0 pointer to object's graphic structure
// 1 resource id of animation file
// 2 frame flag (0=first 1=last)
@@ -274,7 +275,7 @@ int32 FN_set_frame(int32 *params) {
#ifdef _SWORD2_DEBUG
// check that we haven't been passed a zero resource number
if (res == 0)
- Con_fatal_error("FN_set_frame: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
+ Con_fatal_error("fnSetFrame: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
#endif
// open the resource (& check it's valid)
@@ -285,7 +286,7 @@ int32 FN_set_frame(int32 *params) {
// check this this resource is actually an animation file!
head = (_standardHeader *) anim_file;
if (head->fileType != ANIMATION_FILE)
- Con_fatal_error("FN_set_frame: %s (%d) is not an anim!", FetchObjectName(res), res);
+ Con_fatal_error("fnSetFrame: %s (%d) is not an anim!", FetchObjectName(res), res);
#endif
// set up pointer to the animation header
@@ -294,7 +295,7 @@ int32 FN_set_frame(int32 *params) {
/* #ifdef _SWORD2_DEBUG
// check there's at least one frame
if (anim_head->noAnimFrames == 0)
- Con_fatal_error("FN_set_frame: %s (%d) has zero frame count!", FetchObjectName(res), res);
+ Con_fatal_error("fnSetFrame: %s (%d) has zero frame count!", FetchObjectName(res), res);
#endif */
// set up anim resource in graphic object
@@ -313,8 +314,8 @@ int32 FN_set_frame(int32 *params) {
return IR_CONT;
}
-int32 FN_no_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnNoSprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -326,8 +327,8 @@ int32 FN_no_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_back_par0_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnBackPar0Sprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -339,8 +340,8 @@ int32 FN_back_par0_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_back_par1_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnBackPar1Sprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -352,8 +353,8 @@ int32 FN_back_par1_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_back_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnBackSprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -365,8 +366,8 @@ int32 FN_back_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_sort_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnSortSprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -378,8 +379,8 @@ int32 FN_sort_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_fore_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnForeSprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -391,8 +392,8 @@ int32 FN_fore_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_fore_par0_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnForePar0Sprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -404,8 +405,8 @@ int32 FN_fore_par0_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_fore_par1_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnForePar1Sprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -417,8 +418,8 @@ int32 FN_fore_par1_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_shaded_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnShadedSprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -433,8 +434,8 @@ int32 FN_shaded_sprite(int32 *params) {
return IR_CONT;
}
-int32 FN_unshaded_sprite(int32 *params) {
- // params 0 pointer to object's graphic structure
+int32 Logic::fnUnshadedSprite(int32 *params) {
+ // params: 0 pointer to object's graphic structure
Object_graphic *ob_graphic = (Object_graphic *) params[0];
@@ -479,14 +480,14 @@ static uint32 sequenceTextLines = 0;
static _sequenceTextInfo sequence_text_list[MAX_SEQUENCE_TEXT_LINES];
-int32 FN_add_sequence_text(int32 *params) {
-// params 0 text number
-// 1 frame number to start the text displaying
-// 2 frame number to stop the text dispalying
+int32 Logic::fnAddSequenceText(int32 *params) {
+// params: 0 text number
+// 1 frame number to start the text displaying
+// 2 frame number to stop the text dispalying
#ifdef _SWORD2_DEBUG
if (sequenceTextLines == MAX_SEQUENCE_TEXT_LINES)
- Con_fatal_error("FN_add_sequence_text ran out of lines");
+ Con_fatal_error("fnAddSequenceText ran out of lines");
#endif
sequence_text_list[sequenceTextLines].textNumber = params[0];
@@ -648,19 +649,21 @@ void ClearSequenceSpeech(_movieTextObject *textSprites[]) {
sequenceTextLines = 0;
}
-int32 FN_smacker_lead_in(int32 *params) {
+int32 Logic::fnSmackerLeadIn(int32 *params) {
uint8 *leadIn;
uint32 rv;
#ifdef _SWORD2_DEBUG
_standardHeader *header;
#endif
+ // params: 0 id of lead-in music
+
leadIn = res_man.open(params[0]);
#ifdef _SWORD2_DEBUG
header = (_standardHeader *) leadIn;
if (header->fileType != WAV_FILE)
- Con_fatal_error("FN_smacker_lead_in() given invalid resource");
+ Con_fatal_error("fnSmackerLeadIn() given invalid resource");
#endif
leadIn += sizeof(_standardHeader);
@@ -673,22 +676,24 @@ int32 FN_smacker_lead_in(int32 *params) {
res_man.close(params[0]);
// fade out any music that is currently playing
- FN_stop_music(NULL);
+ fnStopMusic(NULL);
// continue script
return IR_CONT;
}
-int32 FN_smacker_lead_out(int32 *params) {
- // ready for use in FN_play_sequence
+int32 Logic::fnSmackerLeadOut(int32 *params) {
+ // params: 0 id of lead-out music
+
+ // ready for use in fnPlaySequence
smackerLeadOut = params[0];
// continue script
return IR_CONT;
}
-int32 FN_play_sequence(int32 *params) {
- // params 0 pointer to null-terminated ascii filename
+int32 Logic::fnPlaySequence(int32 *params) {
+ // params: 0 pointer to null-terminated ascii filename
// 1 number of frames in the sequence, used for PSX.
char filename[30];
@@ -705,7 +710,7 @@ int32 FN_play_sequence(int32 *params) {
// of computer games" - but at the very least we want to show the
// cutscene subtitles, so I removed them.
- debug(5, "FN_play_sequence(\"%s\");", params[0]);
+ debug(5, "fnPlaySequence(\"%s\");", params[0]);
#ifdef _SWORD2_DEBUG
// check that the name paseed from script is 8 chars or less
@@ -733,7 +738,7 @@ int32 FN_play_sequence(int32 *params) {
#ifdef _SWORD2_DEBUG
header = (_standardHeader *)leadOut;
if (header->fileType != WAV_FILE)
- error("FN_smacker_lead_out() given invalid resource");
+ error("fnSmackerLeadOut() given invalid resource");
#endif
leadOut += sizeof(_standardHeader);
@@ -742,7 +747,7 @@ int32 FN_play_sequence(int32 *params) {
// play the smacker
// don't want to carry on streaming game music when smacker starts!
- FN_stop_music(NULL);
+ fnStopMusic(NULL);
// pause sfx during sequence, except the one used for lead-in music
g_sound->pauseFxForSequence();
@@ -785,7 +790,7 @@ int32 FN_play_sequence(int32 *params) {
memset(pal, 0, 256 * sizeof(_palEntry));
g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT);
- debug(5, "FN_play_sequence FINISHED");
+ debug(5, "fnPlaySequence FINISHED");
// continue script
return IR_CONT;
diff --git a/sword2/anims.h b/sword2/anims.h
index 30605b8685..224e6ffcb5 100644
--- a/sword2/anims.h
+++ b/sword2/anims.h
@@ -24,16 +24,6 @@
namespace Sword2 {
-int32 FN_anim(int32 *params);
-int32 FN_reverse_anim(int32 *params);
-int32 FN_mega_table_anim(int32 *params);
-int32 FN_reverse_mega_table_anim(int32 *params);
-int32 FN_set_frame(int32 *params);
-int32 FN_no_sprite(int32 *params);
-int32 FN_back_sprite(int32 *params);
-int32 FN_sort_sprite(int32 *params);
-int32 FN_fore_sprite(int32 *params);
-
} // End of namespace Sword2
#endif
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp
index c0cfb46080..65dec308ab 100644
--- a/sword2/build_display.cpp
+++ b/sword2/build_display.cpp
@@ -28,6 +28,7 @@
#include "bs2/defs.h"
#include "bs2/interpreter.h"
#include "bs2/layers.h"
+#include "bs2/logic.h"
#include "bs2/maketext.h"
#include "bs2/mouse.h"
#include "bs2/object.h"
@@ -824,13 +825,14 @@ void Register_frame(int32 *params, buildit *build_unit) {
res_man.close(ob_graph->anim_resource);
}
-int32 FN_register_frame(int32 *params) {
- //this call would be made from an objects service script 0
+int32 Logic::fnRegisterFrame(int32 *params) {
+ // this call would be made from an objects service script 0
- // params: 0 pointer to mouse structure or NULL for no write to mouse
- // list (non-zero means write sprite-shape to mouse list)
- // 1 pointer to graphic structure
- // 2 pointer to mega structure or NULL if not a mega
+ // params: 0 pointer to mouse structure or NULL for no write to
+ // mouse list (non-zero means write sprite-shape to
+ // mouse list)
+ // 1 pointer to graphic structure
+ // 2 pointer to mega structure or NULL if not a mega
Object_graphic *ob_graph = (Object_graphic *) params[1];
@@ -839,7 +841,7 @@ int32 FN_register_frame(int32 *params) {
case BGP0_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_bgp0 == MAX_bgp0_sprites)
- Con_fatal_error("ERROR: bgp0_list full in FN_register_frame");
+ Con_fatal_error("ERROR: bgp0_list full in fnRegisterFrame");
#endif
Register_frame(params, &bgp0_list[cur_bgp0]);
@@ -848,7 +850,7 @@ int32 FN_register_frame(int32 *params) {
case BGP1_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_bgp1 == MAX_bgp1_sprites)
- Con_fatal_error("ERROR: bgp1_list full in FN_register_frame");
+ Con_fatal_error("ERROR: bgp1_list full in fnRegisterFrame");
#endif
Register_frame(params, &bgp1_list[cur_bgp1]);
@@ -857,7 +859,7 @@ int32 FN_register_frame(int32 *params) {
case BACK_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_back == MAX_back_sprites)
- Con_fatal_error("ERROR: back_list full in FN_register_frame");
+ Con_fatal_error("ERROR: back_list full in fnRegisterFrame");
#endif
Register_frame(params, &back_list[cur_back]);
@@ -866,7 +868,7 @@ int32 FN_register_frame(int32 *params) {
case SORT_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_sort == MAX_sort_sprites)
- Con_fatal_error("ERROR: sort_list full in FN_register_frame");
+ Con_fatal_error("ERROR: sort_list full in fnRegisterFrame");
#endif
sort_order[cur_sort] = cur_sort;
@@ -876,7 +878,7 @@ int32 FN_register_frame(int32 *params) {
case FORE_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fore == MAX_fore_sprites)
- Con_fatal_error("ERROR: fore_list full in FN_register_frame");
+ Con_fatal_error("ERROR: fore_list full in fnRegisterFrame");
#endif
Register_frame(params, &fore_list[cur_fore]);
@@ -885,7 +887,7 @@ int32 FN_register_frame(int32 *params) {
case FGP0_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fgp0 == MAX_fgp0_sprites)
- Con_fatal_error("ERROR: fgp0_list full in FN_register_frame");
+ Con_fatal_error("ERROR: fgp0_list full in fnRegisterFrame");
#endif
Register_frame(params, &fgp0_list[cur_fgp0]);
@@ -894,7 +896,7 @@ int32 FN_register_frame(int32 *params) {
case FGP1_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fgp1 == MAX_fgp1_sprites)
- Con_fatal_error("ERROR: fgp1_list full in FN_register_frame");
+ Con_fatal_error("ERROR: fgp1_list full in fnRegisterFrame");
#endif
Register_frame(params, &fgp1_list[cur_fgp1]);
@@ -937,37 +939,43 @@ void Start_new_palette(void) {
this_screen.new_palette = 0;
}
-int32 FN_update_player_stats(int32 *params) {
- //engine needs to know certain info about the player
+int32 Logic::fnUpdatePlayerStats(int32 *params) {
+ // engine needs to know certain info about the player
+
+ // params: 0 pointer to mega structure
Object_mega *ob_mega = (Object_mega *) params[0];
this_screen.player_feet_x = ob_mega->feet_x;
this_screen.player_feet_y = ob_mega->feet_y;
- //for the script
+ // for the script
PLAYER_FEET_X = ob_mega->feet_x;
PLAYER_FEET_Y = ob_mega->feet_y;
PLAYER_CUR_DIR = ob_mega->current_dir;
SCROLL_OFFSET_X = this_screen.scroll_offset_x;
- debug(5, "FN_Update_player_stats: %d %d", ob_mega->feet_x, ob_mega->feet_y);
+ debug(5, "fnUpdatePlayerStats: %d %d", ob_mega->feet_x, ob_mega->feet_y);
return IR_CONT;
}
-int32 FN_fade_down(int32 *params) {
+int32 Logic::fnFadeDown(int32 *params) {
// NONE means up! can only be called when screen is fully faded up -
// multiple calls wont have strange effects
+ // params: none
+
if (g_display->getFadeStatus() == RDFADE_NONE)
g_display->fadeDown();
return IR_CONT;
}
-int32 FN_fade_up(int32 *params) {
+int32 Logic::fnFadeUp(int32 *params) {
+ // params: none
+
g_display->waitForFade();
if (g_display->getFadeStatus() == RDFADE_BLACK)
@@ -992,15 +1000,15 @@ int32 FN_fade_up(int32 *params) {
// uint8 noEntries;
// } _paletteHeader;
-int32 FN_set_palette(int32 *params) {
+int32 Logic::fnSetPalette(int32 *params) {
+ // params: 0 resource number of palette file, or 0 if it's to be
+ // the palette from the current screen
+
SetFullPalette(params[0]);
return IR_CONT;
}
void SetFullPalette(int32 palRes) {
- // params 0 resource number of palette file
- // or 0 if it's to be the palette from the current screen
-
uint8 *file;
_standardHeader *head;
@@ -1042,7 +1050,7 @@ void SetFullPalette(int32 palRes) {
#ifdef _SWORD2_DEBUG
if (head->fileType != PALETTE_FILE)
- Con_fatal_error("FN_set_palette() called with invalid resource!");
+ Con_fatal_error("fnSetPalette() called with invalid resource!");
#endif
file = (uint8 *) (head + 1);
@@ -1083,15 +1091,18 @@ void SetFullPalette(int32 palRes) {
// close screen file
res_man.close(this_screen.background_layer_id);
} else
- Con_fatal_error("FN_set_palette(0) called, but no current screen available!");
+ Con_fatal_error("fnSetPalette(0) called, but no current screen available!");
}
}
-int32 FN_restore_game(int32 *params) {
+int32 Logic::fnRestoreGame(int32 *params) {
+ // params: none
return IR_CONT;
}
-int32 FN_change_shadows(int32 *params) {
+int32 Logic::fnChangeShadows(int32 *params) {
+ // params: none
+
uint32 rv;
// if last screen was using a shading mask (see below)
diff --git a/sword2/build_display.h b/sword2/build_display.h
index f318fcd110..c8607f16f4 100644
--- a/sword2/build_display.h
+++ b/sword2/build_display.h
@@ -89,8 +89,6 @@ extern buildit sort_list[];
void Reset_render_lists(void);
void Build_display(void);
-int32 FN_fade_down(int32 *params);
-int32 FN_fade_up(int32 *params);
void Process_image(buildit *build_unit);
void DisplayMsg( uint8 *text, int time );
void RemoveMsg(void);
diff --git a/sword2/console.cpp b/sword2/console.cpp
index e69fa7a772..b8c811fdec 100644
--- a/sword2/console.cpp
+++ b/sword2/console.cpp
@@ -497,7 +497,7 @@ uint32 Parse_user_input(void) {
Print_current_info();
return 0;
case 15: // RUNLIST
- LLogic.examineRunList();
+ g_logic.examineRunList();
return 0;
case 16: // KILL
res_man.kill(&input[1][0]);
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index 78de6dbf3b..d504c05406 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -1327,14 +1327,14 @@ public:
// Prime system with a game cycle
// Reset the graphic 'buildit' list before a
- // new logic list (see FN_register_frame)
+ // new logic list (see fnRegisterFrame)
Reset_render_lists();
// Reset the mouse hot-spot list (see
- // FN_register_mouse and FN_register_frame)
+ // fnRegisterMouse and fnRegisterFrame)
Reset_mouse_list();
- if (LLogic.processSession())
+ if (g_logic.processSession())
Con_fatal_error("restore 1st cycle failed??");
}
}
@@ -1441,22 +1441,22 @@ void Gui::restartControl(void) {
// prime system with a game cycle
// reset the graphic 'buildit' list before a new logic list
- // (see FN_register_frame)
+ // (see fnRegisterFrame)
Reset_render_lists();
- // reset the mouse hot-spot list (see FN_register_mouse and
- // FN_register_frame)
+ // reset the mouse hot-spot list (see fnRegisterMouse and
+ // fnRegisterFrame)
Reset_mouse_list();
g_display->closeMenuImmediately();
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
- // - this is taken from FN_init_background
+ // - this is taken from fnInitBackground
// switch on scrolling (2 means first time on screen)
this_screen.scroll_flag = 2;
- if (LLogic.processSession())
+ if (g_logic.processSession())
Con_fatal_error("restart 1st cycle failed??");
// So palette not restored immediately after control panel - we want
diff --git a/sword2/credits.h b/sword2/credits.h
index db07f095b8..43e9889341 100644
--- a/sword2/credits.h
+++ b/sword2/credits.h
@@ -27,8 +27,6 @@ namespace Sword2 {
// int32 __declspec( dllexport ) Credits(_drvDrawStatus *pDrawStatus, _drvSoundStatus *pSoundStatus, const char *cdPath, BOOL smoke, BOOL *pAppFocus, _drvKeyStatus *pKeyStatus);
//int32 Credits(_drvDrawStatus *pDrawStatus, _drvSoundStatus *pSoundStatus, const char *cdPath, BOOL smoke, BOOL *pAppFocus, _drvKeyStatus *pKeyStatus);
-int32 FN_play_credits(int32 *params);
-
} // End of namespace Sword2
#endif
diff --git a/sword2/debug.cpp b/sword2/debug.cpp
index 14d2054279..0d13c14393 100644
--- a/sword2/debug.cpp
+++ b/sword2/debug.cpp
@@ -60,7 +60,7 @@ uint8 rectFlicker = 0;
uint8 testingSnR = 0; // "SAVEREST" - for system to kill all
// object resources (except player) in
- // FN_add_human()
+ // fnAddHuman()
int32 startTime = 0; // "TIMEON" & "TIMEOFF" - system start
// time.
@@ -153,7 +153,7 @@ void Build_debug_text(void) {
// testingSnR indicator
- if (testingSnR) { // see FN_add_human()
+ if (testingSnR) { // see fnAddHuman()
sprintf (buf, "TESTING LOGIC STABILITY!");
Make_debug_text_block (buf, 0, 105);
}
@@ -313,8 +313,8 @@ void Build_debug_text(void) {
Make_debug_text_block (largest_layer_info, 0, 60);
Make_debug_text_block (largest_sprite_info, 0, 75);
- // "waiting for person" indicator - set form FN_they_do &
- // FN_they_do_we_wait
+ // "waiting for person" indicator - set form fnTheyDo and
+ // fnTheyDoWeWait
if (speechScriptWaiting) {
sprintf(buf, "script waiting for %s (%d)",
diff --git a/sword2/defs.h b/sword2/defs.h
index 7f88352d14..eb940b55ab 100644
--- a/sword2/defs.h
+++ b/sword2/defs.h
@@ -76,13 +76,13 @@
#define SYSTEM_TESTING_TEXT VAR(1230)
#define SYSTEM_WANT_PREVIOUS_LINE VAR(1245)
-// 1=on 0=off (set in FN_add_human & FN_no_human)
+// 1=on 0=off (set in fnAddHuman and fnNoHuman)
#define MOUSE_AVAILABLE VAR(686)
-// used in FN_choose
+// used in fnChoose
#define AUTO_SELECTED VAR(1115)
-// see FN_start_conversation & FN_chooser
+// see fnStartConversation and fnChooser
#define CHOOSER_COUNT_FLAG VAR(15)
// signifies a demo mode
@@ -138,7 +138,7 @@
#define RESTORE_ICON 364
#define RESTART_ICON 342
-// res id of conversation exit icon, 'EXIT' menu icon (used in FN_choose)
+// res id of conversation exit icon, 'EXIT' menu icon (used in fnChoose)
#define EXIT_ICON 65
#endif
diff --git a/sword2/events.cpp b/sword2/events.cpp
index 0174715bc3..12131825e6 100644
--- a/sword2/events.cpp
+++ b/sword2/events.cpp
@@ -33,9 +33,9 @@ namespace Sword2 {
_event_unit event_list[MAX_events];
void Init_event_system(void) {
- for (int j = 0; j < MAX_events; j++) {
+ for (int i = 0; i < MAX_events; i++) {
//denotes free slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
}
}
@@ -43,8 +43,8 @@ void Init_event_system(void) {
uint32 CountEvents(void) {
uint32 count = 0;
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id)
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id)
count++;
}
@@ -52,65 +52,61 @@ uint32 CountEvents(void) {
}
#endif
-int32 FN_request_speech(int32 *params) {
+int32 Logic::fnRequestSpeech(int32 *params) {
// change current script - must be followed by a TERMINATE script
// directive
// params: 0 id of target to catch the event and startup speech
// servicing
- uint32 j = 0;
+ int i;
- while(1) {
- if (event_list[j].id == (uint32) params[0])
+ for (i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == (uint32) params[0])
break;
- if (!event_list[j].id)
+ if (!event_list[i].id)
break;
-
- j++;
}
- if (j == MAX_events)
- Con_fatal_error("FN_set_event out of event slots");
+ if (i == MAX_events)
+ Con_fatal_error("fnSetEvent out of event slots");
// found that slot
// id of person to stop
- event_list[j].id = params[0];
+ event_list[i].id = params[0];
// full script id to interact with - megas run their own 7th script
- event_list[j].interact_id = (params[0] * 65536) + 6;
+ event_list[i].interact_id = (params[0] * 65536) + 6;
return IR_CONT;
}
void Set_player_action_event(uint32 id, uint32 interact_id) {
- uint32 j = 0;
+ int i;
- while (1) {
- if (event_list[j].id == id)
+ for (i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == id)
break;
- if (!event_list[j].id)
+ if (!event_list[i].id)
break;
-
- j++;
}
- if (j == MAX_events)
+ if (i == MAX_events)
Con_fatal_error("Set_event out of event slots");
// found that slot
// id of person to stop
- event_list[j].id = id;
+ event_list[i].id = id;
// full script id of action script number 2
- event_list[j].interact_id = (interact_id * 65536) + 2;
+ event_list[i].interact_id = (interact_id * 65536) + 2;
}
-int32 FN_set_player_action_event(int32 *params) {
+int32 Logic::fnSetPlayerActionEvent(int32 *params) {
// we want to intercept the player character and have him interact
// with an object - from script this code is the same as the mouse
// engine calls when you click on an object - here, a third party
@@ -120,80 +116,74 @@ int32 FN_set_player_action_event(int32 *params) {
// params: 0 id to interact with
- uint32 j = 0;
-
// search for an existing event or a slot
- while(1) {
- if (event_list[j].id == CUR_PLAYER_ID)
- break;
+ int i;
- if (!event_list[j].id)
+ for (i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == CUR_PLAYER_ID)
break;
- j++;
+ if (!event_list[i].id)
+ break;
}
- if (j == MAX_events)
+ if (i == MAX_events)
Con_fatal_error("Set_event out of event slots");
// found that slot
// id of person to stop
- event_list[j].id = CUR_PLAYER_ID;
+ event_list[i].id = CUR_PLAYER_ID;
// full script id of action script number 2
- event_list[j].interact_id = (params[0] * 65536) + 2;
+ event_list[i].interact_id = (params[0] * 65536) + 2;
return IR_CONT;
}
-int32 FN_send_event(int32 *params) {
+int32 Logic::fnSendEvent(int32 *params) {
// we want to intercept the player character and have him interact
// with an object - from script
// params: 0 id to recieve event
// 1 script to run
- uint32 j = 0;
-
- debug(5, "FN_send_event(%d, %d)", params[0], params[1]);
-
// search for an existing event or a slot
- while(1) {
- if (event_list[j].id == (uint32) params[0])
- break;
+ int i;
- if (!event_list[j].id)
+ for (i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == (uint32) params[0])
break;
- j++;
+ if (!event_list[i].id)
+ break;
}
- if (j == MAX_events)
- Con_fatal_error("fn_send_event out of event slots");
+ if (i == MAX_events)
+ Con_fatal_error("fnSendEvent out of event slots");
// found that slot
// id of person to stop
- event_list[j].id = params[0];
+ event_list[i].id = params[0];
//full script id
- event_list[j].interact_id = params[1];
+ event_list[i].interact_id = params[1];
return IR_CONT;
}
-int32 FN_check_event_waiting(int32 *params) {
+int32 Logic::fnCheckEventWaiting(int32 *params) {
// returns yes/no in RESULT
- // no params
+ // params: none
RESULT = 0;
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == ID) {
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == ID) {
RESULT = 1;
break;
}
@@ -202,19 +192,19 @@ int32 FN_check_event_waiting(int32 *params) {
return IR_CONT;
}
-// like FN_check_event_waiting, but starts the event rather than setting
-// RESULT to 1
+// like fnCheckEventWaiting, but starts the event rather than setting RESULT
+// to 1
-int32 FN_check_for_event(int32 *params) {
- // no params
+int32 Logic::fnCheckForEvent(int32 *params) {
+ // params: none
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == ID) {
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == ID) {
// start the event
// run 3rd script of target object on level 1
- LLogic.logicOne(event_list[j].interact_id);
+ logicOne(event_list[i].interact_id);
// clear the event slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
return IR_TERMINATE;
}
}
@@ -222,36 +212,35 @@ int32 FN_check_for_event(int32 *params) {
return IR_CONT;
}
-// combination of FN_pause & FN_check_for_event
+// combination of fnPause and fnCheckForEvent
// - ie. does a pause, but also checks for event each cycle
-int32 FN_pause_for_event(int32 *params) {
+int32 Logic::fnPauseForEvent(int32 *params) {
// returns yes/no in RESULT
- // params
- // 0 pointer to object's logic structure
- // 1 number of game-cycles to pause
+ // params: 0 pointer to object's logic structure
+ // 1 number of game-cycles to pause
Object_logic *ob_logic = (Object_logic *)params[0];
// first, check for an event
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == ID) {
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == ID) {
// reset the 'looping' flag
ob_logic->looping = 0;
// start the event
// run 3rd script of target object on level 1
- LLogic.logicOne(event_list[j].interact_id);
+ logicOne(event_list[i].interact_id);
// clear the event slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
return IR_TERMINATE;
}
}
- // no event, so do the FN_pause bit
+ // no event, so do the fnPause bit
// start the pause
if (ob_logic->looping == 0) {
@@ -277,22 +266,21 @@ int32 FN_pause_for_event(int32 *params) {
}
bool Check_event_waiting(void) {
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == ID)
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == ID)
return true;
}
return false;
}
-int32 FN_clear_event(int32 *params) {
-// no params
-// no return vaule
+int32 Logic::fnClearEvent(int32 *params) {
+ // params: none
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == ID) {
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == ID) {
//clear the slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
return IR_CONT;
}
}
@@ -301,16 +289,16 @@ int32 FN_clear_event(int32 *params) {
}
void Start_event(void) {
- // call this from stuff like fn_walk
+ // call this from stuff like fnWalk
// you must follow with a return IR_TERMINATE
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == ID) {
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == ID) {
// run 3rd script of target object on level 1
- LLogic.logicOne(event_list[j].interact_id);
+ g_logic.logicOne(event_list[i].interact_id);
//clear the slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
return;
}
}
@@ -319,27 +307,29 @@ void Start_event(void) {
Con_fatal_error("Start_event can't find event for id %d", ID);
}
-int32 FN_start_event(int32 *params) {
- for (int j = 0; j < MAX_events; j++)
- if (event_list[j].id == ID) {
+int32 Logic::fnStartEvent(int32 *params) {
+ // params: none
+
+ for (int i = 0; i < MAX_events; i++)
+ if (event_list[i].id == ID) {
// run 3rd script of target object on level 1
- LLogic.logicOne(event_list[j].interact_id);
+ logicOne(event_list[i].interact_id);
// clear the slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
return IR_TERMINATE;
}
// oh dear - stop the system
- Con_fatal_error("FN_start_event can't find event for id %d", ID);
+ Con_fatal_error("fnStartEvent can't find event for id %d", ID);
return 0; // never called - but lets stop them bloody errors
}
void Kill_all_ids_events(uint32 id) {
- for (int j = 0; j < MAX_events; j++) {
- if (event_list[j].id == id) {
+ for (int i = 0; i < MAX_events; i++) {
+ if (event_list[i].id == id) {
// clear the slot
- event_list[j].id = 0;
+ event_list[i].id = 0;
}
}
}
diff --git a/sword2/events.h b/sword2/events.h
index 78ff68df52..27e88bebf1 100644
--- a/sword2/events.h
+++ b/sword2/events.h
@@ -34,11 +34,8 @@ struct _event_unit {
extern _event_unit event_list[MAX_events];
void Init_event_system(void);
-int32 FN_set_event(int32 *params);
void Set_player_action_event(uint32 id, uint32 interact_id);
-int32 FN_check_event_waiting(void);
void Start_event(void);
-int32 FN_start_event(void);
bool Check_event_waiting(void);
void Kill_all_ids_events(uint32 id);
diff --git a/sword2/function.cpp b/sword2/function.cpp
index 4a250892b4..eb19aca836 100644
--- a/sword2/function.cpp
+++ b/sword2/function.cpp
@@ -38,114 +38,115 @@ namespace Sword2 {
Object_graphic engine_graph; // global for engine
Object_mega engine_mega; // global for engine
-int32 FN_test_function(int32 *params) {
- // param 0 address of a flag
-
- debug(5, " TEST %d %d", params[0], RESULT);
+int32 Logic::fnTestFunction(int32 *params) {
+ // params: 0 address of a flag
return IR_CONT;
}
-int32 FN_test_flags(int32 *params) {
- // param 0 value of flag
-
- debug(5, "FN_test_flags %d, %d\n", params[0], params[1]);
+int32 Logic::fnTestFlags(int32 *params) {
+ // params: 0 value of flag
return IR_CONT;
}
-int32 FN_gosub(int32 *params) {
+int32 Logic::fnGosub(int32 *params) {
// hurray, script subroutines
- // param 0 id of script
- LLogic.logicUp(params[0]);
+ // params: 0 id of script
+
+ logicUp(params[0]);
// logic goes up - pc is saved for current level
return IR_GOSUB;
}
-int32 FN_new_script(int32 *params) {
+int32 Logic::fnNewScript(int32 *params) {
// change current script - must be followed by a TERMINATE script
// directive
- // param 0 id of script
- debug(5, "FN_new_script %d", params[0]);
+ // params: 0 id of script
// must clear this
PLAYER_ACTION = 0;
- LLogic.logicReplace(params[0]);
+ logicReplace(params[0]);
- //drop out no pc save - and around again
+ // drop out no pc save - and around again
return IR_TERMINATE;
}
-int32 FN_interact(int32 *params) {
+int32 Logic::fnInteract(int32 *params) {
// run targets action on a subroutine
// called by player on his base level 0 idle, for example
- // param 0 id of target from which we derive action script
- // reference
- debug(5, "FN_interact %d", params[0]);
+ // params: 0 id of target from which we derive action script
+ // reference
// must clear this
PLAYER_ACTION = 0;
// 3rd script of clicked on id
- LLogic.logicUp((params[0] * 65536) + 2);
+ logicUp((params[0] * 65536) + 2);
// out, up and around again - pc is saved for current level to be
// returned to
return IR_GOSUB;
}
-int32 FN_preload(int32 *params) {
+int32 Logic::fnPreLoad(int32 *params) {
// Open & close a resource.
+
// Forces a resource into memory before it's "officially" opened for
// use. eg. if an anim needs to run on smoothly from another,
// "preloading" gets it into memory in advance to avoid the cacheing
// delay that normally occurs before the first frame.
- res_man.open(params[0]); // open resource
- res_man.close(params[0]); // close resource
- return IR_CONT; // continue script
+ // params: 0 resource to preload
+
+ res_man.open(params[0]);
+ res_man.close(params[0]);
+ return IR_CONT;
}
-int32 FN_prefetch(int32 *params) {
+int32 Logic::fnPreFetch(int32 *params) {
// Go fetch resource in the background.
+ // params: 0 resource to fetch [guess]
+
return IR_CONT;
}
-int32 FN_fetch_wait(int32 *params) {
+int32 Logic::fnFetchWait(int32 *params) {
// Fetches a resource in the background but prevents the script from
// continuing until the resource is in memory.
+ // params: 0 resource to fetch [guess]
+
return IR_CONT;
}
-int32 FN_release(int32 *params) {
+int32 Logic::fnRelease(int32 *params) {
// Releases a resource from memory. Used for freeing memory for
// sprites that have just been used and will not be used again.
// Sometimes it is better to kick out a sprite straight away so that
// the memory can be used for more frequent animations.
+ // params: 0 resource to release [guess]
+
return IR_CONT;
}
-int32 FN_random(int32 *params) {
+int32 Logic::fnRandom(int32 *params) {
// Generates a random number between 'min' & 'max' inclusive, and
// sticks it in the script flag 'result'
// params: 0 min
// 1 max
- // return_value = random integer between min and max, inclusive
RESULT = g_sword2->_rnd.getRandomNumberRng(params[0], params[1]);
-
- // continue script
return IR_CONT;
}
-int32 FN_pause(int32 *params) {
+int32 Logic::fnPause(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 number of game-cycles to pause
@@ -176,7 +177,7 @@ int32 FN_pause(int32 *params) {
}
}
-int32 FN_random_pause(int32 *params) {
+int32 Logic::fnRandomPause(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 minimum number of game-cycles to pause
// 2 maximum number of game-cycles to pause
@@ -185,28 +186,26 @@ int32 FN_random_pause(int32 *params) {
int32 pars[2];
if (ob_logic->looping == 0) {
- pars[0] = params[1]; // min
- pars[1] = params[2]; // max
+ pars[0] = params[1];
+ pars[1] = params[2];
- FN_random(pars);
-
- // random value between 'min' & 'max' inclusive
+ fnRandom(pars);
pars[1] = RESULT;
}
- pars[0] = params[0]; // &logic
- return FN_pause(pars);
+ pars[0] = params[0];
+ return fnPause(pars);
}
-int32 FN_pass_graph(int32 *params) {
+int32 Logic::fnPassGraph(int32 *params) {
// makes an engine local copy of passed graphic_structure and
// mega_structure - run script 4 of an object to request this
- // used by FN_turn_to(id) etc
+ // used by fnTurnTo(id) etc
//
// remember, we cannot simply read a compact any longer but instead
// must request it from the object itself
- //params 0 pointer to a graphic structure (might not need this?)
+ // params: 0 pointer to a graphic structure (might not need this?)
memcpy(&engine_graph, (uint8 *) params[0], sizeof(Object_graphic));
@@ -214,24 +213,25 @@ int32 FN_pass_graph(int32 *params) {
return IR_CONT;
}
-int32 FN_pass_mega(int32 *params) {
+int32 Logic::fnPassMega(int32 *params) {
// makes an engine local copy of passed graphic_structure and
// mega_structure - run script 4 of an object to request this
- // used by FN_turn_to(id) etc
+ // used by fnTurnTo(id) etc
//
// remember, we cannot simply read a compact any longer but instead
// must request it from the object itself
- // params 0 pointer to a mega structure
+ // params: 0 pointer to a mega structure
memcpy(&engine_mega, (uint8 *) params[0], sizeof(Object_mega));
- //makes no odds
+ // makes no odds
return IR_CONT;
}
-int32 FN_set_value(int32 *params) {
+int32 Logic::fnSetValue(int32 *params) {
// temp. function!
+
// used for setting far-referenced megaset resource field in mega
// object, from start script
@@ -258,12 +258,12 @@ uint8 red[4] = { 255, 0, 0, 0 };
uint8 green[4] = { 0, 255, 0, 0 };
uint8 blue[4] = { 0, 0, 255, 0 };
-int32 FN_flash(int32 *params) {
+int32 Logic::fnFlash(int32 *params) {
// flash colour 0 (ie. border) - useful during script development
- // eg. FN_flash(BLUE) where a text line is missed; RED when some code
+ // eg. fnFlash(BLUE) where a text line is missed; RED when some code
// missing, etc
- // params 0: colour to flash
+ // params: 0 colour to flash
#ifdef _SWORD2_DEBUG
// what colour?
@@ -294,7 +294,7 @@ int32 FN_flash(int32 *params) {
}
-int32 FN_colour(int32 *params) {
+int32 Logic::fnColour(int32 *params) {
// set border colour - useful during script development
// eg. set to colour during a timer situation, then black when timed
// out
@@ -325,10 +325,10 @@ int32 FN_colour(int32 *params) {
return IR_CONT;
}
-int32 FN_display_msg(int32 *params) {
+int32 Logic::fnDisplayMsg(int32 *params) {
// Display a message to the user on the screen.
- //
- // params 0: Text number of message to be displayed.
+
+ // params: 0 Text number of message to be displayed.
uint32 local_text = params[0] & 0xffff;
uint32 text_res = params[0] / SIZE;
@@ -345,24 +345,24 @@ int32 FN_display_msg(int32 *params) {
return IR_CONT;
}
-int32 FN_reset_globals(int32 *params) {
- // FN_reset_globals is used by the demo - so it can loop back &
- // restart itself
+int32 Logic::fnResetGlobals(int32 *params) {
+ // fnResetGlobals is used by the demo - so it can loop back & restart
+ // itself
+
+ // params: none
int32 size;
uint32 *globals;
- int j;
size = res_man.fetchLen(1);
size -= sizeof(_standardHeader);
- debug(5, "globals size %d", size / 4);
+ debug(5, "globals size: %d", size);
globals = (uint32 *) ((uint8 *) res_man.open(1) + sizeof(_standardHeader));
// blank each global variable
- for (j = 0; j < size / 4; j++)
- globals[j] = 0;
+ memset(globals, 0, size);
res_man.close(1);
@@ -370,7 +370,7 @@ int32 FN_reset_globals(int32 *params) {
res_man.killAllObjects(0);
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
- // - this is taken from FN_init_background
+ // - this is taken from fnInitBackground
// switch on scrolling (2 means first time on screen)
this_screen.scroll_flag = 2;
@@ -378,12 +378,12 @@ int32 FN_reset_globals(int32 *params) {
return IR_CONT;
}
-int32 FN_play_credits(int32 *params) {
- // params: none
-
+int32 Logic::fnPlayCredits(int32 *params) {
// This function just quits the game if this is the playable demo, ie.
// credits are NOT played in the demo any more!
+ // params: none
+
if (!DEMO) {
uint8 oldPal[1024];
uint8 tmpPal[1024];
@@ -413,7 +413,7 @@ int32 FN_play_credits(int32 *params) {
pars[0] = 309;
pars[1] = FX_SPOT;
- FN_play_music(pars);
+ fnPlayMusic(pars);
music_length = 1000 * g_sound->musicTimeRemaining();
@@ -439,7 +439,7 @@ int32 FN_play_credits(int32 *params) {
g_system->delay_msecs(30);
}
- FN_stop_music(NULL);
+ fnStopMusic(NULL);
g_sound->restoreMusicState();
g_display->setPalette(0, 256, oldPal, RDPAL_FADE);
diff --git a/sword2/icons.cpp b/sword2/icons.cpp
index 8de09452a1..06a80e585d 100644
--- a/sword2/icons.cpp
+++ b/sword2/icons.cpp
@@ -23,6 +23,7 @@
#include "bs2/defs.h"
#include "bs2/icons.h"
#include "bs2/interpreter.h"
+#include "bs2/logic.h"
#include "bs2/mouse.h"
namespace Sword2 {
@@ -34,10 +35,8 @@ uint32 total_temp = 0;
menu_object master_menu_list[TOTAL_engine_pockets];
uint32 total_masters=0;
-int32 FN_add_menu_object(int32 *params) {
- // param 0 pointer to a menu_object structure to copy down
-
- debug(5, "FN_add_menu_object icon res");
+int32 Logic::fnAddMenuObject(int32 *params) {
+ // params: 0 pointer to a menu_object structure to copy down
#ifdef _SWORD2_DEBUG
if (total_temp == TOTAL_engine_pockets)
@@ -52,12 +51,14 @@ int32 FN_add_menu_object(int32 *params) {
return IR_CONT;
}
-int32 FN_refresh_inventory(int32 *params) {
+int32 Logic::fnRefreshInventory(int32 *params) {
// called from 'menu_look_or_combine' script in 'menu_master' object
// to update the menu to display a combined object while George runs
// voice-over. Note that 'object_held' must be set to the graphic of
// the combined object
+ // params: none
+
// can reset this now
COMBINE_BASE = 0;
diff --git a/sword2/interpreter.cpp b/sword2/interpreter.cpp
index 407767340b..3a7a398c4b 100644
--- a/sword2/interpreter.cpp
+++ b/sword2/interpreter.cpp
@@ -21,6 +21,7 @@
#include "bs2/driver/driver96.h"
#include "bs2/console.h"
#include "bs2/interpreter.h"
+#include "bs2/logic.h"
namespace Sword2 {
@@ -33,254 +34,175 @@ namespace Sword2 {
// The machine code table
-int32 FN_test_function(int32 *params);
-int32 FN_test_flags(int32 *params);
-int32 FN_register_start_point(int32 *params);
-int32 FN_init_background(int32 *params);
-int32 FN_set_session(int32 *params);
-int32 FN_back_sprite(int32 *params);
-int32 FN_sort_sprite(int32 *params);
-int32 FN_fore_sprite(int32 *params);
-int32 FN_register_mouse(int32 *params);
-int32 FN_anim(int32 *);
-int32 FN_random(int32 *);
-int32 FN_preload(int32 *);
-int32 FN_add_subject(int32 *);
-int32 FN_interact(int32 *);
-int32 FN_choose(int32 *);
-int32 FN_walk(int32 *);
-int32 FN_walk_to_anim(int32 *); // walk to start position of anim
-int32 FN_turn(int32 *); // turn to (dir)
-int32 FN_stand_at(int32 *); // stand at (x,y,dir)
-int32 FN_stand(int32 *); // stand facing (dir)
-int32 FN_stand_after_anim(int32 *); // stand at end position of anim
-int32 FN_pause(int32 *);
-int32 FN_mega_table_anim(int32 *);
-int32 FN_add_menu_object(int32 *);
-int32 FN_start_conversation(int32 *);
-int32 FN_end_conversation(int32 *);
-int32 FN_set_frame(int32 *);
-int32 FN_random_pause(int32 *);
-int32 FN_register_frame(int32 *);
-int32 FN_no_sprite(int32 *);
-int32 FN_send_sync(int32 *);
-int32 FN_update_player_stats(int32 *);
-int32 FN_pass_graph(int32 *);
-int32 FN_init_floor_mouse(int32 *);
-int32 FN_pass_mega(int32 *);
-int32 FN_face_xy(int32 *);
-int32 FN_end_session(int32 *);
-int32 FN_no_human(int32 *);
-int32 FN_add_human(int32 *);
-int32 FN_we_wait(int32 *);
-int32 FN_they_do_we_wait(int32 *);
-int32 FN_they_do(int32 *);
-int32 FN_walk_to_talk_to_mega(int32 *);
-int32 FN_fade_down(int32 *);
-int32 FN_i_speak(int32 *);
-int32 FN_total_restart(int32 *);
-int32 FN_set_walkgrid(int32 *);
-int32 FN_speech_process(int32 *);
-int32 FN_set_scaling(int32 *);
-int32 FN_start_event(int32 *);
-int32 FN_check_event_waiting(int32 *);
-int32 FN_request_speech(int32 *);
-int32 FN_gosub(int32 *);
-int32 FN_timed_wait(int32 *);
-int32 FN_play_fx(int32 *);
-int32 FN_stop_fx(int32 *);
-int32 FN_play_music(int32 *);
-int32 FN_stop_music(int32 *);
-int32 FN_set_value(int32 *);
-int32 FN_new_script(int32 *);
-int32 FN_get_sync(int32 *);
-int32 FN_wait_sync(int32 *);
-int32 FN_register_walkgrid(int32 *);
-int32 FN_reverse_mega_table_anim(int32 *);
-int32 FN_reverse_anim(int32 *);
-int32 FN_add_to_kill_list(int32 *);
-int32 FN_set_standby_coords(int32 *);
-int32 FN_back_par0_sprite(int32 *params);
-int32 FN_back_par1_sprite(int32 *params);
-int32 FN_fore_par0_sprite(int32 *params);
-int32 FN_fore_par1_sprite(int32 *params);
-int32 FN_set_player_action_event(int32 *params);
-int32 FN_set_scroll_coordinate(int32 *params);
-int32 FN_stand_at_anim(int32 *params);
-int32 FN_set_scroll_left_mouse(int32 *params);
-int32 FN_set_scroll_right_mouse(int32 *params);
-int32 FN_colour(int32 *params);
-int32 FN_flash(int32 *params);
-int32 FN_prefetch(int32 *params);
-int32 FN_get_player_savedata(int32 *params);
-int32 FN_pass_player_savedata(int32 *params);
-int32 FN_send_event(int32 *params);
-int32 FN_add_walkgrid(int32 *params);
-int32 FN_remove_walkgrid(int32 *params);
-int32 FN_check_for_event(int32 *params);
-int32 FN_pause_for_event(int32 *params);
-int32 FN_clear_event(int32 *params);
-int32 FN_face_mega(int32 *params);
-int32 FN_play_sequence(int32 *params);
-int32 FN_shaded_sprite(int32 *params);
-int32 FN_unshaded_sprite(int32 *params);
-int32 FN_fade_up(int32 *params);
-int32 FN_display_msg(int32 *params);
-int32 FN_set_object_held(int32 *params);
-int32 FN_add_sequence_text(int32 *params);
-int32 FN_reset_globals(int32 *params);
-int32 FN_set_palette(int32 *params);
-int32 FN_register_pointer_text(int32 *params);
-int32 FN_fetch_wait(int32 *params);
-int32 FN_release(int32 *params);
-int32 FN_sound_fetch(int32 *params);
-int32 FN_prepare_music(int32 *params);
-int32 FN_smacker_lead_in(int32 *params);
-int32 FN_smacker_lead_out(int32 *params);
-int32 FN_stop_all_fx(int32 *params);
-int32 FN_check_player_activity(int32 *params);
-int32 FN_reset_player_activity_delay(int32 *params);
-int32 FN_check_music_playing(int32 *params);
-int32 FN_play_credits(int32 *params);
-int32 FN_set_scroll_speed_normal(int32 *params);
-int32 FN_set_scroll_speed_slow(int32 *params);
-int32 FN_remove_chooser(int32 *params);
-int32 FN_set_fx_vol_and_pan(int32 *params);
-int32 FN_set_fx_vol(int32 *params);
-int32 FN_restore_game(int32 *params);
-int32 FN_refresh_inventory(int32 *params);
-int32 FN_change_shadows(int32 *params);
-
#define MAX_FN_NUMBER 117
-extern int32 (*McodeTable[]) (int32 *);
-
// Point to the global variable data
int32 *globalInterpreterVariables2 = NULL;
int g_debugFlag = 0; // Set this to turn debugging on
-int32 (*McodeTable[MAX_FN_NUMBER + 1]) (int32 *) = {
- FN_test_function,
- FN_test_flags,
- FN_register_start_point,
- FN_init_background,
- FN_set_session,
- FN_back_sprite,
- FN_sort_sprite,
- FN_fore_sprite,
- FN_register_mouse,
- FN_anim,
- FN_random,
- FN_preload,
- FN_add_subject,
- FN_interact,
- FN_choose,
- FN_walk,
- FN_walk_to_anim,
- FN_turn,
- FN_stand_at,
- FN_stand,
- FN_stand_after_anim,
- FN_pause,
- FN_mega_table_anim,
- FN_add_menu_object,
- FN_start_conversation,
- FN_end_conversation,
- FN_set_frame,
- FN_random_pause,
- FN_register_frame,
- FN_no_sprite,
- FN_send_sync,
- FN_update_player_stats,
- FN_pass_graph,
- FN_init_floor_mouse,
- FN_pass_mega,
- FN_face_xy,
- FN_end_session,
- FN_no_human,
- FN_add_human,
- FN_we_wait,
- FN_they_do_we_wait,
- FN_they_do,
- FN_walk_to_talk_to_mega,
- FN_fade_down,
- FN_i_speak,
- FN_total_restart,
- FN_set_walkgrid,
- FN_speech_process,
- FN_set_scaling,
- FN_start_event,
- FN_check_event_waiting,
- FN_request_speech,
- FN_gosub,
- FN_timed_wait,
- FN_play_fx,
- FN_stop_fx,
- FN_play_music,
- FN_stop_music,
- FN_set_value,
- FN_new_script,
- FN_get_sync,
- FN_wait_sync,
- FN_register_walkgrid,
- FN_reverse_mega_table_anim,
- FN_reverse_anim,
- FN_add_to_kill_list,
- FN_set_standby_coords,
- FN_back_par0_sprite,
- FN_back_par1_sprite,
- FN_fore_par0_sprite,
- FN_fore_par1_sprite,
- FN_set_player_action_event,
- FN_set_scroll_coordinate,
- FN_stand_at_anim,
- FN_set_scroll_left_mouse,
- FN_set_scroll_right_mouse,
- FN_colour,
- FN_flash,
- FN_prefetch,
- FN_get_player_savedata,
- FN_pass_player_savedata,
- FN_send_event,
- FN_add_walkgrid,
- FN_remove_walkgrid,
- FN_check_for_event,
- FN_pause_for_event,
- FN_clear_event,
- FN_face_mega,
- FN_play_sequence,
- FN_shaded_sprite,
- FN_unshaded_sprite,
- FN_fade_up,
- FN_display_msg,
- FN_set_object_held,
- FN_add_sequence_text,
- FN_reset_globals,
- FN_set_palette,
- FN_register_pointer_text,
- FN_fetch_wait,
- FN_release,
- FN_prepare_music,
- FN_sound_fetch,
- FN_prepare_music,
- FN_smacker_lead_in,
- FN_smacker_lead_out,
- FN_stop_all_fx,
- FN_check_player_activity,
- FN_reset_player_activity_delay,
- FN_check_music_playing,
- FN_play_credits,
- FN_set_scroll_speed_normal,
- FN_set_scroll_speed_slow,
- FN_remove_chooser,
- FN_set_fx_vol_and_pan,
- FN_set_fx_vol,
- FN_restore_game,
- FN_refresh_inventory,
- FN_change_shadows,
+#define OPCODE(x, y) { x, &Logic::y, #y }
+
+void Logic::setupOpcodes(void) {
+ static const OpcodeEntry opcodes[MAX_FN_NUMBER + 1] = {
+ /* 00 */
+ OPCODE(1, fnTestFunction),
+ OPCODE(1, fnTestFlags),
+ OPCODE(2, fnRegisterStartPoint),
+ OPCODE(2, fnInitBackground),
+ /* 04 */
+ OPCODE(1, fnSetSession),
+ OPCODE(1, fnBackSprite),
+ OPCODE(1, fnSortSprite),
+ OPCODE(1, fnForeSprite),
+ /* 08 */
+ OPCODE(1, fnRegisterMouse),
+ OPCODE(3, fnAnim),
+ OPCODE(2, fnRandom),
+ OPCODE(1, fnPreLoad),
+ /* 0C */
+ OPCODE(2, fnAddSubject),
+ OPCODE(1, fnInteract),
+ OPCODE(0, fnChoose),
+ OPCODE(7, fnWalk),
+ /* 10 */
+ OPCODE(5, fnWalkToAnim),
+ OPCODE(6, fnTurn),
+ OPCODE(5, fnStandAt),
+ OPCODE(3, fnStand),
+ /* 14 */
+ OPCODE(3, fnStandAfterAnim),
+ OPCODE(2, fnPause),
+ OPCODE(4, fnMegaTableAnim),
+ OPCODE(1, fnAddMenuObject),
+ /* 18 */
+ OPCODE(0, fnStartConversation),
+ OPCODE(0, fnEndConversation),
+ OPCODE(3, fnSetFrame),
+ OPCODE(3, fnRandomPause),
+ /* 1C */
+ OPCODE(3, fnRegisterFrame),
+ OPCODE(1, fnNoSprite),
+ OPCODE(2, fnSendSync),
+ OPCODE(1, fnUpdatePlayerStats),
+ /* 20 */
+ OPCODE(1, fnPassGraph),
+ OPCODE(1, fnInitFloorMouse),
+ OPCODE(1, fnPassMega),
+ OPCODE(6, fnFaceXY),
+ /* 24 */
+ OPCODE(1, fnEndSession),
+ OPCODE(0, fnNoHuman),
+ OPCODE(0, fnAddHuman),
+ OPCODE(1, fnWeWait),
+ /* 28 */
+ OPCODE(8, fnTheyDoWeWait),
+ OPCODE(7, fnTheyDo),
+ OPCODE(6, fnWalkToTalkToMega),
+ OPCODE(0, fnFadeDown),
+ /* 2C */
+ OPCODE(0, fnISpeak),
+ OPCODE(0, fnTotalRestart),
+ OPCODE(0, fnSetWalkGrid),
+ OPCODE(5, fnSpeechProcess),
+ /* 30 */
+ OPCODE(3, fnSetScaling),
+ OPCODE(0, fnStartEvent),
+ OPCODE(0, fnCheckEventWaiting),
+ OPCODE(1, fnRequestSpeech),
+ /* 34 */
+ OPCODE(1, fnGosub),
+ OPCODE(3, fnTimedWait),
+ OPCODE(5, fnPlayFx),
+ OPCODE(1, fnStopFx),
+ /* 38 */
+ OPCODE(2, fnPlayMusic),
+ OPCODE(0, fnStopMusic),
+ OPCODE(2, fnSetValue),
+ OPCODE(1, fnNewScript),
+ /* 3C */
+ OPCODE(0, fnGetSync),
+ OPCODE(0, fnWaitSync),
+ OPCODE(0, fnRegisterWalkGrid),
+ OPCODE(4, fnReverseMegaTableAnim),
+ /* 40 */
+ OPCODE(3, fnReverseAnim),
+ OPCODE(0, fnAddToKillList),
+ OPCODE(3, fnSetStandbyCoords),
+ OPCODE(1, fnBackPar0Sprite),
+ /* 44 */
+ OPCODE(1, fnBackPar1Sprite),
+ OPCODE(1, fnForePar0Sprite),
+ OPCODE(1, fnForePar1Sprite),
+ OPCODE(1, fnSetPlayerActionEvent),
+ /* 48 */
+ OPCODE(2, fnSetScrollCoordinate),
+ OPCODE(3, fnStandAtAnim),
+ OPCODE(1, fnSetScrollLeftMouse),
+ OPCODE(1, fnSetScrollRightMouse),
+ /* 4C */
+ OPCODE(1, fnColour),
+ OPCODE(1, fnFlash),
+ OPCODE(1, fnPreFetch),
+ OPCODE(3, fnGetPlayerSaveData),
+ /* 50 */
+ OPCODE(3, fnPassPlayerSaveData),
+ OPCODE(2, fnSendEvent),
+ OPCODE(1, fnAddWalkGrid),
+ OPCODE(1, fnRemoveWalkGrid),
+ /* 54 */
+ OPCODE(0, fnCheckForEvent),
+ OPCODE(2, fnPauseForEvent),
+ OPCODE(0, fnClearEvent),
+ OPCODE(5, fnFaceMega),
+ /* 58 */
+ OPCODE(2, fnPlaySequence),
+ OPCODE(1, fnShadedSprite),
+ OPCODE(1, fnUnshadedSprite),
+ OPCODE(0, fnFadeUp),
+ /* 60 */
+ OPCODE(1, fnDisplayMsg),
+ OPCODE(0, fnSetObjectHeld),
+ OPCODE(3, fnAddSequenceText),
+ OPCODE(0, fnResetGlobals),
+ /* 64 */
+ OPCODE(1, fnSetPalette),
+ OPCODE(1, fnRegisterPointerText),
+ OPCODE(1, fnFetchWait),
+ OPCODE(1, fnRelease),
+ /* 68 */
+ OPCODE(1, fnPrepareMusic),
+ OPCODE(1, fnSoundFetch),
+ OPCODE(1, fnPrepareMusic), // Again, apparently
+ OPCODE(1, fnSmackerLeadIn),
+ /* 6C */
+ OPCODE(1, fnSmackerLeadOut),
+ OPCODE(0, fnStopAllFx),
+ OPCODE(1, fnCheckPlayerActivity),
+ OPCODE(0, fnResetPlayerActivityDelay),
+ /* 70 */
+ OPCODE(0, fnCheckMusicPlaying),
+ OPCODE(0, fnPlayCredits),
+ OPCODE(0, fnSetScrollSpeedNormal),
+ OPCODE(0, fnSetScrollSpeedSlow),
+ /* 74 */
+ OPCODE(0, fnRemoveChooser),
+ OPCODE(3, fnSetFxVolAndPan),
+ OPCODE(3, fnSetFxVol),
+ OPCODE(0, fnRestoreGame),
+ /* 78 */
+ OPCODE(0, fnRefreshInventory),
+ OPCODE(0, fnChangeShadows)
+ };
+
+ _opcodes = opcodes;
};
+int32 Logic::executeOpcode(int i, int32 *params) {
+ OpcodeProc op = _opcodes[i].proc;
+ return (this->*op) (params);
+}
+
#define CHECKSTACKPOINTER2 assert(stackPointer2 >= 0 && stackPointer2 < STACK_SIZE);
#define PUSHONSTACK(x) { stack2[stackPointer2] = (x); stackPointer2++; CHECKSTACKPOINTER2 }
#define POPOFFSTACK(x) { x = stack2[stackPointer2 - 1]; stackPointer2--; CHECKSTACKPOINTER2 }
@@ -329,10 +251,10 @@ int RunScript(char *scriptData, char *objectData, uint32 *offset) {
if (*offset < noScripts) {
ip = READ_LE_UINT32((const int *) code + *offset + 1);
- debug(5, "Start script %d with offset %d",*offset,ip);
+ debug(5, "Start script %d with offset %d", *offset, ip);
} else {
ip = *offset;
- debug(5, "Start script with offset %d",ip);
+ debug(5, "Start script with offset %d", ip);
}
code += noScripts * sizeof(int) + sizeof(int);
@@ -399,7 +321,10 @@ int RunScript(char *scriptData, char *objectData, uint32 *offset) {
// amount to adjust stack by (no of parameters)
Read8ip(value);
debug(5, "Call mcode %d with stack = %x", parameter, stack2 + stackPointer2 - value);
- retVal = McodeTable[parameter](stack2 + stackPointer2 - value);
+
+ retVal = g_logic.executeOpcode(parameter, stack2 + stackPointer2 - value);
+
+// retVal = g_logic._opcodes[parameter].proc(stack2 + stackPointer2 - value);
stackPointer2 -= value;
CHECKSTACKPOINTER2
diff --git a/sword2/layers.cpp b/sword2/layers.cpp
index 24e71a666e..d6b7674819 100644
--- a/sword2/layers.cpp
+++ b/sword2/layers.cpp
@@ -31,9 +31,10 @@
#include "bs2/debug.h"
#include "bs2/header.h"
#include "bs2/layers.h"
+#include "bs2/logic.h"
#include "bs2/protocol.h"
#include "bs2/resman.h"
-#include "bs2/sound.h" // for Clear_fx_queue() called from FN_init_background()
+#include "bs2/sound.h" // for Clear_fx_queue() called from fnInitBackground()
namespace Sword2 {
@@ -42,10 +43,11 @@ namespace Sword2 {
screen_info this_screen;
-int32 FN_init_background(int32 *params) {
+int32 Logic::fnInitBackground(int32 *params) {
+ // this screen defines the size of the back buffer
+
// params: 0 res id of normal background layer - cannot be 0
// 1 1 yes 0 no for a new palette
- // this screen defines the size of the back buffer
_multiScreenHeader *screenLayerTable;
_screenHeader *screen_head;
@@ -60,10 +62,10 @@ int32 FN_init_background(int32 *params) {
Clear_fx_queue();
#ifdef _SWORD2_DEBUG
- debug(5, "FN_init_background(%d)", *params);
+ debug(5, "fnInitBackground(%d)", params[0]);
- if (!*params) {
- Con_fatal_error("ERROR: FN_set_background cannot have 0 for background layer id!");
+ if (!params[0]) {
+ Con_fatal_error("ERROR: fnInitBackground cannot have 0 for background layer id!");
}
#endif
@@ -196,7 +198,7 @@ int32 FN_init_background(int32 *params) {
return 1;
}
-// called from FN_init_background & also from control panel
+// called from fnInitBackground and also from control panel
void SetUpBackgroundLayers(void) {
_multiScreenHeader *screenLayerTable;
diff --git a/sword2/layers.h b/sword2/layers.h
index f96829e44c..b9a9f066e0 100644
--- a/sword2/layers.h
+++ b/sword2/layers.h
@@ -25,7 +25,7 @@ namespace Sword2 {
typedef struct {
uint16 scroll_offset_x; // Position x
uint16 scroll_offset_y; // Position y
- uint16 max_scroll_offset_x; // Calc'ed in FN_init_background
+ uint16 max_scroll_offset_x; // Calc'ed in fnInitBackground
uint16 max_scroll_offset_y;
int16 player_feet_x; // Feet coordinates to use - cant just
int16 player_feet_y; // fetch the player compact anymore
@@ -48,9 +48,7 @@ typedef struct {
extern screen_info this_screen;
-int32 FN_init_background(int32 *params);
-
-// called from control panel (as well as inside FN_init_background)
+// called from control panel (as well as inside fnInitBackground)
void SetUpBackgroundLayers(void);
diff --git a/sword2/logic.cpp b/sword2/logic.cpp
index d173767a37..c3654ba042 100644
--- a/sword2/logic.cpp
+++ b/sword2/logic.cpp
@@ -30,7 +30,7 @@
namespace Sword2 {
-logic LLogic;
+Logic g_logic;
#define LEVEL (_curObjectHub->logic_level)
@@ -42,7 +42,7 @@ uint32 object_kill_list[OBJECT_KILL_LIST_SIZE];
// keeps note of no. of objects in the kill list
uint32 kills = 0;
-int logic::processSession(void) {
+int Logic::processSession(void) {
// do one cycle of the current session
uint32 run_list;
@@ -218,7 +218,7 @@ int logic::processSession(void) {
return 1;
}
-void logic::expressChangeSession(uint32 sesh_id) {
+void Logic::expressChangeSession(uint32 sesh_id) {
// a game-object can bring an immediate halt to the session and cause
// a new one to start without a screen update
@@ -237,7 +237,7 @@ void logic::expressChangeSession(uint32 sesh_id) {
Init_sync_system();
- // reset walkgrid list (see FN_register_walkgrid)
+ // reset walkgrid list (see fnRegisterWalkGrid)
router.clearWalkGridList();
// stops all fx & clears the queue
@@ -247,7 +247,7 @@ void logic::expressChangeSession(uint32 sesh_id) {
router.freeAllRouteMem();
}
-void logic::naturalChangeSession(uint32 sesh_id) {
+void Logic::naturalChangeSession(uint32 sesh_id) {
// FIXME: This function doesn't seem to be used anywhere
// A new session will begin next game cycle. The current cycle will
@@ -256,37 +256,38 @@ void logic::naturalChangeSession(uint32 sesh_id) {
_currentRunList = sesh_id;
}
-uint32 logic::getRunList(void) {
+uint32 Logic::getRunList(void) {
// pass back the private _currentRunList variable
return _currentRunList;
}
-int32 FN_set_session(int32 *params) {
+int32 Logic::fnSetSession(int32 *params) {
// used by player invoked start scripts
- // param 0 id of new run list
- LLogic.expressChangeSession(params[0]);
+ // params: 0 id of new run list
+
+ expressChangeSession(params[0]);
return IR_CONT;
}
-int32 FN_end_session(int32 *params) {
+int32 Logic::fnEndSession(int32 *params) {
// causes no more objects in this logic loop to be processed
// the logic engine will restart at the beginning of the new list
// !!the current screen will not be drawn!!
- // param 0 id of new run-list
+ // params: 0 id of new run-list
// terminate current and change to next run-list
- LLogic.expressChangeSession(params[0]);
+ expressChangeSession(params[0]);
// stop the script - logic engine will now go around and the new
// screen will begin
return IR_STOP;
}
-void logic::logicUp(uint32 new_script) {
+void Logic::logicUp(uint32 new_script) {
// move the current object up a level
- // called by FN_gosub command - remember, only the logic object has
+ // called by fnGosub command - remember, only the logic object has
// access to _curObjectHub
// going up a level - and we'll keeping going this cycle
@@ -304,7 +305,7 @@ void logic::logicUp(uint32 new_script) {
_curObjectHub->script_pc[LEVEL] = new_script & 0xffff;
}
-void logic::logicOne(uint32 new_script) {
+void Logic::logicOne(uint32 new_script) {
// force to level one
LEVEL = 1;
@@ -314,7 +315,7 @@ void logic::logicOne(uint32 new_script) {
_curObjectHub->script_pc[1] = new_script & 0xffff;
}
-void logic::logicReplace(uint32 new_script) {
+void Logic::logicReplace(uint32 new_script) {
// change current logic - script must quit with a TERMINATE directive
// - which does not write to &pc
@@ -323,7 +324,7 @@ void logic::logicReplace(uint32 new_script) {
_curObjectHub->script_pc[LEVEL] = new_script & 0xffff;
}
-uint32 logic::examineRunList(void) {
+uint32 Logic::examineRunList(void) {
uint32 *game_object_list;
_standardHeader *file_header;
int scrolls = 0;
@@ -372,7 +373,7 @@ uint32 logic::examineRunList(void) {
return 1;
}
-void logic::totalRestart(void) {
+void Logic::totalRestart(void) {
// reset the object restart script 1 on level 0
LEVEL = 0;
@@ -382,17 +383,19 @@ void logic::totalRestart(void) {
_curObjectHub->script_pc[0] = 1;
}
-int32 FN_total_restart(int32 *params) {
+int32 Logic::fnTotalRestart(int32 *params) {
// mega runs this to restart its base logic again - like being cached
// in again
- LLogic.totalRestart();
+ // params: none
+
+ totalRestart();
// drop out without saving pc and go around again
return IR_TERMINATE;
}
-int32 FN_add_to_kill_list(int32 *params) {
+int32 Logic::fnAddToKillList(int32 *params) {
// call *once* from object's logic script - ie. in startup code
// - so not re-called every time script drops off & restarts!
@@ -401,7 +404,7 @@ int32 FN_add_to_kill_list(int32 *params) {
// screen, which causes this object's startup logic to be re-run
// every time we enter the screen. "Which is nice"
- // params: none
+ // params: none
uint32 entry;
@@ -420,7 +423,7 @@ int32 FN_add_to_kill_list(int32 *params) {
#ifdef _SWORD2_DEBUG
// no room at the inn
if (kills == OBJECT_KILL_LIST_SIZE)
- Con_fatal_error("List full in FN_add_to_kill_list(%u)", ID);
+ Con_fatal_error("List full in fnAddToKillList(%u)", ID);
#endif
// add this 'ID' to the kill list
@@ -441,14 +444,14 @@ int32 FN_add_to_kill_list(int32 *params) {
return IR_CONT;
}
-void logic::processKillList(void) {
+void Logic::processKillList(void) {
for (uint32 j = 0; j < kills; j++)
res_man.remove(object_kill_list[j]);
kills = 0;
}
-void logic::resetKillList(void) {
+void Logic::resetKillList(void) {
kills = 0;
}
diff --git a/sword2/logic.h b/sword2/logic.h
index 92a2971291..0bf985b4e8 100644
--- a/sword2/logic.h
+++ b/sword2/logic.h
@@ -29,8 +29,158 @@ namespace Sword2 {
#define TREE_SIZE 3
-class logic {
+class Logic {
+private:
+ void setupOpcodes(void);
+
+ // FIXME: Some opcodes pass pointers in integer variables. I don't
+ // think that's entirely portable.
+
+ typedef int32 (Logic::*OpcodeProc)(int32 *);
+ struct OpcodeEntry {
+ byte numArgs;
+ OpcodeProc proc;
+ const char *desc;
+ };
+
+ const OpcodeEntry *_opcodes;
+
+ // denotes the res id of the game-object-list in current use
+ uint32 _currentRunList;
+
+ void processKillList(void);
+
+ //pc during logic loop
+ uint32 _pc;
+
+ // each object has one of these tacked onto the beginning
+ _object_hub *_curObjectHub;
+
public:
+ Logic() {
+ setupOpcodes();
+ }
+
+ int32 executeOpcode(int op, int32 *params);
+
+ int32 fnTestFunction(int32 *params);
+ int32 fnTestFlags(int32 *params);
+ int32 fnRegisterStartPoint(int32 *params);
+ int32 fnInitBackground(int32 *params);
+ int32 fnSetSession(int32 *params);
+ int32 fnBackSprite(int32 *params);
+ int32 fnSortSprite(int32 *params);
+ int32 fnForeSprite(int32 *params);
+ int32 fnRegisterMouse(int32 *params);
+ int32 fnAnim(int32 *params);
+ int32 fnRandom(int32 *params);
+ int32 fnPreLoad(int32 *params);
+ int32 fnAddSubject(int32 *params);
+ int32 fnInteract(int32 *params);
+ int32 fnChoose(int32 *params);
+ int32 fnWalk(int32 *params);
+ int32 fnWalkToAnim(int32 *params);
+ int32 fnTurn(int32 *params);
+ int32 fnStandAt(int32 *params);
+ int32 fnStand(int32 *params);
+ int32 fnStandAfterAnim(int32 *params);
+ int32 fnPause(int32 *params);
+ int32 fnMegaTableAnim(int32 *params);
+ int32 fnAddMenuObject(int32 *params);
+ int32 fnStartConversation(int32 *params);
+ int32 fnEndConversation(int32 *params);
+ int32 fnSetFrame(int32 *params);
+ int32 fnRandomPause(int32 *params);
+ int32 fnRegisterFrame(int32 *params);
+ int32 fnNoSprite(int32 *params);
+ int32 fnSendSync(int32 *params);
+ int32 fnUpdatePlayerStats(int32 *params);
+ int32 fnPassGraph(int32 *params);
+ int32 fnInitFloorMouse(int32 *params);
+ int32 fnPassMega(int32 *params);
+ int32 fnFaceXY(int32 *params);
+ int32 fnEndSession(int32 *params);
+ int32 fnNoHuman(int32 *params);
+ int32 fnAddHuman(int32 *params);
+ int32 fnWeWait(int32 *params);
+ int32 fnTheyDoWeWait(int32 *params);
+ int32 fnTheyDo(int32 *params);
+ int32 fnWalkToTalkToMega(int32 *params);
+ int32 fnFadeDown(int32 *params);
+ int32 fnISpeak(int32 *params);
+ int32 fnTotalRestart(int32 *params);
+ int32 fnSetWalkGrid(int32 *params);
+ int32 fnSpeechProcess(int32 *params);
+ int32 fnSetScaling(int32 *params);
+ int32 fnStartEvent(int32 *params);
+ int32 fnCheckEventWaiting(int32 *params);
+ int32 fnRequestSpeech(int32 *params);
+ int32 fnGosub(int32 *params);
+ int32 fnTimedWait(int32 *params);
+ int32 fnPlayFx(int32 *params);
+ int32 fnStopFx(int32 *params);
+ int32 fnPlayMusic(int32 *params);
+ int32 fnStopMusic(int32 *params);
+ int32 fnSetValue(int32 *params);
+ int32 fnNewScript(int32 *params);
+ int32 fnGetSync(int32 *params);
+ int32 fnWaitSync(int32 *params);
+ int32 fnRegisterWalkGrid(int32 *params);
+ int32 fnReverseMegaTableAnim(int32 *params);
+ int32 fnReverseAnim(int32 *params);
+ int32 fnAddToKillList(int32 *params);
+ int32 fnSetStandbyCoords(int32 *params);
+ int32 fnBackPar0Sprite(int32 *params);
+ int32 fnBackPar1Sprite(int32 *params);
+ int32 fnForePar0Sprite(int32 *params);
+ int32 fnForePar1Sprite(int32 *params);
+ int32 fnSetPlayerActionEvent(int32 *params);
+ int32 fnSetScrollCoordinate(int32 *params);
+ int32 fnStandAtAnim(int32 *params);
+ int32 fnSetScrollLeftMouse(int32 *params);
+ int32 fnSetScrollRightMouse(int32 *params);
+ int32 fnColour(int32 *params);
+ int32 fnFlash(int32 *params);
+ int32 fnPreFetch(int32 *params);
+ int32 fnGetPlayerSaveData(int32 *params);
+ int32 fnPassPlayerSaveData(int32 *params);
+ int32 fnSendEvent(int32 *params);
+ int32 fnAddWalkGrid(int32 *params);
+ int32 fnRemoveWalkGrid(int32 *params);
+ int32 fnCheckForEvent(int32 *params);
+ int32 fnPauseForEvent(int32 *params);
+ int32 fnClearEvent(int32 *params);
+ int32 fnFaceMega(int32 *params);
+ int32 fnPlaySequence(int32 *params);
+ int32 fnShadedSprite(int32 *params);
+ int32 fnUnshadedSprite(int32 *params);
+ int32 fnFadeUp(int32 *params);
+ int32 fnDisplayMsg(int32 *params);
+ int32 fnSetObjectHeld(int32 *params);
+ int32 fnAddSequenceText(int32 *params);
+ int32 fnResetGlobals(int32 *params);
+ int32 fnSetPalette(int32 *params);
+ int32 fnRegisterPointerText(int32 *params);
+ int32 fnFetchWait(int32 *params);
+ int32 fnRelease(int32 *params);
+ int32 fnPrepareMusic(int32 *params);
+ int32 fnSoundFetch(int32 *params);
+ int32 fnSmackerLeadIn(int32 *params);
+ int32 fnSmackerLeadOut(int32 *params);
+ int32 fnStopAllFx(int32 *params);
+ int32 fnCheckPlayerActivity(int32 *params);
+ int32 fnResetPlayerActivityDelay(int32 *params);
+ int32 fnCheckMusicPlaying(int32 *params);
+ int32 fnPlayCredits(int32 *params);
+ int32 fnSetScrollSpeedNormal(int32 *params);
+ int32 fnSetScrollSpeedSlow(int32 *params);
+ int32 fnRemoveChooser(int32 *params);
+ int32 fnSetFxVolAndPan(int32 *params);
+ int32 fnSetFxVol(int32 *params);
+ int32 fnRestoreGame(int32 *params);
+ int32 fnRefreshInventory(int32 *params);
+ int32 fnChangeShadows(int32 *params);
+
//do one cycle of the current session
int processSession(void);
@@ -42,8 +192,7 @@ public:
uint32 getRunList(void);
- // setup script_id and script_pc in _curObjectHub - called by
- // FN_gosub()
+ // setup script_id and script_pc in _curObjectHub - called by fnGosub()
void logicUp(uint32 new_script);
void logicReplace(uint32 new_script);
@@ -51,23 +200,9 @@ public:
void totalRestart(void);
uint32 examineRunList(void);
void resetKillList(void);
-
-private:
- // denotes the res id of the game-object-list in current use
- uint32 _currentRunList;
-
- void processKillList(void);
-
- //pc during logic loop
- uint32 _pc;
-
- // each object has one of these tacked onto the beginning
- _object_hub *_curObjectHub;
};
-extern logic LLogic;
-
-int32 FN_add_to_kill_list(int32 *params);
+extern Logic g_logic;
} // End of namespace Sword2
diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp
index 86e3b1184a..04d59867ac 100644
--- a/sword2/mouse.cpp
+++ b/sword2/mouse.cpp
@@ -26,6 +26,7 @@
#include "bs2/events.h"
#include "bs2/icons.h"
#include "bs2/interpreter.h"
+#include "bs2/logic.h"
#include "bs2/layers.h"
#include "bs2/maketext.h"
#include "bs2/mouse.h"
@@ -227,7 +228,7 @@ void System_menu_mouse(void) {
pars[0] = 221; // SystemM234 (M234.wav)
pars[1] = FX_LOOP;
- FN_play_music(pars);
+ g_logic.fnPlayMusic(pars);
// restore proper looping_music_id
looping_music_id = safe_looping_music_id;
@@ -300,7 +301,7 @@ void System_menu_mouse(void) {
if (looping_music_id) {
pars[0] = looping_music_id;
pars[1] = FX_LOOP;
- FN_play_music(pars);
+ g_logic.fnPlayMusic(pars);
// cross-fades into the required music:
// - either a restored game tune
@@ -308,7 +309,7 @@ void System_menu_mouse(void) {
// entering control panels
} else {
// stop the control panel music
- FN_stop_music(NULL);
+ g_logic.fnStopMusic(NULL);
}
}
}
@@ -651,8 +652,8 @@ void Normal_mouse(void) {
// let the existing interaction continue and start
// fading down - switch the human off too
- FN_no_human(NULL);
- FN_fade_down(NULL);
+ g_logic.fnNoHuman(NULL);
+ g_logic.fnFadeDown(NULL);
EXIT_FADING = 1; // tell the walker
} else if (old_button == button_click && mouse_touching == CLICKED_ID && mouse_pointer_res != NORMAL_MOUSE_ID) {
// re-click - do nothing - except on floors
@@ -1036,8 +1037,8 @@ void ClearPointerText(void) {
}
}
-int32 FN_no_human(int32 *params) {
- // param none
+int32 Logic::fnNoHuman(int32 *params) {
+ // params: none
// for logic scripts
MOUSE_AVAILABLE = 0;
@@ -1082,13 +1083,13 @@ void No_human(void) {
Set_luggage(0);
}
-int32 FN_add_human(int32 *params) {
- // param none
+int32 Logic::fnAddHuman(int32 *params) {
+ // params: none
// for logic scripts
MOUSE_AVAILABLE = 1;
- //off
+ // off
if (mouse_status) {
mouse_status = 0; // on
mouse_touching = 1; // forces engine to choose a cursor
@@ -1138,7 +1139,7 @@ int32 FN_add_human(int32 *params) {
// testing logic scripts by simulating an instant Save &
// Restore
- BS2_SetPalette(0, 1, white, RDPAL_INSTANT);
+ g_display->setPalette(0, 1, white, RDPAL_INSTANT);
// stops all fx & clears the queue - eg. when leaving a
// location
@@ -1150,20 +1151,20 @@ int32 FN_add_human(int32 *params) {
res_man.killAllObjects(0);
- BS2_SetPalette(0, 1, black, RDPAL_INSTANT);
+ g_display->setPalette(0, 1, black, RDPAL_INSTANT);
}
#endif
return IR_CONT;
}
-int32 FN_register_mouse(int32 *params) {
+int32 Logic::fnRegisterMouse(int32 *params) {
// this call would be made from an objects service script 0
// the object would be one with no graphic but with a mouse - i.e. a
// floor or one whose mouse area is manually defined rather than
// intended to fit sprite shape
- // param 0 pointer to Object_mouse or 0 for no write to mouse
+ // params: 0 pointer to Object_mouse or 0 for no write to mouse
// list
debug(5, "cur_mouse = %d", cur_mouse);
@@ -1202,7 +1203,7 @@ int32 FN_register_mouse(int32 *params) {
mouse_list[cur_mouse].id = ID;
// not using sprite as mask - this is only done from
- // FN_register_frame()
+ // fnRegisterFrame()
mouse_list[cur_mouse].anim_resource = 0;
mouse_list[cur_mouse].anim_pc = 0;
@@ -1215,11 +1216,11 @@ int32 FN_register_mouse(int32 *params) {
}
// use this in the object's service script prior to registering the mouse area
-// ie. before FN_register_mouse or FN_register_frame
+// ie. before fnRegisterMouse or fnRegisterFrame
// - best if kept at very top of service script
-int32 FN_register_pointer_text(int32 *params) {
- // param 0 local id of text line to use as pointer text
+int32 Logic::fnRegisterPointerText(int32 *params) {
+ // params: 0 local id of text line to use as pointer text
#ifdef _SWORD2_DEBUG
if (cur_mouse == TOTAL_mouse_list)
@@ -1227,7 +1228,7 @@ int32 FN_register_pointer_text(int32 *params) {
#endif
// current object id - used for checking pointer_text when mouse area
- // registered (in FN_register_mouse & FN_register_frame)
+ // registered (in fnRegisterMouse and fnRegisterFrame)
mouse_list[cur_mouse].id = ID;
mouse_list[cur_mouse].pointer_text = params[0];
@@ -1235,16 +1236,8 @@ int32 FN_register_pointer_text(int32 *params) {
return IR_CONT;
}
-int32 FN_blank_mouse(int32 *params) {
- //set mouse to normal pointer - used in speech
- //no params
-
- Set_mouse(0);
- return IR_CONT;
-}
-
-int32 FN_init_floor_mouse(int32 *params) {
- // params 0 pointer to object's mouse structure
+int32 Logic::fnInitFloorMouse(int32 *params) {
+ // params: 0 pointer to object's mouse structure
Object_mouse *ob_mouse = (Object_mouse *) params[0];
@@ -1262,8 +1255,8 @@ int32 FN_init_floor_mouse(int32 *params) {
#define SCROLL_MOUSE_WIDTH 20
-int32 FN_set_scroll_left_mouse(int32 *params) {
- // params 0 pointer to object's mouse structure
+int32 Logic::fnSetScrollLeftMouse(int32 *params) {
+ // params: 0 pointer to object's mouse structure
Object_mouse *ob_mouse = (Object_mouse *) params[0];
@@ -1286,8 +1279,8 @@ int32 FN_set_scroll_left_mouse(int32 *params) {
return IR_CONT;
}
-int32 FN_set_scroll_right_mouse(int32 *params) {
- // params 0 pointer to object's mouse structure
+int32 Logic::fnSetScrollRightMouse(int32 *params) {
+ // params: 0 pointer to object's mouse structure
Object_mouse *ob_mouse = (Object_mouse *) params[0];
@@ -1310,8 +1303,8 @@ int32 FN_set_scroll_right_mouse(int32 *params) {
return IR_CONT;
}
-int32 FN_set_object_held(int32 *params) {
- // params 0 luggage icon to set
+int32 Logic::fnSetObjectHeld(int32 *params) {
+ // params: 0 luggage icon to set
Set_luggage(params[0]);
@@ -1327,33 +1320,18 @@ int32 FN_set_object_held(int32 *params) {
// called from speech scripts to remove the chooser bar when it's not
// appropriate to keep it displayed
-int32 FN_remove_chooser(int32 *params) {
- g_display->hideMenu(RDMENU_BOTTOM);
- return IR_CONT;
-}
+int32 Logic::fnRemoveChooser(int32 *params) {
+ // params: none
-int32 FN_disable_menu(int32 *params) {
- // mode locked - no menu available
- mouse_mode_locked = 1;
- mouse_mode = MOUSE_normal;
-
- g_display->hideMenu(RDMENU_TOP);
g_display->hideMenu(RDMENU_BOTTOM);
-
- return IR_CONT;
-}
-
-int32 FN_enable_menu(int32 *params) {
- // mode unlocked - menu available
- mouse_mode_locked = 0;
return IR_CONT;
}
-int32 FN_check_player_activity(int32 *params) {
+int32 Logic::fnCheckPlayerActivity(int32 *params) {
// Used to decide when to trigger music cues described as "no player
// activity for a while"
- // params 0 threshold delay in seconds, ie. what we want to
+ // params: 0 threshold delay in seconds, ie. what we want to
// check the actual delay against
uint32 threshold = params[0] * 12; // in game cycles
@@ -1371,10 +1349,11 @@ int32 FN_check_player_activity(int32 *params) {
return IR_CONT;
}
-int32 FN_reset_player_activity_delay(int32 *params) {
+int32 Logic::fnResetPlayerActivityDelay(int32 *params) {
// Use if you want to deliberately reset the "no player activity"
// counter for any reason
- // no params
+
+ // params: none
player_activity_delay = 0;
return IR_CONT;
diff --git a/sword2/mouse.h b/sword2/mouse.h
index bf17df6a2f..93eaa6f5eb 100644
--- a/sword2/mouse.h
+++ b/sword2/mouse.h
@@ -94,9 +94,6 @@ void Mouse_engine(void);
void Set_mouse(uint32 res);
void Set_luggage(uint32 res);
-int32 FN_no_human(int32 *params);
-int32 FN_add_human(int32 *params);
-
void ClearPointerText(void);
} // End of namespace Sword2
diff --git a/sword2/object.h b/sword2/object.h
index 27af4723a1..2b7e7c38e7 100644
--- a/sword2/object.h
+++ b/sword2/object.h
@@ -42,9 +42,9 @@ typedef struct {
// logic structure - contains fields used in logic script processing
typedef struct {
- int32 looping; // 0 when first calling FN_<function>;
+ int32 looping; // 0 when first calling fn<function>;
// 1 when calling subsequent times in same loop
- int32 pause; // pause count, used by FN_pause()
+ int32 pause; // pause count, used by fnPause()
} Object_logic;
// status bits for 'type' field of Object_graphic)
@@ -102,7 +102,7 @@ typedef struct {
int32 feet_x; // mega feet coords - frame-offsets are added to these position mega frames
int32 feet_y;
int32 current_dir; // current dirction faced by mega; used by autorouter to determine turns required
- int32 NOT_USED_5; // means were currently avoiding a collision (see FN_walk)
+ int32 NOT_USED_5; // means were currently avoiding a collision (see fnWalk)
int32 megaset_res; // resource id of mega-set file
int32 NOT_USED_6; // NOT USED
} Object_mega;
diff --git a/sword2/protocol.cpp b/sword2/protocol.cpp
index 2970792a17..0557bd3926 100644
--- a/sword2/protocol.cpp
+++ b/sword2/protocol.cpp
@@ -188,7 +188,7 @@ uint8 *FetchTextLine(uint8 *file, uint32 text_line) {
}
-// Used for testing text & speech (see FN_I_speak in speech.cpp)
+// Used for testing text & speech (see fnISpeak in speech.cpp)
uint8 CheckTextLine(uint8 *file, uint32 text_line) {
_textHeader *text_header = (_textHeader *) (file + sizeof(_standardHeader));
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index cf910676b2..abd06b3c8b 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -27,6 +27,7 @@
#include "bs2/function.h"
#include "bs2/header.h"
#include "bs2/interpreter.h"
+#include "bs2/logic.h"
#include "bs2/maketext.h"
#include "bs2/memory.h"
#include "bs2/mouse.h" // for system Set_mouse & Set_luggage routines
@@ -1067,7 +1068,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
// down - but if we restored to a different CD the music is stopped
// in getCd() when it asks for the CD
- FN_stop_music(NULL);
+ g_logic.fnStopMusic(NULL);
Clear_fx_queue(); // stops all fx & clears the queue (James22july97)
getCd(_cdTab[newCluster] & 3);
@@ -1370,7 +1371,7 @@ void ResourceManager::getCd(int cd) {
// current CD - otherwise when we take out the CD, Windows will
// complain!
- FN_stop_music(NULL);
+ g_logic.fnStopMusic(NULL);
textRes = res_man.open(2283);
DisplayMsg(FetchTextLine(textRes, 5 + cd) + 2, 0);
diff --git a/sword2/router.cpp b/sword2/router.cpp
index 836c14a325..8123b07529 100644
--- a/sword2/router.cpp
+++ b/sword2/router.cpp
@@ -2634,7 +2634,7 @@ void Router::clearWalkGridList(void) {
memset(_walkGridList, 0, ARRAYSIZE(_walkGridList));
}
-// called from FN_add_walkgrid
+// called from fnAddWalkGrid
void Router::addWalkGrid(int32 gridResource) {
int i;
@@ -2658,7 +2658,7 @@ void Router::addWalkGrid(int32 gridResource) {
Con_fatal_error("ERROR: _walkGridList[] full");
}
-// called from FN_remove_walkgrid
+// called from fnRemoveWalkGrid
void Router::removeWalkGrid(int32 gridResource) {
for (int i = 0; i < MAX_WALKGRIDS; i++) {
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index acd3ae70f3..e062ed0c93 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -183,7 +183,7 @@ void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc) {
g_header.screenId = this_screen.background_layer_id;
// resource id of current run-list
- g_header.runListId = LLogic.getRunList();
+ g_header.runListId = g_logic.getRunList();
// those scroll position control things
g_header.feet_x = this_screen.feet_x;
@@ -382,7 +382,7 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
res_man.killAll(0);
// clean out the system kill list (no more objects to kill)
- LLogic.resetKillList();
+ g_logic.resetKillList();
// get player character data from savegame buffer
@@ -419,20 +419,20 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
pars[0] = g_header.screenId;
pars[1] = 1;
- FN_init_background(pars);
+ g_logic.fnInitBackground(pars);
- // (JEL08oct97) so palette not restored immediately after control
- // panel - we want to fade up instead!
+ // So palette not restored immediately after control panel - we want to
+ // fade up instead!
this_screen.new_palette = 99;
- // these need setting after the defaults get set in FN_init_background
+ // these need setting after the defaults get set in fnInitBackground
// remember that these can change through the game, so need saving &
// restoring too
this_screen.feet_x = g_header.feet_x;
this_screen.feet_y = g_header.feet_y;
// start the new run list
- LLogic.expressChangeSession(g_header.runListId);
+ g_logic.expressChangeSession(g_header.runListId);
// Force in the new scroll position, so unsightly scroll-catch-up does
// not occur when screen first draws after returning from restore panel
@@ -508,8 +508,7 @@ bool SaveExists(uint16 slotNo) {
void GetPlayerStructures(void) {
// request the player object structures which need saving
- // script no. 7 - 'george_savedata_request' calls
- // FN_pass_player_savedata
+ // script no. 7 - 'george_savedata_request' calls fnPassPlayerSaveData
uint32 null_pc = 7;
char *raw_script_ad;
@@ -541,7 +540,7 @@ void PutPlayerStructures(void) {
raw_script_ad = (char *) head;
- // script no. 8 - 'george_savedata_return' calls FN_get_player_savedata
+ // script no. 8 - 'george_savedata_return' calls fnGetPlayerSaveData
null_pc = 8;
RunScript(raw_script_ad, raw_script_ad, &null_pc);
@@ -575,7 +574,7 @@ void PutPlayerStructures(void) {
res_man.close(CUR_PLAYER_ID);
}
-int32 FN_pass_player_savedata(int32 *params) {
+int32 Logic::fnPassPlayerSaveData(int32 *params) {
// copies the 4 essential player structures into the savegame header
// - run script 7 of player object to request this
@@ -596,8 +595,8 @@ int32 FN_pass_player_savedata(int32 *params) {
return IR_CONT;
}
-int32 FN_get_player_savedata(int32 *params) {
- // reverse of FN_pass_player_savedata
+int32 Logic::fnGetPlayerSaveData(int32 *params) {
+ // reverse of fnPassPlayerSaveData
// - run script 8 of player object
// params: 0 pointer to object's logic structure
@@ -634,10 +633,9 @@ int32 FN_get_player_savedata(int32 *params) {
pars[2] = ob_mega->current_dir;
// set player to stand
- FN_stand(pars);
+ fnStand(pars);
- // reset looping flag (which would have been '1' during
- // FN_walk)
+ // reset looping flag (which would have been '1' during fnWalk)
ob_logic->looping = 0;
}
diff --git a/sword2/scroll.cpp b/sword2/scroll.cpp
index f8b3265bc7..584bc2bffb 100644
--- a/sword2/scroll.cpp
+++ b/sword2/scroll.cpp
@@ -24,6 +24,7 @@
#include "bs2/header.h"
#include "bs2/interpreter.h"
#include "bs2/layers.h"
+#include "bs2/logic.h"
#include "bs2/scroll.h"
namespace Sword2 {
@@ -146,12 +147,12 @@ void Set_scrolling(void) {
}
}
-int32 FN_set_scroll_coordinate(int32 *params) {
+int32 Logic::fnSetScrollCoordinate(int32 *params) {
// set the special scroll offset variables
// call when starting screens and to change the camera within screens
- // call AFTER FN_init_background() to override the defaults
+ // call AFTER fnInitBackground() to override the defaults
// called feet_x and feet_y to retain intelectual compatibility with
// Sword1 !
@@ -167,12 +168,16 @@ int32 FN_set_scroll_coordinate(int32 *params) {
return IR_CONT;
}
-int32 FN_set_scroll_speed_normal(int32 *params) {
+int32 Logic::fnSetScrollSpeedNormal(int32 *params) {
+ // params: none
+
scroll_fraction = 16;
return IR_CONT;
}
-int32 FN_set_scroll_speed_slow(int32 *params) {
+int32 Logic::fnSetScrollSpeedSlow(int32 *params) {
+ // params: none
+
scroll_fraction = 32;
return IR_CONT;
}
diff --git a/sword2/sound.cpp b/sword2/sound.cpp
index f1d04b701e..18c8d8adcb 100644
--- a/sword2/sound.cpp
+++ b/sword2/sound.cpp
@@ -32,7 +32,8 @@
#include "bs2/console.h"
#include "bs2/defs.h" // for RESULT
#include "bs2/interpreter.h"
-#include "bs2/protocol.h" // for FetchObjectName() for debugging FN_play_fx
+#include "bs2/logic.h"
+#include "bs2/protocol.h" // for FetchObjectName() for debugging fnPlayFx
#include "bs2/resman.h"
#include "bs2/sound.h"
#include "bs2/sword2.h"
@@ -116,7 +117,7 @@ void Trigger_fx(uint8 j) {
res_man.close(fxq[j].resource);
} else {
// random & looped fx are already loaded into sound memory
- // by FN_play_fx()
+ // by fnPlayFx()
// - to be referenced by 'j', so pass NULL data
if (fxq[j].type == FX_RANDOM) {
@@ -134,7 +135,7 @@ void Trigger_fx(uint8 j) {
// called from script only
-int32 FN_play_fx(int32 *params) {
+int32 Logic::fnPlayFx(int32 *params) {
// params: 0 sample resource id
// 1 type (FX_SPOT, FX_RANDOM, FX_LOOP)
// 2 delay (0..65535)
@@ -142,13 +143,13 @@ int32 FN_play_fx(int32 *params) {
// 4 pan (-16..16)
// example script:
- // FN_play_fx (FXWATER, FX_LOOP, 0, 10, 15);
+ // fnPlayFx (FXWATER, FX_LOOP, 0, 10, 15);
// // fx_water is just a local script flag
// fx_water = result;
// .
// .
// .
- // FN_stop_fx (fx_water);
+ // fnStopFx (fx_water);
uint8 j = 0;
uint8 *data;
@@ -207,7 +208,7 @@ int32 FN_play_fx(int32 *params) {
#ifdef _SWORD2_DEBUG
header = (_standardHeader*) data;
if (header->fileType != WAV_FILE)
- Con_fatal_error("FN_play_fx given invalid resource");
+ Con_fatal_error("fnPlayFx given invalid resource");
#endif
// but then releases it to "age" out if the space is needed
@@ -223,7 +224,7 @@ int32 FN_play_fx(int32 *params) {
#ifdef _SWORD2_DEBUG
header = (_standardHeader*)data;
if (header->fileType != WAV_FILE)
- Con_fatal_error("FN_play_fx given invalid resource");
+ Con_fatal_error("fnPlayFx given invalid resource");
#endif
data += sizeof(_standardHeader);
@@ -244,26 +245,27 @@ int32 FN_play_fx(int32 *params) {
Trigger_fx(j);
}
- // in case we want to call FN_stop_fx() later, to kill this fx
+ // in case we want to call fnStopFx() later, to kill this fx
// (mainly for FX_LOOP & FX_RANDOM)
RESULT = j;
return IR_CONT;
}
-int32 FN_sound_fetch(int32 *params) {
+int32 Logic::fnSoundFetch(int32 *params) {
+ // params: 0 id of sound to fetch [guess]
return IR_CONT;
}
// to alter the volume and pan of a currently playing fx
-int32 FN_set_fx_vol_and_pan(int32 *params) {
+int32 Logic::fnSetFxVolAndPan(int32 *params) {
// params: 0 id of fx (ie. the id returned in 'result' from
- // FN_play_fx
+ // fnPlayFx
// 1 new volume (0..16)
// 2 new pan (-16..16)
- debug(5, "FN_set_fx_vol_and_pan(%d, %d, %d)", params[0], params[1], params[2]);
+ debug(5, "fnSetFxVolAndPan(%d, %d, %d)", params[0], params[1], params[2]);
// setFxIdVolumePan(int32 id, uint8 vol, uint8 pan);
// driver fx_id is 1 + <pos in queue>
@@ -273,9 +275,9 @@ int32 FN_set_fx_vol_and_pan(int32 *params) {
// to alter the volume of a currently playing fx
-int32 FN_set_fx_vol(int32 *params) {
+int32 Logic::fnSetFxVol(int32 *params) {
// params: 0 id of fx (ie. the id returned in 'result' from
- // FN_play_fx
+ // fnPlayFx
// 1 new volume (0..16)
// SetFxIdVolume(int32 id, uint8 vol);
@@ -285,7 +287,7 @@ int32 FN_set_fx_vol(int32 *params) {
// called from script only
-int32 FN_stop_fx(int32 *params) {
+int32 Logic::fnStopFx(int32 *params) {
// params: 0 position in queue
// This will stop looped & random fx instantly, and remove the fx
@@ -314,8 +316,9 @@ int32 FN_stop_fx(int32 *params) {
// called from script only
-int32 FN_stop_all_fx(int32 *params) {
+int32 Logic::fnStopAllFx(int32 *params) {
// Stops all looped & random fx and clears the entire queue
+
// params: none
Clear_fx_queue();
@@ -332,14 +335,15 @@ void Clear_fx_queue(void) {
Init_fx_queue();
}
-int32 FN_prepare_music(int32 *params) {
+int32 Logic::fnPrepareMusic(int32 *params) {
+ // params: 1 id of music to prepare [guess]
return IR_CONT;
}
// Start a tune playing, to play once or to loop until stopped or next one
// played
-int32 FN_play_music(int32 *params) {
+int32 Logic::fnPlayMusic(int32 *params) {
// params: 0 tune id
// 1 loop flag (0 or 1)
@@ -347,8 +351,6 @@ int32 FN_play_music(int32 *params) {
bool loopFlag;
uint32 rv;
- debug(5, "FN_play_music(%d, %d)", params[0], params[1]);
-
if (params[1] == FX_LOOP) {
loopFlag = true;
@@ -388,7 +390,9 @@ int32 FN_play_music(int32 *params) {
return IR_CONT;
}
-int32 FN_stop_music(int32 *params) { // called from script only
+// called from script only
+
+int32 Logic::fnStopMusic(int32 *params) {
// params: none
looping_music_id = 0; // clear the 'looping' flag
@@ -401,7 +405,7 @@ void Kill_music(void) {
g_sound->stopMusic();
}
-int32 FN_check_music_playing(int32 *params) {
+int32 Logic::fnCheckMusicPlaying(int32 *params) {
// params: none
// sets result to no. of seconds of current tune remaining
diff --git a/sword2/sound.h b/sword2/sound.h
index 327db16677..66a68db660 100644
--- a/sword2/sound.h
+++ b/sword2/sound.h
@@ -53,9 +53,6 @@ void UnpauseAllSound(void);
void Kill_music(void);
-int32 FN_play_music(int32 *params); // for save_Rest.cpp
-int32 FN_stop_music(int32 *params);
-
// used to store id of tunes that loop, for save & restore
extern uint32 looping_music_id;
diff --git a/sword2/speech.cpp b/sword2/speech.cpp
index 42ac9ef551..e3df918b68 100644
--- a/sword2/speech.cpp
+++ b/sword2/speech.cpp
@@ -82,7 +82,7 @@ uint32 default_response_id = 0;
int16 officialTextNumber = 0;
// usually 0; if non-zero then it's the id of whoever we're waiting for in a
-// speech script see FN_they_do, FN_they_do_we_wait & FN_we_wait
+// speech script see fnTheyDo, fnTheyDoWeWait and fnWeWait
int32 speechScriptWaiting = 0;
// calculated by LocateTalker() for use in speech-panning & text-sprite
@@ -91,7 +91,6 @@ int16 text_x, text_y;
_subject_unit subject_list[MAX_SUBJECT_LIST];
-int32 FN_i_speak(int32 *params);
void LocateTalker(int32 *params);
void Form_text(int32 *params);
uint8 WantSpeechForLine(uint32 wavId);
@@ -100,7 +99,7 @@ uint8 WantSpeechForLine(uint32 wavId);
void GetCorrectCdForSpeech(int32 wavId); // for testing speech & text
#endif
-int32 FN_add_subject(int32 *params) {
+int32 Logic::fnAddSubject(int32 *params) {
// params: 0 id
// 1 daves reference number
@@ -123,12 +122,12 @@ int32 FN_add_subject(int32 *params) {
default_response_id = params[1];
// a luggage icon is clicked on someone when it wouldn't have
- // been in the chooser list (see FN_choose below)
+ // been in the chooser list (see fnChoose below)
} else {
subject_list[IN_SUBJECT].res = params[0];
subject_list[IN_SUBJECT].ref = params[1];
- debug(5, "FN_add_subject res %d, uid %d", params[0], params[1]);
+ debug(5, "fnAddSubject res %d, uid %d", params[0], params[1]);
IN_SUBJECT++;
}
@@ -139,7 +138,7 @@ int32 FN_add_subject(int32 *params) {
// could alternately use logic->looping of course
int choosing = 0;
-int32 FN_choose(int32 *params) {
+int32 Logic::fnChoose(int32 *params) {
// params: none
// the human is switched off so there will be no normal mouse engine
@@ -149,8 +148,6 @@ int32 FN_choose(int32 *params) {
uint8 *icon;
uint32 pos = 0;
- debug(5, "FN_choose");
-
AUTO_SELECTED = 0; // see below
// new thing to intercept objects held at time of clicking on a person
@@ -211,7 +208,7 @@ int32 FN_choose(int32 *params) {
// build menus from subject_list
if (!IN_SUBJECT)
- Con_fatal_error("FN_choose with no subjects :-O");
+ Con_fatal_error("fnChoose with no subjects :-O");
// init top menu from master list
// all icons are highlighted / full colour
@@ -303,40 +300,29 @@ int32 FN_choose(int32 *params) {
}
}
-int32 FN_start_conversation(int32 *params) {
+int32 Logic::fnStartConversation(int32 *params) {
// Start conversation
- // FN_no_human(); // an FN_no_human
- // FN_change_speech_text(PLAYER, GEORGE_WIDTH, GEORGE_PEN);
-
- // params: none
-
- debug(5, "FN_start_conversation %d", ID);
-
// reset 'chooser_count_flag' at the start of each conversation:
- // Note that FN_start_conversation might accidently be called
- // every time the script loops back for another chooser
- // but we only want to reset the chooser count flag the first time
- // this function is called ie. when talk flag is zero
+ // Note that fnStartConversation might accidently be called every time
+ // the script loops back for another chooser but we only want to reset
+ // the chooser count flag the first time this function is called ie.
+ // when talk flag is zero
+
+ // params: none
if (TALK_FLAG == 0)
- CHOOSER_COUNT_FLAG = 0; // see FN_chooser & speech scripts
+ CHOOSER_COUNT_FLAG = 0; // see fnChooser & speech scripts
- FN_no_human(params);
+ fnNoHuman(params);
return IR_CONT;
}
-int32 FN_end_conversation(int32 *params) {
+int32 Logic::fnEndConversation(int32 *params) {
// end conversation
- // talk_flag=0;
- // FN_end_chooser();
- // FN_add_human();
- // FN_change_speech_text(PLAYER, VOICE_OVER_WIDTH, VOICE_OVER_PEN);
- // FN_idle();
- // params: none
- debug(5, "FN_end_conversation");
+ // params: none
g_display->hideMenu(RDMENU_BOTTOM);
@@ -355,7 +341,7 @@ int32 FN_end_conversation(int32 *params) {
return IR_CONT;
}
-int32 FN_they_do(int32 *params) {
+int32 Logic::fnTheyDo(int32 *params) {
// doesn't send the command until target is waiting - once sent we
// carry on
@@ -375,7 +361,7 @@ int32 FN_they_do(int32 *params) {
// request status of target
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("FN_they_do %d not an object", target);
+ Con_fatal_error("fnTheyDo %d not an object", target);
raw_script_ad = (char *) head;
@@ -411,7 +397,7 @@ int32 FN_they_do(int32 *params) {
return IR_REPEAT;
}
-int32 FN_they_do_we_wait(int32 *params) {
+int32 Logic::fnTheyDoWeWait(int32 *params) {
// give target a command and wait for it to register as finished
// params: 0 pointer to ob_logic
@@ -432,14 +418,12 @@ int32 FN_they_do_we_wait(int32 *params) {
_standardHeader *head;
int32 target = params[1];
- debug(5, "FN_they_do_we_wait id %d, command %d", params[1], params[2]);
-
// ok, see if the target is busy - we must request this info from the
// target object
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("FN_they_do_we_wait %d not an object", target);
+ Con_fatal_error("fnTheyDoWeWait %d not an object", target);
raw_script_ad = (char *) head;
@@ -506,8 +490,9 @@ int32 FN_they_do_we_wait(int32 *params) {
return IR_REPEAT;
}
-int32 FN_we_wait(int32 *params) {
+int32 Logic::fnWeWait(int32 *params) {
// loop until the target is free
+
// params: 0 target
uint32 null_pc = 5; // 4th script - get-speech-state
@@ -518,7 +503,7 @@ int32 FN_we_wait(int32 *params) {
// request status of target
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("FN_we_wait %d not an object", target);
+ Con_fatal_error("fnWeWait: %d not an object", target);
raw_script_ad = (char *) head;
@@ -543,7 +528,7 @@ int32 FN_we_wait(int32 *params) {
return IR_REPEAT;
}
-int32 FN_timed_wait(int32 *params) {
+int32 Logic::fnTimedWait(int32 *params) {
// loop until the target is free but only while the timer is high
// useful when clicking on a target to talk to them - if they never
// reply then this'll fall out avoiding a lock up
@@ -566,7 +551,7 @@ int32 FN_timed_wait(int32 *params) {
// request status of target
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("FN_timed_wait %d not an object", target);
+ Con_fatal_error("fnTimedWait %d not an object", target);
raw_script_ad = (char *) head;
@@ -617,7 +602,7 @@ int32 FN_timed_wait(int32 *params) {
return IR_REPEAT;
}
-int32 FN_speech_process(int32 *params) {
+int32 Logic::fnSpeechProcess(int32 *params) {
// Recieve and sequence the commands sent from the conversation
// script.
@@ -666,7 +651,7 @@ int32 FN_speech_process(int32 *params) {
// run the function - (it thinks it's been called from
// script - bloody fool)
- if (FN_i_speak(pars) != IR_REPEAT) {
+ if (fnISpeak(pars) != IR_REPEAT) {
debug(5, "speech-process talk finished");
// command finished
@@ -685,7 +670,7 @@ int32 FN_speech_process(int32 *params) {
pars[3] = params[4]; // ob_walkdata
pars[4] = ob_speech->ins1; // direction to turn to
- if (FN_turn(pars) != IR_REPEAT) {
+ if (fnTurn(pars) != IR_REPEAT) {
// command finished
ob_speech->command = 0;
@@ -702,7 +687,7 @@ int32 FN_speech_process(int32 *params) {
pars[3] = params[4]; // ob_walkdata
pars[4] = ob_speech->ins1; // target
- if (FN_face_mega(pars) != IR_REPEAT) {
+ if (fnFaceMega(pars) != IR_REPEAT) {
// command finished
ob_speech->command = 0;
@@ -717,7 +702,7 @@ int32 FN_speech_process(int32 *params) {
pars[1] = params[0]; // ob_graphic
pars[2] = ob_speech->ins1; // anim res
- if (FN_anim(pars) != IR_REPEAT) {
+ if (fnAnim(pars) != IR_REPEAT) {
// command finished
ob_speech->command = 0;
@@ -732,7 +717,7 @@ int32 FN_speech_process(int32 *params) {
pars[1] = params[0]; // ob_graphic
pars[2] = ob_speech->ins1; // anim res
- if (FN_reverse_anim(pars) != IR_REPEAT) {
+ if (fnReverseAnim(pars) != IR_REPEAT) {
// command finished
ob_speech->command = 0;
@@ -748,7 +733,7 @@ int32 FN_speech_process(int32 *params) {
pars[2] = params[3]; // ob_mega
pars[3] = ob_speech->ins1; // pointer to anim table
- if (FN_mega_table_anim(pars) != IR_REPEAT) {
+ if (fnMegaTableAnim(pars) != IR_REPEAT) {
// command finished
ob_speech->command = 0;
@@ -764,7 +749,7 @@ int32 FN_speech_process(int32 *params) {
pars[2] = params[3]; // ob_mega
pars[3] = ob_speech->ins1; // pointer to anim table
- if (FN_reverse_mega_table_anim(pars) != IR_REPEAT) {
+ if (fnReverseMegaTableAnim(pars) != IR_REPEAT) {
// command finished
ob_speech->command = 0;
@@ -775,22 +760,22 @@ int32 FN_speech_process(int32 *params) {
// come back again next cycle
return IR_REPEAT;
case INS_no_sprite:
- FN_no_sprite(params); // ob_graphic
+ fnNoSprite(params); // ob_graphic
ob_speech->command = 0; // command finished
ob_speech->wait_state = 1; // waiting for command
return IR_REPEAT ;
case INS_sort:
- FN_sort_sprite(params); // ob_graphic
+ fnSortSprite(params); // ob_graphic
ob_speech->command = 0; // command finished
ob_speech->wait_state = 1; // waiting for command
return IR_REPEAT;
case INS_foreground:
- FN_fore_sprite(params); // ob_graphic
+ fnForeSprite(params); // ob_graphic
ob_speech->command = 0; // command finished
ob_speech->wait_state = 1; // waiting for command
return IR_REPEAT;
case INS_background:
- FN_back_sprite(params); // ob_graphic
+ fnBackSprite(params); // ob_graphic
ob_speech->command = 0; // command finished
ob_speech->wait_state = 1; // waiting for command
return IR_REPEAT;
@@ -803,7 +788,7 @@ int32 FN_speech_process(int32 *params) {
pars[5] = ob_speech->ins2; // target y
pars[6] = ob_speech->ins3; // target direction
- if (FN_walk(pars) != IR_REPEAT) {
+ if (fnWalk(pars) != IR_REPEAT) {
debug(5, "speech-process walk finished");
// command finished
@@ -822,7 +807,7 @@ int32 FN_speech_process(int32 *params) {
pars[3] = params[4]; // ob_walkdata
pars[4] = ob_speech->ins1; // anim resource
- if (FN_walk_to_anim(pars) != IR_REPEAT) {
+ if (fnWalkToAnim(pars) != IR_REPEAT) {
debug(5, "speech-process walk finished");
// command finished
@@ -838,7 +823,7 @@ int32 FN_speech_process(int32 *params) {
pars[0] = params[0]; // ob_graphic
pars[1] = params[3]; // ob_mega
pars[2] = ob_speech->ins1; // anim resource
- FN_stand_after_anim(pars);
+ fnStandAfterAnim(pars);
ob_speech->command = 0; // command finished
ob_speech->wait_state = 1; // waiting for command
return IR_REPEAT; // come back again next cycle
@@ -846,7 +831,7 @@ int32 FN_speech_process(int32 *params) {
pars[0] = params[0]; // ob_graphic
pars[1] = ob_speech->ins1; // anim_resource
pars[2] = ob_speech->ins2; // FIRST_FRAME or LAST_FRAME
- ret = FN_set_frame(pars);
+ ret = fnSetFrame(pars);
ob_speech->command = 0; // command finished
ob_speech->wait_state = 1; // waiting for command
return IR_REPEAT; // come back again next cycle
@@ -915,8 +900,8 @@ int32 FN_speech_process(int32 *params) {
uint32 unpause_zone = 0;
-int32 FN_i_speak(int32 *params) {
- // its the super versatile FN_speak
+int32 Logic::fnISpeak(int32 *params) {
+ // its the super versatile fnSpeak
// text and wavs can be selected in any combination
// we can assume no human - there should be no human at least!
@@ -993,7 +978,7 @@ int32 FN_i_speak(int32 *params) {
textNumber = params[S_TEXT]; // for debug info
// For testing all text & speech!
- // A script loop can send any text number to FN_I_speak & it
+ // A script loop can send any text number to fnISpeak and it
// will only run the valid ones or return with 'result' equal
// to '1' or '2' to mean 'invalid text resource' and 'text
// number out of range' respectively
diff --git a/sword2/startup.cpp b/sword2/startup.cpp
index 1e32086529..a50d627672 100644
--- a/sword2/startup.cpp
+++ b/sword2/startup.cpp
@@ -18,22 +18,23 @@
*/
#include "stdafx.h"
+#include "bs2/sword2.h" // for CloseGame()
#include "bs2/build_display.h"
#include "bs2/console.h"
#include "bs2/debug.h"
#include "bs2/defs.h"
#include "bs2/header.h"
#include "bs2/interpreter.h"
+#include "bs2/logic.h"
#include "bs2/maketext.h" // for Kill_text_bloc()
#include "bs2/memory.h"
-#include "bs2/mouse.h" // for FN_add_human()
+#include "bs2/mouse.h"
#include "bs2/object.h"
#include "bs2/resman.h"
#include "bs2/router.h"
#include "bs2/sound.h"
#include "bs2/speech.h" // for 'speech_text_bloc_no' - so that speech text can be cleared when running a new start-script
#include "bs2/startup.h"
-#include "bs2/sword2.h" // for CloseGame()
#include "bs2/sync.h"
#include "bs2/tony_gsdk.h"
@@ -139,12 +140,10 @@ uint32 Init_start_menu(void) {
return 1;
}
-int32 FN_register_start_point(int32 *params) {
+int32 Logic::fnRegisterStartPoint(int32 *params) {
// params: 0 id of startup script to call - key
// 1 pointer to ascii message
- debug(5, " FN_register_start_point %d %s", params[0], params[1]);
-
#ifdef _SWORD2_DEBUG
if (total_startups == MAX_starts)
Con_fatal_error("ERROR: start_list full");
@@ -252,7 +251,7 @@ uint32 Con_start(uint8 *input) {
Clear_fx_queue();
// fade out any music that is currently playing
- FN_stop_music(NULL);
+ g_logic.fnStopMusic(NULL);
// halt the sample prematurely
g_sound->unpauseSpeech();
@@ -299,7 +298,7 @@ uint32 Con_start(uint8 *input) {
// make sure thre's a mouse, in case restarting while
// mouse not available
- FN_add_human(NULL);
+ g_logic.fnAddHuman(NULL);
} else
Print_to_console("not a legal start position");
} else {
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index e43633467e..6fcacd540f 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -248,20 +248,20 @@ int32 GameCycle(void) {
// do one game cycle
//got a screen to run?
- if (LLogic.getRunList()) {
+ if (g_logic.getRunList()) {
//run the logic session UNTIL a full loop has been performed
do {
// reset the graphic 'buildit' list before a new
- // logic list (see FN_register_frame)
+ // logic list (see fnRegisterFrame)
Reset_render_lists();
- // reset the mouse hot-spot list (see FN_register_mouse
- // & FN_register_frame)
+ // reset the mouse hot-spot list (see fnRegisterMouse
+ // and fnRegisterFrame)
Reset_mouse_list();
// keep going as long as new lists keep getting put in
// - i.e. screen changes
- } while (LLogic.processSession());
+ } while (g_logic.processSession());
} else {
// start the console and print the start options perhaps?
StartConsole();
@@ -386,7 +386,7 @@ void Sword2Engine::go() {
// 'P' while not paused = pause!
PauseGame();
} else if (c == 'C' && _gameId == GID_SWORD2) {
- FN_play_credits(NULL);
+ g_logic.fnPlayCredits(NULL);
}
#ifdef _SWORD2_DEBUG
else if (c == 'S') {
diff --git a/sword2/sync.cpp b/sword2/sync.cpp
index 0e25e4d29a..a42cc08e54 100644
--- a/sword2/sync.cpp
+++ b/sword2/sync.cpp
@@ -22,6 +22,7 @@
#include "bs2/debug.h"
#include "bs2/defs.h"
#include "bs2/interpreter.h"
+#include "bs2/logic.h"
#include "bs2/sync.h"
namespace Sword2 {
@@ -42,8 +43,8 @@ void Init_sync_system(void) {
sync_list[j].id = 0;
}
-int32 FN_send_sync(int32 *params) {
- // param 0 sync's recipient
+int32 Logic::fnSendSync(int32 *params) {
+ // params: 0 sync's recipient
// 1 sync value
for (int i = 0; i < MAX_syncs; i++) {
@@ -78,7 +79,7 @@ void Clear_syncs(uint32 id) {
bool Get_sync(void) {
// check for a sync waiting for this character
- // - called from system code eg. from inside FN_anim(), to see if
+ // - called from system code eg. from inside fnAnim(), to see if
// animation to be quit
for (int i = 0; i < MAX_syncs; i++) {
@@ -92,10 +93,11 @@ bool Get_sync(void) {
return false;
}
-int32 FN_get_sync(int32 *params) {
+int32 Logic::fnGetSync(int32 *params) {
// check for a sync waiting for this character
// - called from script
- // params none
+
+ // params: none
for (int i = 0; i < MAX_syncs; i++) {
if (sync_list[i].id == ID) {
@@ -110,16 +112,17 @@ int32 FN_get_sync(int32 *params) {
return IR_CONT;
}
-int32 FN_wait_sync(int32 *params) {
+int32 Logic::fnWaitSync(int32 *params) {
// keep calling until a sync recieved
- // params none
- debug(5, "FN_wait_sync: %d waits", ID);
+ // params: none
+
+ debug(5, "fnWaitSync: %d waits", ID);
for (int i = 0; i < MAX_syncs; i++) {
if (sync_list[i].id == ID) {
// return sync value waiting
- debug(5, "FN_wait_sync: go");
+ debug(5, "fnWaitSync: go");
RESULT = sync_list[i].sync;
return IR_CONT;
}
diff --git a/sword2/walker.cpp b/sword2/walker.cpp
index b5095bd66c..ebf198bbe2 100644
--- a/sword2/walker.cpp
+++ b/sword2/walker.cpp
@@ -29,7 +29,7 @@
#include "bs2/events.h"
#include "bs2/function.h"
#include "bs2/interpreter.h"
-#include "bs2/logic.h" // for FN_add_to_kill_list
+#include "bs2/logic.h"
#include "bs2/object.h"
#include "bs2/protocol.h"
#include "bs2/router.h"
@@ -37,7 +37,7 @@
namespace Sword2 {
-int16 standby_x; // see FN_set_standby_coords
+int16 standby_x; // see fnSetStandbyCoords
int16 standby_y;
uint8 standby_dir;
@@ -45,7 +45,7 @@ uint8 standby_dir;
* Walk mega to (x,y,dir)
*/
-int32 FN_walk(int32 *params) {
+int32 Logic::fnWalk(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -93,7 +93,7 @@ int32 FN_walk(int32 *params) {
// invalid direction (NB. '8' means end walk on ANY direction)
if (params[6] < 0 || params[6] > 8)
- Con_fatal_error("Invalid direction (%d) in FN_walk", params[6]);
+ Con_fatal_error("Invalid direction (%d) in fnWalk", params[6]);
ob_walkdata = (Object_walkdata *) params[3];
@@ -111,7 +111,7 @@ int32 FN_walk(int32 *params) {
// 2 = zero route but may need to turn
if (route == 1 || route == 2) {
- // so script FN_walk loop continues until end of
+ // so script fnWalk loop continues until end of
// walk-anim
ob_logic->looping = 1;
@@ -119,10 +119,10 @@ int32 FN_walk(int32 *params) {
// need to animate the route now, so don't set result
// or return yet!
- // started walk(James23jun97)
+ // started walk
ob_mega->currently_walking = 1;
- // (see FN_get_player_savedata() in save_rest.cpp
+ // (see fnGetPlayerSaveData() in save_rest.cpp
} else {
// free up the walkdata mem block
router.freeRouteMem();
@@ -157,7 +157,7 @@ int32 FN_walk(int32 *params) {
// finished walk
ob_mega->currently_walking = 0;
- // (see FN_get_player_savedata() in save_rest.cpp
+ // (see fnGetPlayerSaveData() in save_rest.cpp
RESULT = 0; // 0 means ok
@@ -202,7 +202,7 @@ int32 FN_walk(int32 *params) {
// finished walk
ob_mega->currently_walking = 0;
- // (see FN_get_player_savedata() in save_rest.cpp
+ // (see fnGetPlayerSaveData() in save_rest.cpp
// if George's walk has been interrupted to run a new action
// script for instance or Nico's walk has been interrupted by
@@ -221,12 +221,12 @@ int32 FN_walk(int32 *params) {
RESULT = 0; // 0 means ok - finished walk
// CONTINUE the script so that RESULT can be checked!
- // Also, if an anim command follows the FN_walk
- // command, the 1st frame of the anim (which is always
- // a stand frame itself) can replace the final stand
- // frame of the walk, to hide the slight difference
- // between the shrinking on the mega frames and the
- // pre-shrunk anim start-frame.
+ // Also, if an anim command follows the fnWalk command,
+ // the 1st frame of the anim (which is always a stand
+ // frame itself) can replace the final stand frame of
+ // the walk, to hide the slight difference between the
+ // shrinking on the mega frames and the pre-shrunk anim
+ // start-frame.
return IR_CONT;
}
@@ -248,7 +248,7 @@ int32 FN_walk(int32 *params) {
* Walk mega to start position of anim
*/
-int32 FN_walk_to_anim(int32 *params) {
+int32 Logic::fnWalkToAnim(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -286,14 +286,14 @@ int32 FN_walk_to_anim(int32 *params) {
pars[5] = standby_y;
pars[6] = standby_dir;
- debug(5, "WARNING: FN_walk_to_anim(%s) used standby coords", FetchObjectName(params[4]));
+ debug(5, "WARNING: fnWalkToAnim(%s) used standby coords", FetchObjectName(params[4]));
}
if (pars[6] < 0 || pars[6] > 7)
- Con_fatal_error("Invalid direction (%d) in FN_walk_to_anim", pars[6]);
+ Con_fatal_error("Invalid direction (%d) in fnWalkToAnim", pars[6]);
}
- // set up the rest of the parameters for FN_walk()
+ // set up the rest of the parameters for fnWalk()
pars[0] = params[0];
pars[1] = params[1];
@@ -303,17 +303,17 @@ int32 FN_walk_to_anim(int32 *params) {
// walkdata (param 3) is needed for earlySlowOut if player clicks
// elsewhere during the walk
- // call FN_walk() with target coords set to anim start position
- return FN_walk(pars);
+ // call fnWalk() with target coords set to anim start position
+ return fnWalk(pars);
}
/**
* turn mega to <direction>
- * just needs to call FN_walk() with current feet coords, so router can
+ * just needs to call fnWalk() with current feet coords, so router can
* produce anim of turn frames
*/
-int32 FN_turn(int32 *params) {
+int32 Logic::fnTurn(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -331,7 +331,7 @@ int32 FN_turn(int32 *params) {
if (ob_logic->looping == 0) {
if (params[4] < 0 || params[4] > 7)
- Con_fatal_error("Invalid direction (%d) in FN_turn", params[4]);
+ Con_fatal_error("Invalid direction (%d) in fnTurn", params[4]);
ob_mega = (Object_mega *) params[2];
@@ -340,15 +340,15 @@ int32 FN_turn(int32 *params) {
pars[6] = params[4]; // DIRECTION to turn to
}
- // set up the rest of the parameters for FN_walk()
+ // set up the rest of the parameters for fnWalk()
pars[0] = params[0];
pars[1] = params[1];
pars[2] = params[2];
pars[3] = params[3];
- // call FN_walk() with target coords set to feet coords
- return FN_walk(pars);
+ // call fnWalk() with target coords set to feet coords
+ return fnWalk(pars);
}
/**
@@ -357,7 +357,7 @@ int32 FN_turn(int32 *params) {
* the mega object, so the router knows in future
*/
-int32 FN_stand_at(int32 *params) {
+int32 Logic::fnStandAt(int32 *params) {
// params: 0 pointer to object's graphic structure
// 1 pointer to object's mega structure
// 2 target x-coord
@@ -370,7 +370,7 @@ int32 FN_stand_at(int32 *params) {
// check for invalid direction
if (params[4] < 0 || params[4] > 7)
- Con_fatal_error("Invalid direction (%d) in FN_stand_at", params[4]);
+ Con_fatal_error("Invalid direction (%d) in fnStandAt", params[4]);
// set up pointers to the graphic & mega structure
@@ -394,9 +394,9 @@ int32 FN_stand_at(int32 *params) {
}
// stand mega in <direction> at current feet coords
-// just needs to call FN_stand_at() with current feet coords
+// just needs to call fnStandAt() with current feet coords
-int32 FN_stand(int32 *params) {
+int32 Logic::fnStand(int32 *params) {
// params: 0 pointer to object's graphic structure
// 1 pointer to object's mega structure
// 2 target direction
@@ -410,15 +410,15 @@ int32 FN_stand(int32 *params) {
pars[3] = ob_mega->feet_y;
pars[4] = params[2]; // DIRECTION to stand in
- // call FN_stand_at() with target coords set to feet coords
- return FN_stand_at(pars);
+ // call fnStandAt() with target coords set to feet coords
+ return fnStandAt(pars);
}
/**
* stand mega at end position of anim
*/
-int32 FN_stand_after_anim(int32 *params) {
+int32 Logic::fnStandAfterAnim(int32 *params) {
// params: 0 pointer to object's graphic structure
// 1 pointer to object's mega structure
// 2 anim resource id
@@ -433,7 +433,7 @@ int32 FN_stand_after_anim(int32 *params) {
anim_file = res_man.open(params[2]);
anim_head = FetchAnimHeader(anim_file);
- // set up the parameter list for FN_walk_to()
+ // set up the parameter list for fnWalkTo()
pars[0] = params[0];
pars[1] = params[1];
@@ -450,22 +450,22 @@ int32 FN_stand_after_anim(int32 *params) {
pars[3] = standby_y;
pars[4] = standby_dir;
- debug(5, "WARNING: FN_stand_after_anim(%s) used standby coords", FetchObjectName(params[2]));
+ debug(5, "WARNING: fnStandAfterAnim(%s) used standby coords", FetchObjectName(params[2]));
}
if (pars[4] < 0 || pars[4] > 7)
- Con_fatal_error("Invalid direction (%d) in FN_stand_after_anim", pars[4]);
+ Con_fatal_error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
// close the anim file
res_man.close(params[2]);
- // call FN_stand_at() with target coords set to anim end position
- return FN_stand_at(pars);
+ // call fnStandAt() with target coords set to anim end position
+ return fnStandAt(pars);
}
// stand mega at start position of anim
-int32 FN_stand_at_anim(int32 *params) {
+int32 Logic::fnStandAtAnim(int32 *params) {
// params: 0 pointer to object's graphic structure
// 1 pointer to object's mega structure
// 2 anim resource id
@@ -480,7 +480,7 @@ int32 FN_stand_at_anim(int32 *params) {
anim_file = res_man.open(params[2]);
anim_head = FetchAnimHeader(anim_file);
- // set up the parameter list for FN_walk_to()
+ // set up the parameter list for fnWalkTo()
pars[0] = params[0];
pars[1] = params[1];
@@ -497,17 +497,17 @@ int32 FN_stand_at_anim(int32 *params) {
pars[3] = standby_y;
pars[4] = standby_dir;
- debug(5, "WARNING: FN_stand_at_anim(%s) used standby coords", FetchObjectName(params[2]));
+ debug(5, "WARNING: fnStandAtAnim(%s) used standby coords", FetchObjectName(params[2]));
}
if (pars[4] < 0 || pars[4] > 7)
- Con_fatal_error("Invalid direction (%d) in FN_stand_after_anim", pars[4]);
+ Con_fatal_error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
// close the anim file
res_man.close(params[2]);
- // call FN_stand_at() with target coords set to anim end position
- return FN_stand_at(pars);
+ // call fnStandAt() with target coords set to anim end position
+ return fnStandAt(pars);
}
// Code to workout direction from start to dest
@@ -544,11 +544,11 @@ int What_target(int startX, int startY, int destX, int destY) {
/**
* turn mega to face point (x,y) on the floor
- * just needs to call FN_walk() with current feet coords & direction computed
+ * just needs to call fnWalk() with current feet coords & direction computed
* by What_target()
*/
-int32 FN_face_xy(int32 *params) {
+int32 Logic::fnFaceXY(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -573,25 +573,25 @@ int32 FN_face_xy(int32 *params) {
pars[6] = What_target(ob_mega->feet_x, ob_mega->feet_y, params[4], params[5]);
}
- // set up the rest of the parameters for FN_walk()
+ // set up the rest of the parameters for fnWalk()
pars[0] = params[0];
pars[1] = params[1];
pars[2] = params[2];
pars[3] = params[3];
- // call FN_walk() with target coords set to feet coords
- return FN_walk(pars);
+ // call fnWalk() with target coords set to feet coords
+ return fnWalk(pars);
}
-int32 FN_face_mega(int32 *params) {
+int32 Logic::fnFaceMega(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
// 3 pointer to object's walkdata structure
// 4 id of target mega to face
- uint32 null_pc = 3; // get ob_mega
+ uint32 null_pc = 3; // get ob_mega
char *raw_script_ad;
int32 pars[7];
Object_logic *ob_logic;
@@ -606,7 +606,7 @@ int32 FN_face_mega(int32 *params) {
head = (_standardHeader*) res_man.open(params[4]);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("FN_face_mega %d not an object", params[4]);
+ Con_fatal_error("fnFaceMega %d not an object", params[4]);
raw_script_ad = (char *) head;
@@ -629,15 +629,14 @@ int32 FN_face_mega(int32 *params) {
pars[2] = params[2];
pars[3] = params[3];
- // call FN_walk() with target coords set to feet coords
- return FN_walk(pars);
+ // call fnWalk() with target coords set to feet coords
+ return fnWalk(pars);
}
-int32 FN_walk_to_talk_to_mega(int32 *params) {
+int32 Logic::fnWalkToTalkToMega(int32 *params) {
// we route to left or right hand side of target id if possible
// target is a shrinking mega
-
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@@ -669,7 +668,7 @@ int32 FN_walk_to_talk_to_mega(int32 *params) {
head = (_standardHeader*) res_man.open(params[4]);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("FN_walk_to_talk_to_mega %d not an object", params[4]);
+ Con_fatal_error("fnWalkToTalkToMega %d not an object", params[4]);
raw_script_ad = (char *) head;
@@ -714,20 +713,22 @@ int32 FN_walk_to_talk_to_mega(int32 *params) {
// first cycle builds the route - thereafter merely follows it
- // Call FN_walk() with target coords set to feet coords. RESULT will
+ // Call fnWalk() with target coords set to feet coords. RESULT will
// be 1 when it finishes, or 0 if it failed to build route.
- return FN_walk(pars);
+ return fnWalk(pars);
}
-int32 FN_set_walkgrid(int32 *params) {
- Con_fatal_error("FN_set_walkgrid no longer valid");
+int32 Logic::fnSetWalkGrid(int32 *params) {
+ // params: none
+
+ Con_fatal_error("fnSetWalkGrid no longer valid");
return IR_CONT;
}
// add this walkgrid resource to the list of those used for routing in this
// location - note this is ignored in the resource is already in the list
-int32 FN_add_walkgrid(int32 *params) {
+int32 Logic::fnAddWalkGrid(int32 *params) {
// params: 0 id of walkgrid resource
// all objects that add walkgrids must be restarted whenever we
@@ -737,7 +738,7 @@ int32 FN_add_walkgrid(int32 *params) {
if (ID != 8) {
// need to call this in case it wasn't called in script!
// ('params' just used as dummy param)
- FN_add_to_kill_list(params);
+ fnAddToKillList(params);
}
router.addWalkGrid(params[0]);
@@ -753,19 +754,21 @@ int32 FN_add_walkgrid(int32 *params) {
// this location - note that this is ignored if the resource isn't actually
// in the list
-int32 FN_remove_walkgrid(int32 *params) {
+int32 Logic::fnRemoveWalkGrid(int32 *params) {
// params: 0 id of walkgrid resource
router.removeWalkGrid(params[0]);
return IR_CONT;
}
-int32 FN_register_walkgrid(int32 *params) {
- Con_fatal_error("FN_register_walkgrid no longer valid");
+int32 Logic::fnRegisterWalkGrid(int32 *params) {
+ // params: none
+
+ Con_fatal_error("fnRegisterWalkGrid no longer valid");
return IR_CONT;
}
-int32 FN_set_scaling(int32 *params) {
+int32 Logic::fnSetScaling(int32 *params) {
// params: 0 pointer to object's mega structure
// 1 scale constant A
// 2 scale constant B
@@ -783,9 +786,9 @@ int32 FN_set_scaling(int32 *params) {
return IR_CONT;
}
-int32 FN_set_standby_coords(int32 *params) {
- // set the standby walk coords to be used by FN_walk_to_anim &
- // FN_stand_after_anim when the anim header's start/end coords are zero
+int32 Logic::fnSetStandbyCoords(int32 *params) {
+ // set the standby walk coords to be used by fnWalkToAnim and
+ // fnStandAfterAnim when the anim header's start/end coords are zero
// useful during development; can stay in final game anyway
@@ -794,7 +797,7 @@ int32 FN_set_standby_coords(int32 *params) {
// 2 direction (0..7)
if (params[2] < 0 || params[2] > 7)
- Con_fatal_error("Invalid direction (%d) in FN_set_standby_coords", params[2]);
+ Con_fatal_error("Invalid direction (%d) in fnSetStandbyCoords", params[2]);
standby_x = (int16) params[0];
standby_y = (int16) params[1];
diff --git a/sword2/walker.h b/sword2/walker.h
index 5a61fc1ca4..73fefc8fbf 100644
--- a/sword2/walker.h
+++ b/sword2/walker.h
@@ -22,13 +22,6 @@
namespace Sword2 {
-int32 FN_face_mega(int32 *params);
-int32 FN_turn(int32 *params);
-int32 FN_walk(int32 *params);
-int32 FN_walk_to_anim(int32 *params);
-int32 FN_stand_after_anim(int32 *params);
-int32 FN_stand(int32 *params);
-
} // End of namespace Sword2
#endif