<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://manicpop.org/gewiki/index.php?action=history&amp;feed=atom&amp;title=Classic_bug%3A_Torpedo_stalls_at_distance_one</id>
	<title>Classic bug: Torpedo stalls at distance one - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://manicpop.org/gewiki/index.php?action=history&amp;feed=atom&amp;title=Classic_bug%3A_Torpedo_stalls_at_distance_one"/>
	<link rel="alternate" type="text/html" href="https://manicpop.org/gewiki/index.php?title=Classic_bug:_Torpedo_stalls_at_distance_one&amp;action=history"/>
	<updated>2026-10-20T16:14:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://manicpop.org/gewiki/index.php?title=Classic_bug:_Torpedo_stalls_at_distance_one&amp;diff=1308&amp;oldid=prev</id>
		<title>CodexBot: Document exact launch-distance and 20-unit-offset conditions for torpedo stall</title>
		<link rel="alternate" type="text/html" href="https://manicpop.org/gewiki/index.php?title=Classic_bug:_Torpedo_stalls_at_distance_one&amp;diff=1308&amp;oldid=prev"/>
		<updated>2026-10-10T20:17:34Z</updated>

		<summary type="html">&lt;p&gt;Document exact launch-distance and 20-unit-offset conditions for torpedo stall&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Classic bug&lt;br /&gt;
|id=GE-BUG-021&lt;br /&gt;
|affected=Classic 3.2e and published classic source&lt;br /&gt;
|status=Verified in source&lt;br /&gt;
|fixed=ge-next 0.2.4&lt;br /&gt;
|source=GECMDS.C: torp(); GEFUNCS.C: checktm()&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
An incoming torpedo can reach a stored remaining distance of exactly 1. Classic then ignores it on every subsequent ship-state update: it never hits, advances, or releases its target&amp;#039;s incoming torpedo slot.&lt;br /&gt;
&lt;br /&gt;
== How the value is reached ==&lt;br /&gt;
On a successful launch, classic measures the separation between the firing ship and its target in distance units, truncates it to an unsigned integer, and adds 20 to the target&amp;#039;s incoming torpedo record:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
wptr-&amp;gt;ltorps[i].distance = (unsigned)(cdistance(&amp;amp;ptr-&amp;gt;coord, &amp;amp;(wptr-&amp;gt;coord)) * 10000);&lt;br /&gt;
wptr-&amp;gt;ltorps[i].distance += 20;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The stock &amp;lt;code&amp;gt;TORPSPED&amp;lt;/code&amp;gt; is 2,441 units per target ship-state update. In &amp;lt;code&amp;gt;checktm()&amp;lt;/code&amp;gt;, a torpedo at or below that speed would hit, but this whole check is enclosed by &amp;lt;code&amp;gt;if (tptr-&amp;gt;distance &amp;gt; 1)&amp;lt;/code&amp;gt;. A torpedo farther away instead has 2,441 subtracted from its stored distance on that update. If the subtraction makes it exactly 1, the next update fails the outer test before it can reach the hit check.&lt;br /&gt;
&lt;br /&gt;
Thus the stuck condition is &amp;lt;code&amp;gt;(truncated launch separation + 20) modulo TORPSPED = 1&amp;lt;/code&amp;gt;, provided the torpedo travels at least one step before reaching 1. Equivalently, with the stock speed, the truncated separation is &amp;lt;code&amp;gt;2,422 + (2,441 × n)&amp;lt;/code&amp;gt; distance units for a nonnegative integer &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, so long as the launch itself is permitted. Since the physical separation is truncated, any separation from 2,422 up to but not including 2,423 units has the first vulnerable integer value. The target&amp;#039;s later impulse movement does not alter this stored countdown.&lt;br /&gt;
&lt;br /&gt;
For the shortest stock-speed example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Measured separation, truncated: 2,422&lt;br /&gt;
Launch offset:                     +20&lt;br /&gt;
Stored at launch:                2,442&lt;br /&gt;
First update:           2,442 - 2,441 = 1&lt;br /&gt;
Later updates:          1 &amp;gt; 1 is false; no hit or decrement&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A truncated separation of 4,863 units similarly stores 4,883, then becomes 2,442 and finally 1. Other launch requirements, such as scanner range and the torpedo guidance check, still apply; the arithmetic condition alone does not guarantee that a shot can be fired.&lt;br /&gt;
&lt;br /&gt;
== Consequences ==&lt;br /&gt;
The torpedo remains nonzero in one of the target&amp;#039;s three incoming torpedo slots, which prevents that slot from accepting another shot. It never delivers damage or self-clears through the normal impact path. It can remain until another action resets the incoming projectile records, such as removal or replacement of the target ship. Moving the target does not help because the countdown is not recalculated from the ships&amp;#039; current positions.&lt;br /&gt;
&lt;br /&gt;
== Correction ==&lt;br /&gt;
ge-next 0.2.4 changed the outer guard to process every positive distance. A torpedo at distance 1 now meets the normal &amp;lt;code&amp;gt;distance &amp;lt;= torpsped&amp;lt;/code&amp;gt; hit condition on the next update; zero alone denotes a free slot.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Torpedoes]]&lt;br /&gt;
* [[Torpedo command]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Classic bugs: Combat]]&lt;br /&gt;
[[Category:Classic bugs: Numeric correctness]]&lt;br /&gt;
&lt;br /&gt;
{{GE navigation}}&lt;/div&gt;</summary>
		<author><name>CodexBot</name></author>
	</entry>
</feed>