Increasing weapon limit

Increasing weapon limit

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Increasing weapon limit

Post by FLOZi »

I've had a request for this, and run into something of a brick wall.

This is the patch so far:

Code: Select all

Index: Sim/Units/COB/CobFile.cpp
===================================================================
--- Sim/Units/COB/CobFile.cpp	(revision 5501)
+++ Sim/Units/COB/CobFile.cpp	(working copy)
@@ -187,7 +187,7 @@
 
 	// Also add the weapon aiming stuff
 	for (int i = 0; i < COB_MaxWeapons; ++i) {
-		char buf[15];
+		char buf[COB_MaxWeapons - 1];
 		sprintf(buf, "Weapon%d", i + 1);
 		string weapon(buf);
 		sprintf(buf, "%d", i + 1);
Index: Sim/Units/COB/CobFile.h
===================================================================
--- Sim/Units/COB/CobFile.h	(revision 5501)
+++ Sim/Units/COB/CobFile.h	(working copy)
@@ -40,7 +40,7 @@
 const int COBFN_Last = 16;					//Make sure to update this, so the array will be sized properly
 
 // These are special (they need space for MaxWeapons of each)
-const int COB_MaxWeapons = 16;
+const int COB_MaxWeapons = 32;
 const int COBFN_QueryPrimary   = COBFN_Last;
 const int COBFN_AimPrimary     = COBFN_QueryPrimary   + COB_MaxWeapons;
 const int COBFN_AimFromPrimary = COBFN_AimPrimary     + COB_MaxWeapons;
Index: Sim/Units/UnitDefHandler.cpp
===================================================================
--- Sim/Units/UnitDefHandler.cpp	(revision 5501)
+++ Sim/Units/UnitDefHandler.cpp	(working copy)
@@ -492,7 +492,7 @@
 	const WeaponDef* noWeaponDef = weaponDefHandler->GetWeapon("NOWEAPON");
 
 	LuaTable weaponsTable = udTable.SubTable("weapons");
-	for (int w = 0; w < 16; w++) {
+	for (int w = 0; w < 32; w++) {
 		LuaTable wTable;
 		string name = weaponsTable.GetString(w + 1, "");
 		if (name.empty()) {
Any ideas what i'm missing?
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Re: Increasing weapon limit

Post by SwiftSpear »

Isn't the weapons limit currently 256?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Increasing weapon limit

Post by FLOZi »

No, 16.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Increasing weapon limit

Post by Tobi »

No real clue about what you're missing, but some comments about the patch:
- First hunk isn't needed, a 15 byte char buffer is more enough to store Weapon0 up to Weapon99999999.
- In the last hunk you hardcoded the 32 instead of using your newly introduced COB_MaxWeapons ;-)

Have you already followed references to check each place where a weapon array is used? Checked UnitDef?
eriatarka
Posts: 67
Joined: 26 Jan 2008, 18:50

Re: Increasing weapon limit

Post by eriatarka »

Tobi wrote:- In the last hunk you hardcoded the 32 instead of using your newly introduced COB_MaxWeapons ;-)
Yeah, please, not more magic numbers, the Spring code has quite enough of those ;)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Increasing weapon limit

Post by FLOZi »

Tobi wrote:No real clue about what you're missing, but some comments about the patch:
- First hunk isn't needed, a 15 byte char buffer is more enough to store Weapon0 up to Weapon99999999.
- In the last hunk you hardcoded the 32 instead of using your newly introduced COB_MaxWeapons ;-)

Have you already followed references to check each place where a weapon array is used? Checked UnitDef?
COB_MaxWeapons already existed.

I guess I'll just include CobFile.h into UnitDefHandler.cpp, but everyone seems to complain about header includes spiralling out of control.


And woops, didn't realise the buffer was created in the loop. Serves me right for coding just to kill time.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Increasing weapon limit

Post by lurker »

So, anybody committed anything upping the limit yet? Snipawolf needs 21 weapons :cry:.
User avatar
Snipawolf
Posts: 4357
Joined: 12 Dec 2005, 01:49

Re: Increasing weapon limit

Post by Snipawolf »

I don't need 21 weapons, not having them just eliminates one of at least 5 ways I can use the weapon combination I have. >_>
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Increasing weapon limit

Post by FLOZi »

lurker wrote:So, anybody committed anything upping the limit yet? Snipawolf needs 21 weapons :cry:.
Nope.

Got flumoxxed as to what I was missing.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Increasing weapon limit

Post by FLOZi »

Fixed and committed - thanks to rattle. He pointed out that the pesky lua fbi_parser.lua was hardcoded to only parse the first 16 weapons.
Post Reply

Return to “Engine”