Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    6

    Lightbulb Bug fixes for Evil Monkeys VTM5 - fireball issues

    Hi all,

    I'm not sure if this has been discussed previously, however I discovered a couple of bugs in the way fireballs are processed and have come up with a solution.

    I noticed that in the VTM code the fireballs initially render two tiles away from the player, and enemies are not being killed unless they are at least three tiles away. This happens because of two issues, both in Mage::castSpell():
    1. A fireball is constructed by passing in pos.x + facingdirection.x and pos.y + facing_direction.y . This is fine, but then a call is made to temp->move() whereby it moves the fireball again by making a call to isValidLevelMove(). This is resolved by removing the if..else.. code and retaining it's contents.

    1. When the fireball is constructed it is added to the npc list in the level class and is not processed again until it reaches it's initial update interval (see code in Level::update()). In the meantime every enemy will have reached it's update interval and therefore will have had an opportunity to move, meaning that an enemy standing right next to the player that should be engulfed in a fiery blaze gets away without so much as a scratch. To get around this we can simply introduce an iterator straight after instatiating a fireball, get it to find any enemy that is standing in it's square, and then kill the enemy.


    I have included the code for the below:

    Code:
    		// Old code
    		//if (temp->move(facing_direction.x, facing_direction.y))
    		//{
    		//	temp->update();
    		//	level->addNPC((Sprite *)temp);
    		//}
    		//else
    		//{
    		//	update();
    		//}
    
    		// New code
    		list <Sprite *>::iterator iter;
    
    		for (iter = level->npc.begin(); iter != level->npc.end(); iter++)
    		{
    			if (((*iter)->classID != FIREBALL_CLASSID) &&
    				((int)(*iter)->getX() == (int)pos.x + (int)facing_direction.x) &&
    				((int)(*iter)->getY() == (int)pos.y + (int)facing_direction.y))
    			{
    				(*iter)->addLives(-1);
    				return;
    			}
    		}
    
    		temp->update();
    		level->addNPC((Sprite *)temp);
    		update();
    I hope this helps anyone out for whom this has been bugging (excuse the pun). Please feel free to make any comments.
    Last edited by tashycat; 11-02-2012 at 10:27 AM. Reason: Typos

  2. #2
    Join Date
    Oct 2005
    Location
    Denmark
    Posts
    102

    Red face And another fix

    I have 2 other bug fix as well for the fireball.
    Actually it's only one, since the above code fixes the first bug, but I'll post it here anyway so people understand why it might crash without the above code.

    1. When at and facing the outer walls and cast a fireball the game crashes. This was due to the above post about the fireball spawned 2 tiles away instead of 1, which caused the fireball to spawn on the other side of the wall, outside the game level, which crashed the game since it was outside the map and the pos x and y were not valid positions anymore.
    2. This is after the fix above. When at and facing the outer walls and cast a fireball, the fireball draws on top of the wall and stays there and never get cleared. The code below fixes this problem by checking if the create fireball spot is a valid level move.

    Code:
      if (facingDirection.y < -1 && facingDirection.y < -1)
        return;
    
      // Fix for fireball spawns on walls. Must be added before the new fireball is created.
      //------------------------------------------------------------------------------
      if (!isValidLevelMove((int)pos.x + facingDirection.x, (int)pos.y + facingDirection.y))
        return;
      //------------------------------------------------------------------------------
    
      Fireball *temp = new Fireball(level, drawArea, SPRITE_FIREBALL,
        (int)pos.x + facingDirection.x, (int)pos.y + facingDirection.y,
        facingDirection.x, facingDirection.y);
    Hope it helps people

    Kind regards
    Satis
    //Satis

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •