Skip to content
Browse files

MegaZeux 2.80d release.

  • Loading branch information...
1 parent 4782ebc commit 8ab51ab301ae8920b9ec93d250dec19f9fe43311 @ajs1984 committed Aug 11, 2008
Showing with 4,836 additions and 3,544 deletions.
  1. +1 −1 Makefile
  2. +1 −1 Makefile.linux
  3. +22 −26 audio.cpp
  4. +1 −0 audio.h
  5. +14 −9 board.cpp
  6. +76 −8 changelog.txt
  7. +10 −2 config.txt
  8. +2 −2 configure.cpp
  9. +209 −132 counter.cpp
  10. +1 −1 counter.h
  11. +40 −0 counter_first_letter.h
  12. +2 −2 counter_list.txt
  13. +208 −243 edit.cpp
  14. +72 −57 edit_di.cpp
  15. +60 −24 event.cpp
  16. +1 −1 event.h
  17. +31 −12 fsafeopen.cpp
  18. +141 −137 game.cpp
  19. +49 −56 game2.cpp
  20. +1,068 −998 graphics.cpp
  21. +7 −7 help.doc
  22. +1 −1 idarray.cpp
  23. +0 −2 idput.cpp
  24. +6 −7 intake.cpp
  25. +5 −8 main.cpp
  26. +493 −211 mzm.cpp
  27. +4 −3 mzm.h
  28. +115 −6 mzm.txt
  29. +1,089 −881 rasm.cpp
  30. +17 −0 rasm.h
  31. +129 −114 robo_ed.cpp
  32. +144 −90 robot.cpp
  33. +15 −15 robot.h
  34. +221 −161 runrobo2.cpp
  35. +80 −40 scrdisp.cpp
  36. +5 −5 scrdisp.h
  37. +2 −2 sfx.cpp
  38. +25 −29 sprite.cpp
  39. +5 −5 sprite.h
  40. +192 −98 txt2hlp.cpp
  41. +217 −86 window.cpp
  42. +6 −7 window.h
  43. +49 −54 world.cpp
