Difference between revisions of "Ikari Warriors (NES)/Fuel drop manipulation"

From SDA Knowledge Base

Jump to: navigation, search
(Part 1 - index of the helicopter)
(Area 4 fuel drop)
Line 117: Line 117:
  
 
==Area 4 fuel drop==
 
==Area 4 fuel drop==
 +
The objective here is to get one of the "garbage sprites" around the helicopter to drop a fuel. This occurs when the drop value of its index is 20. If you enter this section with at least one drop value of 20, the fuel will usually drop pretty quickly without problems. So the issue is to figure out a way for how to get to that section without all the 20ies having been overwritten. Let's take a look at the map with some relevant objects indicated:<br />
 +
[[File:Ikari1 4 fuel manip.JPG]]<br /><br />
 +
 +
Let's start from the bottom. When a new barrel appears on screen, it overwrites the previous drop value to a random (?) value. When shooting a barrel that contains a fuel, its drop value will always turn to 20. However, it's only the last fuel barrels (#1, #2 and #3) that are of interest, since the drop values from the first barrels will be overwritten regardless. So the barrel section is about filling the drop value addresses with 20ies. The path from the barrel section to the helicopter is then to keep at least one 20 in memory. It doesn't seem to be possible to get 20 back in memory around the helicopter, so this is where it gets a bit tricky. #5 (both the red soldier and the turret), #6, #7, #8, #9, #10 and the helicopter will all overwrite the drop value of their respective index...<br /><br />
 +
 +
To understand the difference between a good and a bad route, we will look at two examples. One speedrun route that turns out to be counterproductive with respect to the fuel drop and one route that aims to instead optimize the chances of the fuel drop.<br /><br />
 +
 +
<u>Speedrun route</u><br />
 +
[[File:Ikari Warriors (U)-4 Fuel fail.zip]]
 +
<br /><br />
 +
 +
<u>Fuel-optimized route</u><br />
 +
[[File:Ikari Warriors (U)-4 Fuel manip.zip]]

Revision as of 16:06, 28 March 2017

This page goes more in depth on how to manipulate fuel drops for the helicopters in areas 3 and 4. The RAM-addresses used here are listed in the memory address section.

Some background about object allocation in the RAM

All objects that aren't part of the background are allocated to RAM-address $500 and onwards (player 1 is always in $4FE and player 2 is always in $4FF, but they can be disregarded here since they don't interfere with the foreign objects). This includes enemies, destroyable structures, hidden items, mines etc and even bullets. These addresses are referred to as "object addresses". The object address with index 0 corresponds to $500, index 1 corresponds to $501 etc. A new object entering the screen will be allocated to the lowest available index. If two objects enter the screen at the same frame, the object to the left will first be attributed the object address and will therefore always have the lower index. When an object leaves the screen (regardless of how), the corresponding index will be restored to null. Dropped objects will retain the address of the initial object though. Bullets are also an exception as they will be allocated to an index further down (without interest for the topics of this page).

Different objects provide different values to the object addresses. Some objects share the same value, so there must be additional addresses that determine the exact type of object. However, these values aren't overly important to know, but are helpful when analyzing emulator movie files. Below are some common values (but the list is nowhere near complete):

Object address value Description
(128) Player moving forward
(120) Player in tank/heli
(64) Rail turret, drops, mine
(63) Exploding rail turret
(62) Soldier, heli, blinking object
(61) Dying soldier, exploding barrel
(58) Returning soldier, missile target plate
(54) Guardian soldier
(53) Dying soldier (alternating with 75)
(50) Missile target plate with incoming airstrike
(45) Dying kamikaze (alternating with 83)
2 Helicopter/tank in use
64 Unrevealed mine
66 Object not on screen (includes unrevealed hidden items and destroyable structures with drops)
75 Dying soldier (alternating with -53)
83 Dying kamikaze (alternating with -53)

The type of drop is determined by the value of the object's "drop address". The drop addresses start with $0676. When the object leaves the screen, the drop address isn't reset to null, like the object address. When an object is allocated to an object address, its "drop address" can be overwritten with the object's corresponding drop value. This drop value is overwritten for most objects (including many objects that don't drop anything), but for example blue soldiers don't overwrite the drop values. The only drop value of interest is 20, which means fuel will be dropped.

Area 3 fuel drop

This section will explain how to increase the chances of getting a fuel drop from the first tank in the helicopter section.

