Bugfix - storage eq does not display ammo quantities

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

User avatar
ChrstphrR
Testers Team
Testers Team
Posts: 42
Joined: 09 May 2010, 17:30
Noob?: No
Location: Northern Alberta, Canada

Bugfix - storage eq does not display ammo quantities

#1 Post by ChrstphrR »

Bug description

When using the storage command (or, specifically, storage eq), all ammo item types in your equipment list inside storage do not show the quantity in that item slot, even though they are stackable, and are actually sitting there in your account's storage.

Code: Select all

storage eq

eq
-----------Storage-------------
-- Equipment --
41   Stun Arrow (Arrow)
45   Guisarme [3] (Weapon)
46   Mantle [1] (Armor)
47   Hat [1] (Armor)
48   Mantle [1] (Armor)
49   Poo Poo Hat (Armor) -- Not Identified
50   Poo Poo Hat (Armor) -- Not Identified
51   Poo Poo Hat (Armor) -- Not Identified
52   Poo Poo Hat (Armor) -- Not Identified
53   Guisarme [3] (Weapon)
54   Adventurer's Suit [1] (Armor)
55   Adventurer's Suit [1] (Armor)
-------------------------------
Capacity: 56/300
-------------------------------
Solution:

I suggested a similar fix for inventory to EternalHarvest, many many revisions before current (8161 as of this writing), to fix inventory: i or i eq for quite a long time did not show the arrow quantities inventory, except when they were equipped.

Instead of letting someone else fix this, I actually buckled down and studied that fix, and then made and equivalent one for storage. This was done shamelessly for the ego boost that finding and coding a bug on your own does... and in hopes that I could parlay this patch into a request for SVN write access so I can carry on further bug fixes or improvements.

The change is contained in /src/Commands.pm in the cmdStorage_list subroutine called by cmdStorage.

I added a comment header for the command, detailing its usage, and what routine calls it.
Tabs are used for whitespace, and I took the liberty along with the bugfix, of removing extraneous single tabs that could just be a \n instead:

Code: Select all

Index: src/Commands.pm
===================================================================
--- src/Commands.pm	(revision 8161)
+++ src/Commands.pm	(working copy)
 

+## cmdStorage_list
+##
+## Displays the contents of storage, or a subset indicated by switches.
+##
+## Called by: cmdStorage (not called directly)
+##  
+## Usage:
+##  cmdStorage_list(<list_type>)
+##
+##    Only uses the first parameter of the scalar passed.
+##    <list_type> ::= ''|eq|nu|u
+##
+##
 sub cmdStorage_list {
 	my $type = shift;
 	message "$type\n";
-	
+
 	my @useable;
 	my @equipment;
 	my @non_useable;
-	
+
 	for (my $i = 0; $i < @storageID; $i++) {
 		next if ($storageID[$i] eq "");
 		my $item = $storage{$storageID[$i]};
@@ -4317,22 +4396,31 @@
 			$eqp{binID} = $i;
 			$eqp{name} = $item->{name};
 			$eqp{type} = $itemTypes_lut{$item->{type}};
+			## Add amt so we can give quantities for ammo.
+			$eqp{amount} = $item->{amount};
 			$eqp{identified} = " -- " . T("Not Identified") if !$item->{identified};
 			push @equipment, \%eqp;
 		} else {
 			push @non_useable, $item;
 		}
 	}
-	
+
 	my $msg = T("-----------Storage-------------\n");
-	
+
 	if (!$type || $type eq 'eq') {
 		$msg .= T("-- Equipment --\n");
 		foreach my $item (@equipment) {
-			$msg .= sprintf("%-3d  %s (%s) %s\n", $item->{binID}, $item->{name}, $item->{type}, $item->{identified});
+			## altered to allow for Arrows/Ammo which will are stackable equip.
+			my $line = sprintf("%-3d  %s (%s)", $item->{binID}, $item->{name}, $item->{type});
+			if ($item->{amount} > 1) {
+				$line .= " x $item->{amount}";
+			} else {
+				$line .= $item->{identified};
+			}
+			$msg .= $line . "\n";
 		}
 	}
-	
+
 	if (!$type || $type eq 'nu') {
 		$msg .= T("-- Non-Usable --\n");
 		for (my $i = 0; $i < @non_useable; $i++) {
@@ -4345,7 +4433,7 @@
 				[$binID, $display]);
 		}
 	}