View
2 Makefile
@@ -10,7 +10,7 @@ OBJS = main.o graphics.o window.o hexchar.o event.o \
PREFIX = /usr
-BIN = mzx280c.exe
+BIN = mzx280d.exe
CC = gcc
CPP = g++
View
2 Makefile.linux
@@ -10,7 +10,7 @@ OBJS = main.o graphics.o window.o hexchar.o event.o \
PREFIX = /usr
-BIN = mzx280c
+BIN = mzx280d
CC = gcc
CPP = g++
View
48 audio.cpp
@@ -37,6 +37,7 @@
#include "configure.h"
#include "gdm2s3m.h"
#include "fsafeopen.h"
+#include "delay.h"
struct _ModPlugFile
{
@@ -53,12 +54,11 @@ const int freq_conversion = 3579364;
void audio_callback(void *userdata, Uint8 *stream, int len)
{
- int i, i2, i3, offset = 0;
+ int i, i2, offset = 0;
Sint16 *mix_src_ptr;
Sint32 *mix_dest_ptr;
Sint32 *buffer_src_ptr;
Sint16 *buffer_dest_ptr;
- Sint16 cur_sample16;
Sint32 cur_sample;
int sample_duration, end_duration;
int increment_value, increment_buffer;
@@ -223,7 +223,7 @@ void init_audio(config_info *conf)
SDL_AudioSpec desired_spec =
{
44100,
- AUDIO_S16,
+ AUDIO_S16SYS,
2,
0,
buffer_size,
@@ -348,7 +348,21 @@ void play_sample(int freq, char *filename)
// FIXME - destroy least recently used?
if(audio.num_samples_playing >= MAX_SAMS)
- return;
+ {
+ unsigned int smallest = audio.sam_timestamps[0];
+ int smallest_i = 0;
+ int i;
+ for(i = 1; i < MAX_SAMS; i++)
+ {
+ if(audio.sam_timestamps[i] < smallest)
+ {
+ smallest = audio.sam_timestamps[i];
+ smallest_i = i;
+ }
+ }
+
+ end_individual_sample(smallest_i);
+ }
if(extension_pos && !strcasecmp(filename + extension_pos, ".sam"))
{
@@ -391,9 +405,6 @@ void play_sample(int freq, char *filename)
sample_loaded->mSoundFile.Ins[1].nVolume = (256 * sound_gvol) / 8;
sample_loaded->mSoundFile.Ins[2].nVolume = (256 * sound_gvol) / 8;
- // This number is pretty much obtained via experimentation. It can probably
- // stand to be a little higher.
-
// Find a free position to put it
for(i = 0; i < 16; i++)
{
@@ -405,6 +416,7 @@ void play_sample(int freq, char *filename)
audio.sample_buffers[i] =
(Sint16 *)malloc(audio.audio_settings.size);
audio.num_samples_playing++;
+ audio.sam_timestamps[i] = get_ticks();
}
free(input_buffer);
@@ -454,30 +466,14 @@ void volume_mod(int vol)
audio.current_mod->mSoundFile.SetMasterVolume((vol * music_gvol / 16) + 1);
}
-void mod_exit(void)
-{
-
-}
-
-void mod_init(void)
-{
-
-}
+// FIXME - Implement? The best route right now would be to load a module
+// then mangle it so it only plays the given sample at the given frequency.
void spot_sample(int freq, int sample)
{
}
-// This function will remove samples from the cache one at a time,
-// starting with least-played and ending with currently-playing.
-// Call it removes ONE sample unless CLEAR_ALL is set. Returns 1
-// if nothing was found to deallocate (IE no further fixes possible)
-int free_sam_cache(char clear_all)
-{
-
-}
-
void sound(int frequency, int duration)
{
audio.pc_speaker_playing = 1;
@@ -510,7 +506,7 @@ const int default_period = 428;
void convert_sam_to_wav(char *source_name, char *dest_name)
{
FILE *source, *dest;
- int frequency, period;
+ int frequency;
int source_length, dest_length;
char *data;
View
1 audio.h
@@ -40,6 +40,7 @@ typedef struct
Sint32 *mix_buffer;
Sint16 *mod_buffer;
Sint16 *sample_buffers[MAX_SAMS];
+ Uint32 sam_timestamps[MAX_SAMS];
Uint32 repeat_timeout;
Uint32 repeat_timestamp;
Uint32 pc_speaker_on;
View
23 board.cpp
@@ -75,6 +75,7 @@ Board *load_board_allocate_direct(FILE *fp, int savegame)
{
Board *cur_board = (Board *)malloc(sizeof(Board));
load_board_direct(cur_board, fp, savegame);
+ fread(cur_board->board_name, 25, 1, fp);
return cur_board;
}
@@ -182,6 +183,7 @@ void load_board_direct(Board *cur_board, FILE *fp, int savegame)
// Load board parameters
fread(cur_board->mod_playing, FILENAME_SIZE, 1, fp);
+ cur_board->mod_playing[FILENAME_SIZE] = 0;
cur_board->viewport_x = fgetc(fp);
cur_board->viewport_y = fgetc(fp);
cur_board->viewport_width = fgetc(fp);
@@ -425,12 +427,14 @@ void save_board_file(Board *cur_board, char *name)
fputs(world_version_string, board_file);
optimize_null_objects(cur_board);
save_board(cur_board, board_file, 0);
+ // Write name
+ fwrite(cur_board->board_name, 25, 1, board_file);
fclose(board_file);
}
int save_board(Board *cur_board, FILE *fp, int savegame)
{
- int num_robots, num_scrolls, num_sensors, num_robots_active;
+ int num_robots, num_scrolls, num_sensors;
int start_location = ftell(fp);
int board_width = cur_board->board_width;
int board_height = cur_board->board_height;
@@ -930,14 +934,15 @@ void change_board_size(Board *src_board, int new_width, int new_height)
// Fill in any blanks
if(new_height > board_height)
{
- int size_difference = new_size - board_size;
-
- memset(level_id + board_size, 0, size_difference);
- memset(level_param + board_size, 0, size_difference);
- memset(level_color + board_size, 7, size_difference);
- memset(level_under_id + board_size, 0, size_difference);
- memset(level_under_param + board_size, 0, size_difference);
- memset(level_under_color + board_size, 7, size_difference);
+ int offset = new_width * board_height;
+ int size_difference = new_size - offset;
+
+ memset(level_id + offset, 0, size_difference);
+ memset(level_param + offset, 0, size_difference);
+ memset(level_color + offset, 7, size_difference);
+ memset(level_under_id + offset, 0, size_difference);
+ memset(level_under_param + offset, 0, size_difference);
+ memset(level_under_color + offset, 7, size_difference);
if(overlay_mode)
{
View
84 changelog.txt
@@ -1,3 +1,67 @@
++ Fixed cursor going invisible when escaping from import in the editor
++ Fixed robot editor entry when pressing OK on global info
++ Fixed lack of name for MZB import/export (any MZB's exported in prior
+ beta versions still won't have a name)
++ Fixed some problems with setting the mouse position
++ Fixed problem with exits not bringing you all the way to the edge if width
+ over 400 or height over 200
++ Fixed bug that cleared too much when increasing both width and height while
+ resizing the board
++ Fixed problem with 1 char shortcut commands with spaces immediately after them
++ Fixed problems with load_robot and load_bc (caused crashes and infinite loops)
++ Optmized RASM heavily (this should be most noticable when doing a lot of
+ external robot loading from text files)
++ Fixed inability to use absolute paths in loading a game from command line
++ Fixed lastshot/lasttouch conditions with directions not working
++ Fixed char editor in robots not going into SMZX mode when proper
++ Cleaned up source code so it passes -Wall without complaint and in the process
+ corrected some glaring code errors that may have corrected random problems
++ File opening broken in 2.80c, fixed
++ Implemented MZM2 saving and loading and rewrote mzm.cpp (if anything is changed
+ or fixed regarding MZMs, attribute it to this). MZM2s can be of larger
+ dimensions, smaller filesize for same amount of data, and can store robots.
++ Fixed bug that could cause MZX to crash when making new strings
++ Block operations to overlay when overlay was off caused crashes - fixed
++ Fixed a problem with sprite ccheck2 against other sprites
++ Optimized function counter lookups a bit; speed gain for all counter accesses
+ (especially ones that begin with certain characters such as _)
++ Fixed disassembly error with ' ' character
++ Fixed assembly error where condition extended dir (such as blocked opp seek)
+ was not getting compiled with the dir extension
++ Fixed editor bug where the param was not being cleared when overwriting things
+ by double placement
++ Fixed inability to use counters with playercolor/bulletcolor/missilecolor
++ Added ability to use counters in place of p?? in the robot editor
+ Note - even though this expands functionality of the editor this does not
+ require a version number change because the worlds will still be playable in
+ older MZX versions (and will display correctly in the robot editor - you simply
+ won't be able to correctly edit the commands)
++ Mouse correctly limited to screen edges now
++ Fixed inability to overwrite robots with pushable robots and vice-versa,
+ as well as scrolls with signs and vice-versa
++ Possibly fixed problem with windowing error when editing global robot (?)
++ Fixed disappearing cursor after color selection box with mouse (and other places?)
++ Fixed bug in sprite clipping that caused some to be clipped off inappropriately
++ Made board_id/board_param counters readable
++ Added bound checks for all counters using board_x/board_y/overlay_x/overlay_y
++ Removed ability to put robots, scrolls/signs, and sensors (with the put command in
+ Robotic)
++ Fixed potential direction corruption bug causing directions not to work
+ sometimes even if they display correctly in the robot editor
++ Fixed copy overlay to MZM copying to overlay too
++ Fixed a bug where debug window could display the wrong amount of robot mem
+ and potentially even crash MZX
++ Fixed help_menu counter not doing anything (durr)
++ Changed sprite draw order so they're drawn underneath the message bar,
+ debug box, and time remaining display
++ Changed put p?? in Robotic so it will put default params if available
++ Fixed a bug that could cause copies from overlay to vlayer to not end up at
+ the correct destination
++ Fixed a bug where c?x and cx? would not display correctly in the robot editor
++ Optimized copy blocks a bit using variable length arrays instead of malloc
+
+August 16, 2004 - MZX 2.80c
+
+ Fixed issues with the commands counter not being reset
+ Color intensity now gets reset when you enter the editor
+ SAMs got cutoff sometimes now.. fixed
@@ -49,6 +113,9 @@
+ Lengthened size of mod name buffers
+ Fixed bug where send x y doesn't work from the global robot
+ Fixed a few bugs that could cause MZX to crash
++ Fixed a bug that prevented copyrobot "string" from working in some
+ situations
++ Fixed a bug allowing player duplication in board importing
August 11, 2004 - MZX 2.80b
@@ -64,28 +131,28 @@ August 11, 2004 - MZX 2.80b
+ The player and pushable robots can now be pushed by the push command
+ Fixed bug where you could clone the player by switching boards
+ Fixed bug where you could either turn off overlay or switch to boards
- that don't have it while in overlay edit mode...
+ that don't have it while in overlay edit mode...
+ Fixed bug where remains of debug window would not be cleared in editor
- if the board width is too small
+ if the board width is too small
+ Fixed bug where turning off the menu with a board too small would mess
- things up
+ things up
+ Fixed bug where run lengths were saved one too large... this could fix
- stability problems in at least occasional cases (with saved worlds or
- save games, at least)
+ stability problems in at least occasional cases (with saved worlds or
+ save games, at least)
+ Fixed placing solid things beneath robots (like bombs)
+ Added support for a keyboard plus in the char editors
+ Fixed previous button in SFX editor
+ Made robot name box disappear when robot char box comes up...
+ Fixed bug where mods restart after pressing P if they're the same mod
- as what was playing before
+ as what was playing before
+ Fixed problem with changing params (with P) in the editor.
+ Fixed bug where null boards were not being pruned from old worlds upon
- load
+ load
+ Made file name saving box larger (for saving games and worlds)
+ Fixed bug where default (100%) palette intensity values would not be
applied to the palette a game loads with
+ Fixed bug where exporting char sets that are full size caused a 0
- byte charset to be exported (8bit wraparound)
+ byte charset to be exported (8bit wraparound)
- Removed export text in the board editor. Don't think anyone wanted it...
+ Added support for forms such as :line
+ Fixed sporadic incompletion of strings without trailing quotes at the
@@ -116,3 +183,4 @@ August 11, 2004 - MZX 2.80b
August 9, 2004 - First release, MZX 2.80 BETA
+
View
12 config.txt
@@ -56,15 +56,15 @@
# Allow music to be sampled at higher precision. Increases CPU
# usage but increases audio quality as well.
-#enable_oversampling = 0
+enable_oversampling = 1
# Set resampling mode. Choices are:
# none (fastest, poor quality)
# linear (fast, good quality)
# cubic (slow, great quality)
# fir (very slow, excellent quality)
-#resampling_mode = linear
+resampling_mode = fir
# Whether music/samples should be played or not.
# Does not include PC speaker effects.
@@ -75,16 +75,24 @@
#pc_speaker_on = 1
+# Volume music plays at
+#music_volume = 8
+
+# Volume samples play at
+#sample_volume = 8
### Game options ###
# Name of world file that should be loaded when MZX starts.
+
#startup_file = caverns.mzx
# Default save file name given when you first try to save.
+
#save_file = saved.sav
# Speed MZX should start at (1 through 9)
+
#mzx_speed = 4
View
4 configure.cpp
@@ -363,8 +363,8 @@ config_info default_options =
2048,
0,
1,
- 7,
- 7,
+ 8,
+ 8,
1,
1,
View
341 counter.cpp
@@ -38,6 +38,7 @@
#include "audio.h"
#include "rasm.h"
#include "fsafeopen.h"
+#include "counter_first_letter.h"
typedef int (* builtin_read_function)(World *mzx_world,
Function_counter *counter, char *name, int id);
@@ -192,8 +193,8 @@ int thisx_read(World *mzx_world, Function_counter *counter,
if(mzx_world->mid_prefix == 2)
return (mzx_world->current_board->robot_list[id])->xpos -
mzx_world->player_x;
- else
- return (mzx_world->current_board->robot_list[id])->xpos;
+
+ return (mzx_world->current_board->robot_list[id])->xpos;
}
int thisy_read(World *mzx_world, Function_counter *counter,
@@ -202,8 +203,8 @@ int thisy_read(World *mzx_world, Function_counter *counter,
if(mzx_world->mid_prefix == 2)
return (mzx_world->current_board->robot_list[id])->ypos -
mzx_world->player_y;
- else
- return (mzx_world->current_board->robot_list[id])->ypos;
+
+ return (mzx_world->current_board->robot_list[id])->ypos;
}
int playerx_read(World *mzx_world, Function_counter *counter,
@@ -312,7 +313,12 @@ int board_char_read(World *mzx_world, Function_counter *counter,
Board *src_board = mzx_world->current_board;
int offset = get_counter(mzx_world, "board_x", id) +
(get_counter(mzx_world, "board_y", id) * src_board->board_width);
- return get_id_char(src_board, offset);
+ int board_size = src_board->board_width * src_board->board_height;
+
+ if((offset >- 0) && (offset < board_size))
+ return get_id_char(src_board, offset);
+
+ return -1;
}
int board_color_read(World *mzx_world, Function_counter *counter,
@@ -321,7 +327,12 @@ int board_color_read(World *mzx_world, Function_counter *counter,
Board *src_board = mzx_world->current_board;
int offset = get_counter(mzx_world, "board_x", id) +
(get_counter(mzx_world, "board_y", id) * src_board->board_width);
- return get_id_color(src_board, offset);
+ int board_size = src_board->board_width * src_board->board_height;
+
+ if((offset >- 0) && (offset < board_size))
+ return get_id_color(src_board, offset);
+
+ return -1;
}
int board_w_read(World *mzx_world, Function_counter *counter,
@@ -336,16 +347,46 @@ int board_h_read(World *mzx_world, Function_counter *counter,
return mzx_world->current_board->board_height;
}
+int board_id_read(World *mzx_world, Function_counter *counter,
+ char *name, int id)
+{
+ Board *src_board = mzx_world->current_board;
+ int offset = get_counter(mzx_world, "board_x", id) +
+ (get_counter(mzx_world, "board_y", id) * src_board->board_width);
+ int board_size = src_board->board_width * src_board->board_height;
+
+ if((offset > 0) && (offset < board_size))
+ return src_board->level_id[offset];
+
+ return -1;
+}
+
void board_id_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
Board *src_board = mzx_world->current_board;
int offset = get_counter(mzx_world, "board_x", id) +
(get_counter(mzx_world, "board_y", id) * src_board->board_width);
+ int board_size = src_board->board_width * src_board->board_height;
+
+ if(((value < 122) || (value == 127)) &&
+ (src_board->level_id[offset] < 122) && (offset >= 0) &&
+ (offset < board_size))
+ src_board->level_id[offset] = value;
+}
+
+int board_param_read(World *mzx_world, Function_counter *counter,
+ char *name, int id)
+{
+ Board *src_board = mzx_world->current_board;
+ int offset = get_counter(mzx_world, "board_x", id) +
+ (get_counter(mzx_world, "board_y", id) * src_board->board_width);
+ int board_size = src_board->board_width * src_board->board_height;
- if(((value < 122) || (value == 127)) &&
- (src_board->level_id[offset] < 122))
- src_board->level_id[offset] = value;
+ if((offset >= 0) && (offset < board_size))
+ return src_board->level_param[offset];
+
+ return -1;
}
void board_param_write(World *mzx_world, Function_counter *counter,
@@ -354,9 +395,12 @@ void board_param_write(World *mzx_world, Function_counter *counter,
Board *src_board = mzx_world->current_board;
int offset = get_counter(mzx_world, "board_x", id) +
(get_counter(mzx_world, "board_y", id) * src_board->board_width);
+ int board_size = src_board->board_width * src_board->board_height;
- if(src_board->level_id[offset] < 122)
- src_board->level_param[offset] = value;
+ if((src_board->level_id[offset] < 122) &&
+ (src_board->level_id[offset] < 122) && (offset >= 0) &&
+ (offset < board_size))
+ src_board->level_param[offset] = value;
}
int red_value_read(World *mzx_world, Function_counter *counter,
@@ -369,37 +413,37 @@ int red_value_read(World *mzx_world, Function_counter *counter,
int green_value_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
- int cur_color = get_counter(mzx_world, "current_color", id);
+ int cur_color = get_counter(mzx_world, "current_color", id) & 0xFF;
return get_green_component(cur_color);
}
int blue_value_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
- int cur_color = get_counter(mzx_world, "current_color", id);
+ int cur_color = get_counter(mzx_world, "current_color", id) & 0xFF;
return get_blue_component(cur_color);
}
void red_value_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
- int cur_color = get_counter(mzx_world, "current_color", id);
+ int cur_color = get_counter(mzx_world, "current_color", id) & 0xFF;
set_red_component(cur_color, value);
pal_update = 1;
}
void green_value_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
- int cur_color = get_counter(mzx_world, "current_color", id);
+ int cur_color = get_counter(mzx_world, "current_color", id) & 0xFF;
set_green_component(cur_color, value);
pal_update = 1;
}
void blue_value_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
- int cur_color = get_counter(mzx_world, "current_color", id);
+ int cur_color = get_counter(mzx_world, "current_color", id) & 0xFF;
set_blue_component(cur_color, value);
pal_update = 1;
}
@@ -428,7 +472,12 @@ int overlay_char_read(World *mzx_world, Function_counter *counter,
Board *src_board = mzx_world->current_board;
int offset = get_counter(mzx_world, "overlay_x", id) +
(get_counter(mzx_world, "overlay_y", id) * src_board->board_width);
- return src_board->overlay[offset];
+ int board_size = src_board->board_width * src_board->board_height;
+
+ if((offset >= 0) && (offset < board_size))
+ return src_board->overlay[offset];
+
+ return -1;
}
int overlay_color_read(World *mzx_world, Function_counter *counter,
@@ -437,7 +486,12 @@ int overlay_color_read(World *mzx_world, Function_counter *counter,
Board *src_board = mzx_world->current_board;
int offset = get_counter(mzx_world, "overlay_x", id) +
(get_counter(mzx_world, "overlay_y", id) * src_board->board_width);
- return src_board->overlay_color[offset];
+ int board_size = src_board->board_width * src_board->board_height;
+
+ if((offset >= 0) && (offset < board_size))
+ return src_board->overlay_color[offset];
+
+ return -1;
}
int smzx_mode_read(World *mzx_world, Function_counter *counter,
@@ -589,7 +643,7 @@ int spr_cheight_read(World *mzx_world, Function_counter *counter,
void spr_num_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
- value &= 0xFF;
+ value &= 0xFF;
mzx_world->sprite_num = (unsigned int)value;
}
@@ -671,19 +725,19 @@ void spr_refx_write(World *mzx_world, Function_counter *counter,
{
int spr_num = strtol(name + 3, NULL, 10) & (MAX_SPRITES - 1) & 0xFF;
- if(value < 0)
- value = 0;
+ if(value < 0)
+ value = 0;
- (mzx_world->sprite_list[spr_num])->ref_x = value;
+ (mzx_world->sprite_list[spr_num])->ref_x = value;
}
void spr_refy_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
int spr_num = strtol(name + 3, NULL, 10) & (MAX_SPRITES - 1) & 0xFF;
- if(value < 0)
- value = 0;
+ if(value < 0)
+ value = 0;
(mzx_world->sprite_list[spr_num])->ref_y = value;
}
@@ -937,7 +991,7 @@ int time_seconds_read(World *mzx_world, Function_counter *counter,
int vch_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
- int x, y;
+ unsigned int x, y;
unsigned int vlayer_width = mzx_world->vlayer_width;
unsigned int vlayer_height = mzx_world->vlayer_height;
translate_coordinates(name + 3, &x, &y);
@@ -947,12 +1001,14 @@ int vch_read(World *mzx_world, Function_counter *counter,
int offset = x + (y * vlayer_width);
return mzx_world->vlayer_chars[offset];
}
+
+ return -1;
}
void vch_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
- int x, y;
+ unsigned int x, y;
unsigned int vlayer_width = mzx_world->vlayer_width;
unsigned int vlayer_height = mzx_world->vlayer_height;
translate_coordinates(name + 3, &x, &y);
@@ -967,7 +1023,7 @@ void vch_write(World *mzx_world, Function_counter *counter,
int vco_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
- int x, y;
+ unsigned int x, y;
unsigned int vlayer_width = mzx_world->vlayer_width;
unsigned int vlayer_height = mzx_world->vlayer_height;
translate_coordinates(name + 3, &x, &y);
@@ -977,12 +1033,14 @@ int vco_read(World *mzx_world, Function_counter *counter,
int offset = x + (y * vlayer_width);
return mzx_world->vlayer_colors[offset];
}
+
+ return -1;
}
void vco_write(World *mzx_world, Function_counter *counter,
char *name, int value, int id)
{
- int x, y;
+ unsigned int x, y;
unsigned int vlayer_width = mzx_world->vlayer_width;
unsigned int vlayer_height = mzx_world->vlayer_height;
translate_coordinates(name + 3, &x, &y);
@@ -1229,7 +1287,7 @@ int fread_counter_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
if(mzx_world->input_file)
- fgetw(mzx_world->input_file);
+ return fgetw(mzx_world->input_file);
else
return -1;
}
@@ -1238,7 +1296,7 @@ int fread_pos_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
if(mzx_world->input_file)
- ftell(mzx_world->input_file);
+ return ftell(mzx_world->input_file);
else
return -1;
}
@@ -1311,13 +1369,13 @@ int robot_id_read(World *mzx_world, Function_counter *counter,
int robot_id_n_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
- return get_robot_id(mzx_world->current_board, name + 9);
+ return get_robot_id(mzx_world->current_board, name + 9);
}
int rid_read(World *mzx_world, Function_counter *counter,
char *name, int id)
{
- return get_robot_id(mzx_world->current_board, name + 3);
+ return get_robot_id(mzx_world->current_board, name + 3);
}
int r_read(World *mzx_world, Function_counter *counter,
@@ -1330,6 +1388,8 @@ int r_read(World *mzx_world, Function_counter *counter,
if((robot_num <= src_board->num_robots) &&
(src_board->robot_list[robot_num] != NULL))
return get_counter(mzx_world, next + 1, robot_num);
+
+ return -1;
}
void r_write(World *mzx_world, Function_counter *counter,
@@ -1550,8 +1610,8 @@ Function_counter builtin_counters[] =
{ "board_char", 0, board_char_read, NULL },
{ "board_color", 0, board_color_read, NULL },
{ "board_h", 0, board_h_read, NULL },
- { "board_id", 0, NULL, board_id_write },
- { "board_param", 0, NULL, board_param_write },
+ { "board_id", 0, board_id_read, board_id_write },
+ { "board_param", 0, board_param_read, board_param_write },
{ "board_w", 0, board_w_read, NULL },
{ "bullettype", 0, bullettype_read, bullettype_write },
{ "buttons", 0, buttons_read, NULL },
@@ -1671,10 +1731,8 @@ int set_counter_special(World *mzx_world, int spec_type,
{
if(char_value[0])
{
- char_value[12] = 0;
-
- if(mzx_world->input_file)
- fclose(mzx_world->input_file);
+ if(mzx_world->input_file)
+ fclose(mzx_world->input_file);
mzx_world->input_file = fsafeopen(char_value, "rb");
}
@@ -1692,10 +1750,8 @@ int set_counter_special(World *mzx_world, int spec_type,
{
if(char_value[0])
{
- char_value[12] = 0;
-
- if(mzx_world->output_file)
- fclose(mzx_world->output_file);
+ if(mzx_world->output_file)
+ fclose(mzx_world->output_file);
mzx_world->output_file = fsafeopen(char_value, "wb");
}
@@ -1715,8 +1771,8 @@ int set_counter_special(World *mzx_world, int spec_type,
{
char_value[12] = 0;
- if(mzx_world->output_file)
- fclose(mzx_world->output_file);
+ if(mzx_world->output_file)
+ fclose(mzx_world->output_file);
mzx_world->output_file = fsafeopen(char_value, "ab");
}
@@ -1736,8 +1792,8 @@ int set_counter_special(World *mzx_world, int spec_type,
{
char_value[12] = 0;
- if(mzx_world->output_file)
- fclose(mzx_world->output_file);
+ if(mzx_world->output_file)
+ fclose(mzx_world->output_file);
mzx_world->output_file = fsafeopen(char_value, "r+b");
}
@@ -1774,12 +1830,16 @@ int set_counter_special(World *mzx_world, int spec_type,
case FOPEN_LOAD_GAME:
{
int faded;
- reload_savegame(mzx_world, char_value, &faded);
-
- if(faded)
- insta_fadeout();
-
- mzx_world->swapped = 1;
+ char translated_name[MAX_PATH];
+ if(fsafetranslate(char_value, translated_name))
+ {
+ reload_savegame(mzx_world, char_value, &faded);
+
+ if(faded)
+ insta_fadeout();
+
+ mzx_world->swapped = 1;
+ }
return 0;
}
@@ -1790,26 +1850,32 @@ int set_counter_special(World *mzx_world, int spec_type,
if(new_program)
{
- Board *src_board = mzx_world->current_board;
+ Board *src_board = mzx_world->current_board;
Robot *cur_robot;
int robot_id = id;
if(value != -1)
robot_id = value;
- if(robot_id <= src_board->num_robots)
- {
- cur_robot = mzx_world->current_board->robot_list[robot_id];
-
- if(cur_robot != NULL)
- {
- reallocate_robot(cur_robot, new_size);
- memcpy(cur_robot->program, new_program, new_size);
- free(new_program);
- cur_robot->cur_prog_line = 1;
- return 1;
- }
- }
+ if(robot_id <= src_board->num_robots)
+ {
+ cur_robot = mzx_world->current_board->robot_list[robot_id];
+
+ if(cur_robot != NULL)
+ {
+ reallocate_robot(cur_robot, new_size);
+ clear_label_cache(cur_robot->label_list, cur_robot->num_labels);
+
+ memcpy(cur_robot->program, new_program, new_size);
+ free(new_program);
+ cur_robot->cur_prog_line = 1;
+ cur_robot->label_list =
+ cache_robot_labels(cur_robot, &(cur_robot->num_labels));
+
+ if(value == -1)
+ return 1;
+ }
+ }
}
return 0;
@@ -1818,7 +1884,7 @@ int set_counter_special(World *mzx_world, int spec_type,
case FOPEN_LOAD_BC:
{
FILE *bc_file = fsafeopen(char_value, "rb");
- Board *src_board = mzx_world->current_board;
+ Board *src_board = mzx_world->current_board;
int new_size;
if(bc_file)
@@ -1829,27 +1895,32 @@ int set_counter_special(World *mzx_world, int spec_type,
if(value != -1)
robot_id = value;
- if(robot_id <= src_board->num_robots)
- {
- cur_robot = mzx_world->current_board->robot_list[robot_id];
-
- if(cur_robot != NULL)
- {
- fseek(bc_file, 0, SEEK_END);
- new_size = ftell(bc_file);
- fseek(bc_file, 0, SEEK_SET);
-
- reallocate_robot(cur_robot, new_size);
- fread(cur_robot->program, new_size, 1, bc_file);
- cur_robot->cur_prog_line = 1;
-
- fclose(bc_file);
-
- return 1;
- }
- }
+ if(robot_id <= src_board->num_robots)
+ {
+ cur_robot = mzx_world->current_board->robot_list[robot_id];
+
+ if(cur_robot != NULL)
+ {
+ fseek(bc_file, 0, SEEK_END);
+ new_size = ftell(bc_file);
+ fseek(bc_file, 0, SEEK_SET);
+
+ reallocate_robot(cur_robot, new_size);
+ clear_label_cache(cur_robot->label_list, cur_robot->num_labels);
+
+ fread(cur_robot->program, new_size, 1, bc_file);
+ cur_robot->cur_prog_line = 1;
+ cur_robot->label_list =
+ cache_robot_labels(cur_robot, &(cur_robot->num_labels));
+
+ fclose(bc_file);
+
+ if(value == -1)
+ return 1;
+ }
+ }
- fclose(bc_file);
+ fclose(bc_file);
}
return 0;
@@ -1858,7 +1929,7 @@ int set_counter_special(World *mzx_world, int spec_type,
case FOPEN_SAVE_ROBOT:
{
Robot *cur_robot;
- Board *src_board = mzx_world->current_board;
+ Board *src_board = mzx_world->current_board;
int robot_id = id;
int allow_extras = mzx_world->conf.disassemble_extras;
int base = mzx_world->conf.disassemble_base;
@@ -1868,52 +1939,51 @@ int set_counter_special(World *mzx_world, int spec_type,
cur_robot = mzx_world->current_board->robot_list[robot_id];
- if(robot_id <= src_board->num_robots)
- {
- cur_robot = mzx_world->current_board->robot_list[robot_id];
-
- if(cur_robot != NULL)
- {
- disassemble_file(char_value, cur_robot->program,
- allow_extras, base);
- }
- }
+ if(robot_id <= src_board->num_robots)
+ {
+ cur_robot = mzx_world->current_board->robot_list[robot_id];
+
+ if(cur_robot != NULL)
+ {
+ disassemble_file(char_value, cur_robot->program,
+ allow_extras, base);
+ }
+ }
return 0;
}
case FOPEN_SAVE_BC:
{
- FILE *bc_file = fopen(char_value, "wb");
- int new_size;
+ FILE *bc_file = fsafeopen(char_value, "wb");
if(bc_file)
{
Robot *cur_robot;
- Board *src_board = mzx_world->current_board;
+ Board *src_board = mzx_world->current_board;
int robot_id = id;
if(value != -1)
robot_id = value;
- if(robot_id <= src_board->num_robots)
- {
- cur_robot = mzx_world->current_board->robot_list[robot_id];
-
- if(cur_robot != NULL)
- {
- fwrite(cur_robot->program, cur_robot->program_length, 1, bc_file);
- }
- }
-
- fclose(bc_file);
+ if(robot_id <= src_board->num_robots)
+ {
+ cur_robot = mzx_world->current_board->robot_list[robot_id];
+
+ if(cur_robot != NULL)
+ {
+ fwrite(cur_robot->program, cur_robot->program_length, 1, bc_file);
+ }
+ }
+
+ fclose(bc_file);
}
return 0;
}
-
- return 0;
}
+
+ return 0;
}
// I don't know yet if this works in pure C
@@ -2175,23 +2245,30 @@ String *find_string(World *mzx_world, char *name, int *next)
Function_counter *find_function_counter(char *name)
{
- int bottom = 0, top = num_builtin_counters - 1, middle;
+ int bottom, top, middle;
+ int first_letter = tolower(name[0]) * 2;
int cmpval;
Function_counter *base = builtin_counters;
- while(bottom <= top)
- {
- middle = (top + bottom) / 2;
- cmpval = match_function_counter(name, (base[middle]).counter_name);
-
- if(cmpval > 0)
- bottom = middle + 1;
- else
+ bottom = counter_first_letter[first_letter];
+ top = counter_first_letter[first_letter + 1];
- if(cmpval < 0)
- top = middle - 1;
- else
- return base + middle;
+ if(bottom != -1)
+ {
+ while(bottom <= top)
+ {
+ middle = (top + bottom) / 2;
+ cmpval = match_function_counter(name + 1, (base[middle]).counter_name + 1);
+
+ if(cmpval > 0)
+ bottom = middle + 1;
+ else
+
+ if(cmpval < 0)
+ top = middle - 1;
+ else
+ return base + middle;
+ }
}
return NULL;
@@ -2248,13 +2325,14 @@ void add_string(World *mzx_world, char *name, char *value, int position)
if(count == allocated)
{
if(allocated)
- allocated *= allocated * 2;
+ allocated *= 2;
else
allocated = MIN_STRING_ALLOCATE;
mzx_world->string_list =
(String **)realloc(base, sizeof(String *) * allocated);
mzx_world->num_strings_allocated = allocated;
+ base = mzx_world->string_list;
}
// Doesn't exist, so create it
@@ -2368,6 +2446,7 @@ void set_string(World *mzx_world, char *name, char *value, int id)
String *sdest;
int next;
int size, offset;
+
get_string_size_offset(name, &size, &offset);
if(strlen(name) > 14)
@@ -2521,7 +2600,6 @@ char *set_function_string(World *mzx_world, char *name, int id, char *buffer)
char *get_string(World *mzx_world, char *name, int id, char *buffer)
{
String *sdest;
- int count;
int next;
int size, offset;
@@ -2581,7 +2659,6 @@ void inc_counter(World *mzx_world, char *name, int value, int id)
void inc_string(World *mzx_world, char *name, char *value, int id)
{
String *sdest;
- int current_value;
int next;
value[63] = 0;
@@ -2652,7 +2729,6 @@ void dec_counter(World *mzx_world, char *name, int value, int id)
void dec_string_int(World *mzx_world, char *name, int value, int id)
{
String *sdest;
- int current_value;
int next;
sdest = find_string(mzx_world, name, &next);
@@ -2812,7 +2888,7 @@ void load_string_board(World *mzx_world, char *expression,
set_string(mzx_world, expression, t_buf, id);
}
-int translate_coordinates(char *src, int *x, int *y)
+int translate_coordinates(char *src, unsigned int *x, unsigned int *y)
{
char *next;
@@ -2850,3 +2926,4 @@ int is_string(char *buffer)
}
return 0;
}
+
View
2 counter.h
@@ -99,7 +99,7 @@ void load_string_board(World *mzx_world, char *expression,
int w, int h, char l, char *src, int width, int id);
int set_counter_special(World *mzx_world, int spec_type,
char *char_value, int value, int id);
-int translate_coordinates(char *src, int *x, int *y);
+int translate_coordinates(char *src, unsigned int *x, unsigned int *y);
int is_string(char *buffer);
void get_string_size_offset(char *name, int *ssize, int *soffset);
View
40 counter_first_letter.h
@@ -0,0 +1,40 @@
+int counter_first_letter[512] =
+{
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , 4 ,
+ 5 , 14 , 15 , 18 , 19 , 22 , -1 , -1 , 23 , 32 , 33 , 33 , 34 , 34 ,
+ 35 , 37 , -1 , -1 , 38 , 41 , 42 , 47 , 48 , 54 , -1 , -1 , 55 , 57 ,
+ 58 , 63 , -1 , -1 , 64 , 68 , 69 , 105, 106, 114, -1 , -1 , 115, 119,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
+ -1 , -1 , -1 , -1 , -1 , -1 , 120, 128
+};
View
4 counter_list.txt
@@ -78,8 +78,8 @@ name r/w g/n/f/b i
"PLAYERDIST" r b *
"PLAYERFACEDIR" r w b *
"PLAYERLASTDIR" r w b *
-"PLAYER_X" r b *
-"PLAYER_Y r b *
+"PLAYERX" r b *
+"PLAYERY" r b *
"RED_VALUE" r w b *
"RID<robot name>" r b *
"ROBOT_ID_<robot name>" r b *
View
451 edit.cpp
@@ -122,7 +122,6 @@ Backspace: Delete (move left one in text)
overlay = src_board->overlay; \
overlay_color = src_board->overlay_color; \
clear_screen_no_update(177, 1); \
- draw_mode = 0 \
#define fix_scroll() \
if(cursor_board_x >= board_width) \
@@ -416,72 +415,74 @@ int place_current_at_xy(World *mzx_world, int id, int color, int param,
if(!overlay_edit)
{
- if(old_id != 127)
- {
- if(id == 127)
- {
- id_remove_top(mzx_world, mzx_world->player_x, mzx_world->player_y);
- mzx_world->player_x = x;
- mzx_world->player_y = y;
- }
- else
-
- if((id == 123) || (id == 124))
- {
- if((old_id == 123) || (old_id == 124))
- {
- int old_param = src_board->level_param[offset];
- replace_robot(src_board, copy_robot, old_param);
- src_board->level_color[offset] = color;
- return old_param;
- }
-
- param = duplicate_robot(src_board, copy_robot, x, y);
- if(param != -1)
- {
- (src_board->robot_list[param])->xpos = x;
- (src_board->robot_list[param])->ypos = y;
- (src_board->robot_list[param])->used = 1;
- }
- }
- else
-
- if((id == 125) || (id == 126))
- {
- if((old_id == 125) || (old_id == 126))
- {
- int old_param = src_board->level_param[offset];
- replace_scroll(src_board, copy_scroll, old_param);
- src_board->level_color[offset] = color;
- return old_param;
- }
-
- param = duplicate_scroll(src_board, copy_scroll);
- if(param != -1)
- (src_board->scroll_list[param])->used = 1;
- }
- else
-
- if(id == 122)
- {
- if((old_id == 123) || (old_id == 124))
- {
- int old_param = src_board->level_param[offset];
- replace_sensor(src_board, copy_sensor, old_param);
- src_board->level_color[offset] = color;
- return old_param;
- }
-
- param = duplicate_sensor(src_board, copy_sensor);
- if(param != -1)
- (src_board->sensor_list[param])->used = 1;
- }
-
- if(param != -1)
- {
- place_at_xy(mzx_world, id, color, param, x, y);
- }
- }
+ if(old_id != 127)
+ {
+ if(id == 127)
+ {
+ id_remove_top(mzx_world, mzx_world->player_x, mzx_world->player_y);
+ mzx_world->player_x = x;
+ mzx_world->player_y = y;
+ }
+ else
+
+ if((id == 123) || (id == 124))
+ {
+ if((old_id == 123) || (old_id == 124))
+ {
+ int old_param = src_board->level_param[offset];
+ replace_robot(src_board, copy_robot, old_param);
+ src_board->level_color[offset] = color;
+ src_board->level_id[offset] = id;
+ return old_param;
+ }
+
+ param = duplicate_robot(src_board, copy_robot, x, y);
+ if(param != -1)
+ {
+ (src_board->robot_list[param])->xpos = x;
+ (src_board->robot_list[param])->ypos = y;
+ (src_board->robot_list[param])->used = 1;
+ }
+ }
+ else
+
+ if((id == 125) || (id == 126))
+ {
+ if((old_id == 125) || (old_id == 126))
+ {
+ int old_param = src_board->level_param[offset];
+ replace_scroll(src_board, copy_scroll, old_param);
+ src_board->level_color[offset] = color;
+ src_board->level_id[offset] = id;
+ return old_param;
+ }
+
+ param = duplicate_scroll(src_board, copy_scroll);
+ if(param != -1)
+ (src_board->scroll_list[param])->used = 1;
+ }
+ else
+
+ if(id == 122)
+ {
+ if((old_id == 123) || (old_id == 124))
+ {
+ int old_param = src_board->level_param[offset];
+ replace_sensor(src_board, copy_sensor, old_param);
+ src_board->level_color[offset] = color;
+ return old_param;
+ }
+
+ param = duplicate_sensor(src_board, copy_sensor);
+ if(param != -1)
+ (src_board->sensor_list[param])->used = 1;
+ }
+
+ if(param != -1)
+ {
+ place_at_xy(mzx_world, id, color, param, x, y);
+ }
+ }
}
else
{
@@ -561,8 +562,6 @@ void thing_menu(World *mzx_world, int menu_number, int *new_id,
int id, color, param;
int chosen;
int old_id = *new_id;
- Board *src_board = mzx_world->current_board;
- int at_id = src_board->level_id[x + (y * src_board->board_width)];
cursor_off();
chosen =
@@ -617,7 +616,6 @@ void thing_menu(World *mzx_world, int menu_number, int *new_id,
*new_param = param;
*new_color = color;
}
- cursor_solid();
}
void flash_thing(World *mzx_world, int start, int end, int flash_one,
@@ -663,8 +661,6 @@ void flash_thing(World *mzx_world, int start, int end, int flash_one,
{
id_chars[i2] = backup[i];
}
-
- cursor_solid();
}
void edit_world(World *mzx_world)
@@ -688,11 +684,12 @@ void edit_world(World *mzx_world)
int current_menu = 0;
int show_level = 1;
int display_next_pos;
- int block_x, block_y;
- int block_dest_x, block_dest_y;
- int block_command;
+ int block_x = -1, block_y = -1;
+ int block_dest_x = -1, block_dest_y = -1;
+ int block_command = -1;
+ Board *block_board = NULL;
int text_place;
- int text_start_x;
+ int text_start_x = -1;
int modified = 0;
int debug_x = 60;
int saved_overlay_mode;
@@ -715,7 +712,7 @@ void edit_world(World *mzx_world)
mzx_world->version = VERSION;
- set_palette_intensity(100);
+ set_palette_intensity(100);
if(mzx_world->active)
{
@@ -726,7 +723,6 @@ void edit_world(World *mzx_world)
create_blank_world(mzx_world);
set_update_done(mzx_world);
- cursor_solid();
m_show();
end_mod();
@@ -750,6 +746,7 @@ void edit_world(World *mzx_world)
current_color = 7;
}
+ cursor_solid();
move_cursor(cursor_x, cursor_y);
saved_overlay_mode = src_board->overlay_mode;
@@ -952,7 +949,7 @@ void edit_world(World *mzx_world)
int mouse_x, mouse_y;
get_mouse_position(&mouse_x, &mouse_y);
- if(mouse_y == 20)
+ if((mouse_y == 20) && (edit_screen_height < 20))
{
if((mouse_x >= 1) && (mouse_x <= 41))
{
@@ -967,7 +964,6 @@ void edit_world(World *mzx_world)
new_color = color_selection(current_color, 0);
if(new_color >= 0)
current_color = new_color;
-
}
}
else
@@ -977,7 +973,7 @@ void edit_world(World *mzx_world)
cursor_board_x = mouse_x + scroll_x;
cursor_board_y = mouse_y + scroll_y;
- fix_scroll();
+ fix_scroll();
if(get_mouse_status() == SDL_BUTTON(3))
{
@@ -1090,10 +1086,10 @@ void edit_world(World *mzx_world)
}
if((cursor_board_x - scroll_x) < (debug_x + 25))
- {
+ {
debug_x = 60;
clear_screen_no_update(177, 1);
- }
+ }
break;
}
@@ -1129,10 +1125,10 @@ void edit_world(World *mzx_world)
}
if((cursor_board_x - scroll_x) > (debug_x - 5))
- {
+ {
debug_x = 0;
clear_screen_no_update(177, 1);
- }
+ }
break;
}
@@ -1155,20 +1151,20 @@ void edit_world(World *mzx_world)
else
{
int offset = cursor_board_x + (cursor_board_y * board_width);
- int place_id = current_id;
- int place_param = current_param;
- int place_color = current_color;
- if((!overlay_edit) && (place_id == level_id[offset]) &&
- (place_color == level_color[offset]))
+ if((!overlay_edit) && (current_id == level_id[offset]) &&
+ (current_color == level_color[offset]))
{
- place_id = 0;
- place_color = 7;
+ place_current_at_xy(mzx_world, 0, 7, 0, cursor_board_x,
+ cursor_board_y, &copy_robot, &copy_scroll, &copy_sensor,
+ overlay_edit);
+ }
+ else
+ {
+ current_param = place_current_at_xy(mzx_world, current_id,
+ current_color, current_param, cursor_board_x, cursor_board_y,
+ &copy_robot, &copy_scroll, &copy_sensor, overlay_edit);
}
-
- current_param = place_current_at_xy(mzx_world, place_id,
- place_color, place_param, cursor_board_x, cursor_board_y,
- &copy_robot, &copy_scroll, &copy_sensor, overlay_edit);
}
modified = 1;
break;
@@ -1231,9 +1227,18 @@ void edit_world(World *mzx_world)
}
else
{
- place_current_at_xy(mzx_world, 0, 7, 0, cursor_board_x,
- cursor_board_y, &copy_robot, &copy_scroll, &copy_sensor,
- overlay_edit);
+ if(overlay_edit)
+ {
+ place_current_at_xy(mzx_world, 0, 7, 32, cursor_board_x,
+ cursor_board_y, &copy_robot, &copy_scroll, &copy_sensor,
+ overlay_edit);
+ }
+ else
+ {
+ place_current_at_xy(mzx_world, 0, 7, 0, cursor_board_x,
+ cursor_board_y, &copy_robot, &copy_scroll, &copy_sensor,
+ overlay_edit);
+ }
}
modified = 1;
break;
@@ -1273,15 +1278,15 @@ void edit_world(World *mzx_world)
}
else
{
- if(draw_mode != 2)
- {
- draw_mode = 2;
- text_start_x = cursor_board_x;
- }
- else
- {
- draw_mode = 0;
- }
+ if(draw_mode != 2)
+ {
+ draw_mode = 2;
+ text_start_x = cursor_board_x;
+ }
+ else
+ {
+ draw_mode = 0;
+ }
}
break;
}
@@ -1428,7 +1433,6 @@ void edit_world(World *mzx_world)
if(new_color >= 0)
current_color = new_color;
}
- cursor_solid();
}
else
{
@@ -1487,7 +1491,6 @@ void edit_world(World *mzx_world)
{
status_counter_info(mzx_world);
modified = 1;
- cursor_solid();
}
}
else
@@ -1513,7 +1516,6 @@ void edit_world(World *mzx_world)
modified = 0;
}
- cursor_solid();
}
}
else
@@ -1564,7 +1566,6 @@ void edit_world(World *mzx_world)
int new_board =
choose_board(mzx_world, mzx_world->current_board_id,
"Select current board:", 0);
- cursor_solid();
if(new_board >= 0)
{
@@ -1577,10 +1578,10 @@ void edit_world(World *mzx_world)
fix_mod();
}
- find_player(mzx_world);
+ find_player(mzx_world);
- if(!src_board->overlay_mode)
- overlay_edit = 0;
+ if(!src_board->overlay_mode)
+ overlay_edit = 0;
fix_scroll();
modified = 1;
@@ -1605,7 +1606,6 @@ void edit_world(World *mzx_world)
{
play_sample(428, test_wav);
}
- cursor_solid();
}
else
@@ -1620,19 +1620,22 @@ void edit_world(World *mzx_world)
// Load world curr_file
end_mod();
reload_world(mzx_world, current_world, &fade);
+
+ if(draw_mode > 3)
+ draw_mode = 0;
+
insta_fadein();
synchronize_board_values();
fix_mod();
fix_scroll();
- find_player(mzx_world);
- if(!src_board->overlay_mode)
- overlay_edit = 0;
+ find_player(mzx_world);
+ if(!src_board->overlay_mode)
+ overlay_edit = 0;
modified = 0;
}
}
- cursor_solid();
}
else
{
@@ -1659,6 +1662,8 @@ void edit_world(World *mzx_world)
{
replace_current_board(mzx_world, import_name);
synchronize_board_values();
+ find_player(mzx_world);
+
if(strcmp(src_board->mod_playing, "*") &&
strcasecmp(src_board->mod_playing, mzx_world->real_mod_playing))
{
@@ -1742,7 +1747,6 @@ void edit_world(World *mzx_world)
break;
}
}
- cursor_solid();
}
}
else
@@ -1754,11 +1758,10 @@ void edit_world(World *mzx_world)
if(mzx_world->current_board_id == 0)
strcpy(mzx_world->name, src_board->board_name);
- if(!src_board->overlay_mode)
- overlay_edit = 0;
+ if(!src_board->overlay_mode)
+ overlay_edit = 0;
modified = 1;
- cursor_solid();
}
else
{
@@ -1773,7 +1776,6 @@ void edit_world(World *mzx_world)
{
global_info(mzx_world);
modified = 1;
- cursor_solid();
}
else
{
@@ -1793,29 +1795,30 @@ void edit_world(World *mzx_world)
synchronize_board_values();
fix_scroll();
+ if(draw_mode > 3)
+ draw_mode = 0;
+
// Uh oh, we might need a new player
if((mzx_world->player_x >= board_width) ||
((mzx_world->player_y) >= board_height))
replace_player(mzx_world);
modified = 1;
- cursor_solid();
}
else
if(!overlay_edit)
{
int offset = cursor_board_x + (cursor_board_y * board_width);
int d_id = level_id[offset];
-
+
if(d_id < 122)
{
int d_param = level_param[offset];
d_param = change_param(mzx_world, d_id, d_param, NULL, NULL, NULL);
- level_param[offset] = d_param;
+ level_param[offset] = d_param;
modified = 1;
}
- cursor_solid();
}
}
else
@@ -1897,15 +1900,13 @@ void edit_world(World *mzx_world)
}
}
}
- cursor_solid();
}
else
if(draw_mode != 2)
{
board_exits(mzx_world);
modified = 1;
- cursor_solid();
}
else
{
@@ -1930,7 +1931,6 @@ void edit_world(World *mzx_world)
strcpy(src_board->mod_playing, new_mod);
strcpy(mzx_world->real_mod_playing, new_mod);
}
- cursor_solid();
}
else
{
@@ -1948,7 +1948,7 @@ void edit_world(World *mzx_world)
break;
}
- case SDLK_KP_ENTER:
+ case SDLK_KP_ENTER:
case SDLK_RETURN:
{
if(draw_mode == 3)
@@ -1957,6 +1957,8 @@ void edit_world(World *mzx_world)
int start_y = block_y;
int block_width, block_height;
+ block_board = src_board;
+
if(start_x > cursor_board_x)
{
start_x = cursor_board_x;
@@ -1981,7 +1983,6 @@ void edit_world(World *mzx_world)
block_command = block_cmd(mzx_world);
block_dest_x = cursor_board_x;
block_dest_y = cursor_board_y;
- cursor_solid();
// Some block commands are done automatically
switch(block_command)
@@ -2022,7 +2023,7 @@ void edit_world(World *mzx_world)
case 4:
{
// Flip block
- char *temp_buffer = (char *)malloc(board_width);
+ char temp_buffer[board_width];
int start_offset = start_x + (start_y * board_width);
int end_offset = start_x + ((start_y + block_height - 1) * board_width);
@@ -2206,26 +2207,15 @@ void edit_world(World *mzx_world)
case 8:
{
// Save as MZM
- char *mzm_ext[] = { ".MZM", NULL };
-
mzm_name_buffer[0] = 0;
if(!save_file_dialog(mzx_world, "Export", "Save as: ", mzm_name_buffer))
{
- add_ext(mzm_name_buffer, ".mzm");
- if(overlay_edit)
- {
- save_mzm(mzx_world, mzm_name_buffer, start_x, start_y,
- block_width, block_height, 1, 1);
- }
- else
- {
- save_mzm(mzx_world, mzm_name_buffer, start_x, start_y,
- block_width, block_height, 0, 0);
- }
+ add_ext(mzm_name_buffer, ".mzm");
+ save_mzm(mzx_world, mzm_name_buffer, start_x, start_y,
+ block_width, block_height, overlay_edit, 0);
}
modified = 1;
- cursor_solid();
draw_mode = 0;
break;
}
@@ -2308,12 +2298,12 @@ void edit_world(World *mzx_world)
{
block_height = block_dest_y - block_y + 1;
}
-
- if((dest_x + block_width) > board_width)
- block_width = board_width - dest_x;
+
+ if((dest_x + block_width) > board_width)
+ block_width = board_width - dest_x;
- if((dest_y + block_height) > board_height)
- block_height = board_height - dest_y;
+ if((dest_y + block_height) > board_height)
+ block_height = board_height - dest_y;
draw_mode = 0;
@@ -2323,16 +2313,14 @@ void edit_world(World *mzx_world)
case 1:
{
// Copy block
- char *char_buffer = (char *)malloc(block_width * block_height);
- char *color_buffer = (char *)malloc(block_width * block_height);
+ char char_buffer[block_width * block_height];
+ char color_buffer[block_width * block_height];
copy_layer_to_buffer(start_x, start_y, block_width,
- block_height, overlay, overlay_color, char_buffer,
- color_buffer, board_width);
+ block_height, block_board->overlay, block_board->overlay_color,
+ char_buffer, color_buffer, block_board->board_width);
copy_buffer_to_layer(dest_x, dest_y, block_width,
block_height, char_buffer, color_buffer, overlay,
overlay_color, board_width);
- free(char_buffer);
- free(color_buffer);
// 1 is repeat copy
if(block_command == 1)
@@ -2348,27 +2336,27 @@ void edit_world(World *mzx_world)
case 2:
{
// Move block
- char *char_buffer = (char *)malloc(block_width * block_height);
- char *color_buffer = (char *)malloc(block_width * block_height);
+ char char_buffer[block_width * block_height];
+ char color_buffer[block_width * block_height];
copy_layer_to_buffer(start_x, start_y, block_width,
- block_height, overlay, overlay_color, char_buffer,
- color_buffer, board_width);
+ block_height, block_board->overlay, block_board->overlay_color,
+ char_buffer, color_buffer, block_board->board_width);
clear_layer_block(start_x, start_y, block_width,
- block_height, overlay, overlay_color, board_width);
+ block_height, block_board->overlay, block_board->overlay_color,
+ block_board->board_width);
copy_buffer_to_layer(dest_x, dest_y, block_width,
block_height, char_buffer, color_buffer, overlay,
overlay_color, board_width);
- free(char_buffer);
- free(color_buffer);
+
modified = 1;
break;
}
case 7:
{
- // Copy from overlay
+ // Copy from board
int overlay_offset = dest_x + (dest_y * board_width);
- copy_board_to_layer(src_board, start_x, start_y, block_width,
+ copy_board_to_layer(block_board, start_x, start_y, block_width,
block_height, overlay + overlay_offset,
overlay_color + overlay_offset, board_width);
modified = 1;
@@ -2378,7 +2366,7 @@ void edit_world(World *mzx_world)
case 9:
{
// Load MZM
- load_mzm(mzx_world, mzm_name_buffer, dest_x, dest_y, 1);
+ load_mzm(mzx_world, mzm_name_buffer, dest_x, dest_y, 1, 0);
modified = 1;
break;
}
@@ -2392,7 +2380,6 @@ void edit_world(World *mzx_world)
current_param = new_param;
modified = 1;
}
- cursor_solid();
}
}
else
@@ -2425,11 +2412,11 @@ void edit_world(World *mzx_world)
block_height = block_dest_y - block_y + 1;
}
- if((dest_x + block_width) > board_width)
- block_width = board_width - dest_x;
+ if((dest_x + block_width) > board_width)
+ block_width = board_width - dest_x;
- if((dest_y + block_height) > board_height)
- block_height = board_height - dest_y;
+ if((dest_y + block_height) > board_height)
+ block_height = board_height - dest_y;
draw_mode = 0;
@@ -2440,26 +2427,20 @@ void edit_world(World *mzx_world)
{
// Copy block
int block_size = block_width * block_height;
- char *id_buffer = (char *)malloc(block_size);
- char *param_buffer = (char *)malloc(block_size);
- char *color_buffer = (char *)malloc(block_size);
- char *under_id_buffer = (char *)malloc(block_size);
- char *under_param_buffer = (char *)malloc(block_size);
- char *under_color_buffer = (char *)malloc(block_size);
- copy_board_to_board_buffer(src_board, start_x, start_y,
+ char id_buffer[block_size];
+ char param_buffer[block_size];
+ char color_buffer[block_size];
+ char under_id_buffer[block_size];
+ char under_param_buffer[block_size];
+ char under_color_buffer[block_size];
+ copy_board_to_board_buffer(block_board, start_x, start_y,
block_width, block_height, id_buffer, param_buffer,
color_buffer, under_id_buffer, under_param_buffer,
- under_color_buffer);
+ under_color_buffer, src_board);
copy_board_buffer_to_board(src_board, dest_x, dest_y,
block_width, block_height, id_buffer, param_buffer,
color_buffer, under_id_buffer, under_param_buffer,
under_color_buffer);
- free(id_buffer);
- free(param_buffer);
- free(color_buffer);
- free(under_id_buffer);
- free(under_param_buffer);
- free(under_color_buffer);
// 1 is repeat copy
if(block_command == 1)
@@ -2477,36 +2458,30 @@ void edit_world(World *mzx_world)
{
// Move block
int block_size = block_width * block_height;
- char *id_buffer = (char *)malloc(block_size);
- char *param_buffer = (char *)malloc(block_size);
- char *color_buffer = (char *)malloc(block_size);
- char *under_id_buffer = (char *)malloc(block_size);
- char *under_param_buffer = (char *)malloc(block_size);
- char *under_color_buffer = (char *)malloc(block_size);
- copy_board_to_board_buffer(src_board, start_x, start_y,
+ char id_buffer[block_size];
+ char param_buffer[block_size];
+ char color_buffer[block_size];
+ char under_id_buffer[block_size];
+ char under_param_buffer[block_size];
+ char under_color_buffer[block_size];
+ copy_board_to_board_buffer(block_board, start_x, start_y,
block_width, block_height, id_buffer, param_buffer,
color_buffer, under_id_buffer, under_param_buffer,
- under_color_buffer);
- clear_board_block(src_board, start_x, start_y,
+ under_color_buffer, src_board);
+ clear_board_block(block_board, start_x, start_y,
block_width, block_height);
copy_board_buffer_to_board(src_board, dest_x, dest_y,
block_width, block_height, id_buffer, param_buffer,
color_buffer, under_id_buffer, under_param_buffer,
under_color_buffer);
- free(id_buffer);
- free(param_buffer);
- free(color_buffer);
- free(under_id_buffer);
- free(under_param_buffer);
- free(under_color_buffer);
modified = 1;
break;
}
case 7:
{
- // Copy from board
+ // Copy from overlay
int layer_convert = rtoo_obj_type(mzx_world);
switch(layer_convert)
@@ -2535,10 +2510,12 @@ void edit_world(World *mzx_world)
if(layer_convert != -1)
{
- int overlay_offset = start_x + (start_y * board_width);
+ int overlay_offset = start_x +
+ (start_y * block_board->board_width);
copy_layer_to_board(src_board, dest_x, dest_y, block_width,
- block_height, overlay + overlay_offset,
- overlay_color + overlay_offset, board_width, layer_convert);
+ block_height, block_board->overlay + overlay_offset,
+ block_board->overlay_color + overlay_offset,
+ block_board->board_width, layer_convert);
modified = 1;
}
@@ -2548,7 +2525,7 @@ void edit_world(World *mzx_world)
case 9:
{
// Load MZM
- load_mzm(mzx_world, mzm_name_buffer, dest_x, dest_y, 0);
+ load_mzm(mzx_world, mzm_name_buffer, dest_x, dest_y, 0, 0);
modified = 1;
break;
}
@@ -2570,7 +2547,6 @@ void edit_world(World *mzx_world)
modified = 1;
}
- cursor_solid();
}
break;
@@ -2591,7 +2567,6 @@ void edit_world(World *mzx_world)
{
palette_editor(mzx_world);
modified = 1;
- cursor_solid();
}
}
else
@@ -2610,7 +2585,6 @@ void edit_world(World *mzx_world)
{
sfx_edit(mzx_world);
modified = 1;
- cursor_solid();
}
else
{
@@ -2653,7 +2627,6 @@ void edit_world(World *mzx_world)
confirm(mzx_world, "Exit: World has not been saved, are you sure?"))
{
key = 0;
- cursor_solid();
}
break;
}
@@ -2712,7 +2685,6 @@ void edit_world(World *mzx_world)
} while(v_key != SDLK_ESCAPE);
clear_screen_no_update(177, 1);
- cursor_solid();
}
else
{
@@ -2726,7 +2698,6 @@ void edit_world(World *mzx_world)
{
int fade;
int current_board_id = mzx_world->current_board_id;
- char tempfile_name[128];
save_world(mzx_world, "__test.mzx", 0, 0);
@@ -2742,18 +2713,20 @@ void edit_world(World *mzx_world)
mzx_world->player_restart_y = mzx_world->player_y;