The tank drops in this game are determined by the index the tank is allocated to. If the tank is in index 0 (= $500), it will drop a tank and if it's in index 2 (= $502), it will drop a fuel. All other index will result in no drop. The goal of this manipulation is therefore to maximize the chances of the tank spawning in index 2. This can be broken down in two parts. One part leading up to the fuel drop and one part ensuring the helicopter isn't blocking the relevant index. It's easiest to understand the route by starting with the fuel drop itself and then retracing the steps while trying to keep the drop conditions.

Part 2 - getting the tank in index 2

Ikari Warriors (U)-3 fuel manip.JPG

With reference to the numbering in the screenshot above, we can see that the tank will be allocated to index 2 if, and only if, index 0 and 1 are unoccupied when #1 and #2 appear on screen. This is only true if #3-#5 get index >2 and the objects occupying index 0-2 at that point disappear before the mines appear. There are 4 enemies (the three in #6 + one underwater enemy not shown in the screenshot) and #7 that are always present and can help achieve this condition. If index 0-2 are occupied among these 5 objects and they despawn between the gates and the mines, the tank will get index 2. #7 will disappear after #3-#5 have spawned, but before #1 and #2, so that's never an issue. Fortunately, the four enemies can also be taken out so they despawn according to this condition.

File:Ikari Warriors (U)-3 fuel manip.zip
The fm2-movie in the file above shows a successful fuel drop. The lua script (in the format [object value, index], while following the x-position of the object on screen) and the wch-file both contain the object addresses to make it easier to follow the address allocations. Other than illustrating the description above, it's also worth mentioning the role of #8. If the knife gets an index in the range 0 to 2 (which is not feasible to know in real-time) and is not collected, the leftmost gate (#3) will inherit its index, which means the fuel drop will not be possible. If it's collected, one of the enemy soldiers will inherit its index. #8 should therefore always be collected, no matter what.

File:Ikari Warriors (U)-3 fuel fail.zip
This fm2-movie illustrates some of the things that can go wrong and prevent the fuel drop. Assuming the execution was correct, there are three types of occurrences that will cause problems:

  1. There is a fifth enemy soldier around #6 in the screenshot above.
  2. The underwater kamikaze that comes from the left side and starts following you.
  3. An enemy soldier is running on the right and manages to stay on screen until the group in #6 spawns.

The first case is not possible to work around. All you can do is hope that it didn't get one of the lower index (but they often do since they tend to spawn earlier than the group in #6).
The second case is shown in this movie, but the threat is avoided by barely managing to scroll it off screen before the group at #6 spawned. This enemy doesn't always appear because of sprite limitation, which is an advantage. However, if you collect the heart (like shown in this movie), an index will be released, which increases the chances of spawning this enemy. Avoiding the heart will also result in a more direct route and if this enemy still spawns, it will be scrolled off screen faster. For safety, it's therefore better to leave this heart alone.
It's case 3 that was the root cause in this case. Despite being hit, the enemy's dying animation lasted long enough for it to occupy index 0 when the enemies at #6 spawned. This could have been mitigated by pausing before #6 appeared, but that would also have meant that the underwater enemy probably wouldn't have been pushed off screen. Pausing also increases the risk of more spawns in front of you, which is dangerous in this section. Overall, a difficult situation to deal with.

By following the route and suggestions above, the tank will drop fuel very roughly three times out of four.

Part 1 - index of the helicopter

In the part 2 above, nothing has been mentioned about the index of the helicopter itself. The helicopter is treated like any other object and will be dealt an object address according to the same rules. This means that if the helicopter has index 0, 1 or 2, it will be virtually impossible to get a fuel drop later on. This section will describe how to manipulate the helicopter into a higher index.

Let's start by looking at the map of the section in question with all items shown:
Ikari1-3 heli area.jpg

The objects down to the topmost barrel will be on screen when the helicopter appears. So there are 5 non-moving objects that can potentially help keeping the helicopter out of index 0-2. However, there are also blue soldiers creating some randomness by spawning between the barrel section and the helicopter. So the threat comes from either a blue soldier or one of the lower barrels leaving the screen right before the helicopter appears. The helicopter will then inherit a potentially low index. The only realistic variation in terms of routing comes in the barrel section. You can either go to the left, which is faster, or to the right (going straight ahead is not a good option on foot). Let's look at both options.