-	
+
 	if (!$type || $type eq 'u') {
 		$msg .= T("-- Usable --\n");
 		for (my $i = 0; $i < @useable; $i++) {
@@ -4358,7 +4446,7 @@
 				[$binID, $display]);
 		}
 	}
-	
+
 	$msg .= "-------------------------------\n";
 	$msg .= TF("Capacity: %d/%d\n", $storage{items}, $storage{items_max});
 	$msg .= "-------------------------------\n";
The fixed code yields this:

Code: Select all

storage eq

eq
-----------Storage-------------
-- Equipment --
41   Stun Arrow (Arrow) x 1000
45   Guisarme [3] (Weapon)
46   Mantle [1] (Armor)
47   Hat [1] (Armor)
48   Mantle [1] (Armor)
49   Poo Poo Hat (Armor) -- Not Identified
50   Poo Poo Hat (Armor) -- Not Identified
51   Poo Poo Hat (Armor) -- Not Identified
52   Poo Poo Hat (Armor) -- Not Identified
53   Guisarme [3] (Weapon)
54   Adventurer's Suit [1] (Armor)
55   Adventurer's Suit [1] (Armor)
-------------------------------
Capacity: 56/300
-------------------------------
Caveats:

I have only tested this with arrows, on an archer/hunter character or two, not with other ammo types (bullets or kunais). By just testing for the quantity and displaying it, I figured that any issues with particular ammo (item) types were avoided.


Provided that there are no serious faults or further improvements with this fix, I would like to request write access to the repository to commit it, so that other players can benefit from being able to check their inventory from the console.

Update

Commited as r8162.

Omitted obscene ranting/preview of a future fix. This part was not committed since glomming multiple fixes together is bad practice!
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Bugfix - storage eq does not display ammo quantities

#2 Post by kLabMouse »

Thanks for the Fix.
Also. I have something to add.
It's About Item Types. Actually "KeplerBR" asked about it a few days ago.

Code: Select all

typedef enum <unnamed-tag> {
  LOCATION_NOTHING =  0x0,
  LOCATION_HEAD =  0x1,
  LOCATION_RARM =  0x2,
  LOCATION_ROBE =  0x4,
  LOCATION_ACCESSORY1 =  0x8,
  LOCATION_BODY =  0x10,
  LOCATION_LARM =  0x20,
  LOCATION_SHOES =  0x40,
  LOCATION_ACCESSORY2 =  0x80,
  LOCATION_HEAD2 =  0x100,
  LOCATION_HEAD3 =  0x200,
  LOCATION_ARROW =  0xffff8000,
  LOCATION_COSTUME_HEAD2 =  0x400,
  LOCATION_COSTUME_HEAD3 =  0x800,
  LOCATION_COSTUME_HEAD =  0x1000,
  LOCATION_COSTUME_ROBE =  0x2000,
  LOCATION_COSTUME_FLOOR =  0x4000,
  LOCATION_HEAD_TB =  0x101,
  LOCATION_HEAD_MB =  0x201,
  LOCATION_HEAD_TM =  0x300,
  LOCATION_HEAD_TMB =  0x301,
  LOCATION_COSTUME_HEAD_TM =  0xc00,
  LOCATION_COSTUME_HEAD_TB =  0x1400,
  LOCATION_COSTUME_HEAD_MB =  0x1800,
  LOCATION_COSTUME_HEAD_TMB =  0x1c00,
  LOCATION_LAST =  0xffffffff,
} <unnamed-tag>;
It's an A Mask. On where the Equipment is Equipped.
Like "Two Handed Sword" location will be: LOCATION_RARM & LOCATION_LARM -> 0x22
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Bugfix - storage eq does not display ammo quantities

#3 Post by EternalHarvest »

Already partially mentioned in %Globals::equipSlot_lut.
Kaspy
Halfway to Eternity
Halfway to Eternity
Posts: 398
Joined: 08 Jun 2012, 15:42
Noob?: No
Location: Brazil

Re: Bugfix - storage eq does not display ammo quantities

#4 Post by Kaspy »

EternalHarvest wrote:Already partially mentioned in %Globals::equipSlot_lut.
[EN]
Much is not yet in globals.pm, and command eq needs to be updated to display visual equipment yet.

[PT-BR]
Boa parte não esta ainda no globals.pm, e o comando eq precisa ser atualizado para visualizar os equipamentos visuais ainda.
Image