[comp.sources.games.bugs] Omega's random character bug

cjs@moncsbruce.oz (Chris Stuart) (08/01/88)

The bug where omega occassionally draws random characters on the terrain
map is in drawplayer(), which is in oscr.c

This function has a coupls of static variables which keep track of the players
last position. They have a sanity check for normal maps, but not the country
side. This will give random characters if (for example) you restore a game
which was saved in the countryside.

The following patch may help: I would also ask the author to have a look
and see if inbounds may be used in the countryside. This patch is a hack
from someone who is not at sure what he is doing, but thinks it looks
better this way.

*** ooldscr.c	Mon Aug  1 23:35:08 1988
--- onewscr.c	Mon Aug  1 23:34:05 1988
***************
*** 371,378
  {
    static int lastx= -1,lasty= -1;
    if (Current_Environment == E_COUNTRYSIDE) {
!     wmove(Levelw,screenmod(lasty),lastx);
!     waddch(Levelw,Country[lastx][lasty].current_terrain_type);
      wmove(Levelw,screenmod(Player.y),Player.x);
      waddch(Levelw,PLAYER);
    }

--- 371,380 -----
  {
    static int lastx= -1,lasty= -1;
    if (Current_Environment == E_COUNTRYSIDE) {
!     if(inbounds(lastx, lasty)){
!       wmove(Levelw,screenmod(lasty),lastx);
!       waddch(Levelw,Country[lastx][lasty].current_terrain_type);
!     }
      wmove(Levelw,screenmod(Player.y),Player.x);
      waddch(Levelw,PLAYER);
    }




Cheers, Christopher Stuart

cjs@moncsbruce.oz (Chris Stuart) (08/01/88)

From article <485@moncsbruce.oz>, by cjs@moncsbruce.oz (Chris Stuart):
>                                                     This patch is a hack
> from someone who is not at sure what he is doing, but thinks it looks
> better this way.

Oops. The patch i posted earlier is not sufficient. I post another better
one, but i also regard this as a temporary hack until Lawrence Brothers
casts his expert eye over the problem and posts the 7.2 bugfixes sometime
in the future. This patch adds a new static variables for tracking the
type of the environment: i won't be a bit surprised if it can be done
better.

*** oscr.orig	Tue Aug  2 00:31:52 1988
--- oscr.new	Tue Aug  2 01:30:29 1988
***************
*** 369,374
  void drawplayer()
  {
    static int lastx= -1,lasty= -1;
    if (Current_Environment == E_COUNTRYSIDE) {
      wmove(Levelw,screenmod(lasty),lastx);
      waddch(Levelw,Country[lastx][lasty].current_terrain_type);

--- 369,375 -----
  void drawplayer()
  {
    static int lastx= -1,lasty= -1;
+   static int lastenv = -1;
    if (Current_Environment == E_COUNTRYSIDE) {
      if(lastenv == Current_Environment){
        wmove(Levelw,screenmod(lasty),lastx);
***************
*** 370,377
  {
    static int lastx= -1,lasty= -1;
    if (Current_Environment == E_COUNTRYSIDE) {
!     wmove(Levelw,screenmod(lasty),lastx);
!     waddch(Levelw,Country[lastx][lasty].current_terrain_type);
      wmove(Levelw,screenmod(Player.y),Player.x);
      waddch(Levelw,PLAYER);
    }

--- 371,380 -----
    static int lastx= -1,lasty= -1;
    static int lastenv = -1;
    if (Current_Environment == E_COUNTRYSIDE) {
!     if(lastenv == Current_Environment){
!       wmove(Levelw,screenmod(lasty),lastx);
!       waddch(Levelw,Country[lastx][lasty].current_terrain_type);
!     }
      wmove(Levelw,screenmod(Player.y),Player.x);
      waddch(Levelw,PLAYER);
    }
***************
*** 384,389
    }
    lastx = Player.x;
    lasty = Player.y;
  }
  
  int litroom(x,y)

--- 387,393 -----
    }
    lastx = Player.x;
    lasty = Player.y;
+   lastenv = Current_Environment;
  }
  
  int litroom(x,y)


I also note that there are serious problems with two handed weapons. In
particular, if you drop one which is in use, you get two copies: the one
dropped from the left hand, and the one retained in the right hand. The
allocated space may also be freed, i think, leading to more problems.
Anyone attempted to patch this should give very careful thought to the
appropriate correctness assertions to be maintained by the code.

Cheers, Christopher Stuart