Left side of the barrel section
The following fm2-movie shows the route through the left side of the barrel section:
File:Ikari Warriors (U)-3 Heli address fail.zip
Similar to the movies above, a lua and a wch-file have been included to make it easier to follow the objects' index. As can be seen from the movie name, it shows a case where the helicopter was allocated to an index in the range 0-2, which will prevent the fuel drop later on. To understand why this happens, let's take a look at the map again, but this time with arrows showing how the index are transferred from one object to the next:
Ikari1-3 heli address fail.jpg

As a first step, we can see that there are roughly three transfer phases. The first phase (green arrows), where unknown index are transferred to the objects around the gate. The second phase (red arrows), where the gate object index are transferred to the barrels. The third and final phase (yellow arrows), where the barrel index are transferred into the objects leading up to the helicopter. Numbers in yellow indicate the number of frames between the two connected objects disappear/appear. If a blue soldier is spawned (rng) in the meantime, it will inherit the index instead. As a general rule, the more arrows and the longer chain leading up to an object, the more likely it is to contain a low index.

In phase one (green arrows), we see that #4 and #5 are likely to inherit low index. Depending on when the red soldier leaves the screen, either #6 or the triple shot will inherit its value (the former is to prefer).

In phase two (red arrows), it's difficult to imagine a case where the left barrel in #2 will have an index higher than 2. There are a few more barrels that are likely to have a low index, but not to the same extent as #2.

In phase three (yellow arrows), we can see the issue with this route. #2 leaves the screen some 24 or so frames before the helicopter appears. If no blue soldier appears in the meantime, it's more or less guaranteed that the helicopter will have an index in the range 0-2, which is what we wanted to avoid in the first place. It can be confirmed in the fm2-movie above that this is indeed what happened.

Right side of the barrel section
Let's start again by the movie demonstrating the route:
File:Ikari Warriors (U)-3 Heli address manip.zip
The first thing to notice is that this route is bit less straight-forward and a little over a second slower than the left side of the barrel section. With the route in mind, let's take a look at the map with the flow of the index inheritance for this route.
Ikari1-3 heli address manip.jpg

The green and red arrows are the same as before, while the yellow arrows have moved a bit. Instead of almost guaranteed giving a low index to the helicopter, the barrels at #2 are now destroyed and will likely feed the triple shot object. With in most cases a steady flow of blue soldiers appearing before the helicopter and a high probability of some of the fixed objects carrying low index, it has now become quite improbable (~10%?) for the helicopter to get an index in the range 0-2. Some final comments:
- By not destroying #1, you'll have another fixed object on screen when the helicopter appears, which increases the chances even more of blocking the index 0-2. However this also introduces some other risks instead as well as a minor time loss from a forced detour when dodging the bullets from #1.
- Leaving or destroying #3 is somewhat a matter of taste. By destroying it, its index will go to #1. By leaving it, there are two chances for the mine getting a low index (and in the ideal case even giving a low index to both mines, although that is pretty unlikely) in case a blue soldier appears right before.

Area 4 fuel drop

The objective here is to get one of the "garbage sprites" around the helicopter to drop a fuel. This occurs when the drop value of its index is 20. If you enter this section with at least one drop value of 20, the fuel will usually drop pretty quickly without problems. So the issue is to figure out a way for how to get to that section without all the 20ies having been overwritten. Let's take a look at the map with some relevant objects indicated:
Ikari1 4 fuel manip.JPG

Let's start from the bottom. When a new barrel appears on screen, it overwrites the previous drop value to a random (?) value. When shooting a barrel that contains a fuel, its drop value will always turn to 20. However, it's only the last fuel barrels (#1, #2 and #3) that are of interest, since the drop values from the first barrels will be overwritten regardless. So the barrel section is about filling the drop value addresses with 20ies. The path from the barrel section to the helicopter is then to keep at least one 20 in memory. It doesn't seem to be possible to get 20 back in memory around the helicopter, so this is where it gets a bit tricky. #5 (both the red soldier and the turret), #6, #7, #8, #9, #10 and the helicopter will all overwrite the drop value of their respective index...

To understand the difference between a good and a bad route, we will look at two examples. One speedrun route that turns out to be counterproductive with respect to the fuel drop and one route that aims to instead optimize the chances of the fuel drop.

Speedrun route
File:Ikari Warriors (U)-4 Fuel fail.zip

Fuel-optimized route
File:Ikari Warriors (U)-4 Fuel manip.zip

Personal tools