Update of "summon" commands

Moderator: GZDoom Developers

Post Reply
kgsws-CZ
Posts: 70
Joined: Sun Jul 19, 2009 9:50 pm

Update of "summon" commands

Post by kgsws-CZ »

Make all summon commands accept another arguments - TID, special and args[5] - and of course set it to final item.
New function: summon <item name> [tid [special [arg1 [arg2 [arg3 [arg4 [arg5]]]]]]]

There is working code (maybe it needs some fixes, but it works as is), i dont know which version of zdoom i used :P

d_net.cpp

Code: Select all

// inside function Net_DoCommand:
	case DEM_SUMMON:
	case DEM_SUMMONFRIEND:
	case DEM_SUMMONFOE:
		{
			const PClass *typeinfo;

			// kgsws's change
			SWORD tid;
			BYTE special;
			int args[5];
			// kgsws's end

			s = ReadString (stream);

			// kgsws's change
			tid = ReadWord(stream);
			special = ReadByte(stream);
			for(i = 0; i < 5; i++) args[i] = ReadLong(stream);
			ReadByte(stream);
			// kgsws's end

			typeinfo = PClass::FindClass (s);
			if (typeinfo != NULL && typeinfo->ActorInfo != NULL)
			{
				AActor *source = players[player].mo;
				if (source != NULL)
				{
					if (GetDefaultByType (typeinfo)->flags & MF_MISSILE)
					{
						P_SpawnPlayerMissile (source, typeinfo);
					}
					else
					{
						const AActor *def = GetDefaultByType (typeinfo);
						AActor *spawned = Spawn (typeinfo,
							source->x + FixedMul (def->radius * 2 + source->radius, finecosine[source->angle>>ANGLETOFINESHIFT]),
							source->y + FixedMul (def->radius * 2 + source->radius, finesine[source->angle>>ANGLETOFINESHIFT]),
							source->z + 8 * FRACUNIT, ALLOW_REPLACE);
						if (spawned != NULL)
						{

							// kgsws's change
							spawned->angle = source->angle; // Force target face as player, better? :)
							spawned->tid = tid;
							spawned->special = special;
							for(i = 0; i < 5; i++) {
								spawned->args[i] = args[i];
							}
							if(tid) spawned->AddToHash();
							// kgsws's end

							if (type == DEM_SUMMONFRIEND)
							{
								if (spawned->CountsAsKill()) 
								{
									level.total_monsters--;
								}
								spawned->FriendPlayer = player + 1;
								spawned->flags |= MF_FRIENDLY;
								spawned->LastHeard = players[player].mo;
							}
							else if (type == DEM_SUMMONFOE)
							{
								spawned->FriendPlayer = 0;
								spawned->flags &= ~MF_FRIENDLY;
							}
						}
					}
				}
			}
		}
		break;

// inside function Net_SkipCommand:
		case DEM_MUSICCHANGE:
		case DEM_PRINT:
		case DEM_CENTERPRINT:
		case DEM_UINFCHANGED:
		case DEM_CHANGEMAP:
		case DEM_SPRAY:
		case DEM_MORPHEX:
		case DEM_KILLCLASSCHEAT:
			skip = strlen ((char *)(*stream)) + 1;
			break;
		// kgsws's change
		case DEM_SUMMON:
		case DEM_SUMMONFRIEND:
		case DEM_SUMMONFOE:
			skip = strlen ((char *)(*stream)) + 25;
			break;
		// kgsws's end

		case DEM_INVUSE:
		case DEM_INVDROP:
		case DEM_WARPCHEAT:
			skip = 4;
			break;
info.cpp

Code: Select all

CCMD (summon)
{
	int i;

	if (CheckCheatmode ())
		return;

	if (argv.argc() > 1)
	{
		const PClass *type = PClass::FindClass (argv[1]);
		if (type == NULL)
		{
			Printf ("Unknown class '%s'\n", argv[1]);
			return;
		}
		Net_WriteByte (DEM_SUMMON);
		Net_WriteString (type->TypeName.GetChars());

		// kgsws's change
		if (argv.argc() > 2) {
			Net_WriteWord(clamp(atoi(argv[2]), 0, 32767)); // TID
			if (argv.argc() > 3) {
				Net_WriteByte(clamp(atoi(argv[3]), 0, 255)); // special
				for(i = 4; i < 9; i++) { // args
					if(i < argv.argc()) Net_WriteLong(atoi(argv[i])); else Net_WriteLong(0);
				}
			} else {
				Net_WriteByte(0); // special
				for(i = 0; i < 5; i++) Net_WriteLong(0); // args
			}
		} else {
			Net_WriteWord(0); // TID
			Net_WriteByte(0); // special
			for(i = 0; i < 5; i++) Net_WriteLong(0); // args
		}
		Net_WriteByte(0); // avoid strange things, i dont know why it must be there
		// kgsws's end
	}
}
Update of fuction "summonfriend" and "summonfoe" is same.

It can really help with development of new maps. Now it is required to change map and reload it, but with new summon function it will be possible to try some effects faster.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Update of "summon" commands

Post by Graf Zahl »

Please always post code submissions as .diff files, not code excerpts.
kgsws-CZ
Posts: 70
Joined: Sun Jul 19, 2009 9:50 pm

Re: Update of "summon" commands

Post by kgsws-CZ »

Ok here is for zdoom version 2.3.1

Code: Select all

diff -rup zdoom-orig/src/d_net.cpp zdoom/src/d_net.cpp
--- zdoom-orig/src/d_net.cpp	2009-02-24 06:58:59.000000000 +0100
+++ zdoom/src/d_net.cpp	2009-07-20 19:24:56.000000000 +0200
@@ -2098,9 +2098,20 @@ void Net_DoCommand (int type, BYTE **str
 	case DEM_SUMMONFRIEND2:
 	case DEM_SUMMONFOE2:
 		{
-			const PClass *typeinfo;
+			const PClass *typeinfo;
+			int angle;
+		        SWORD tid;
+		        BYTE special;
+		        int args[5];
+
+			s = ReadString (stream);
+			if (type >= DEM_SUMMON2 && type <= DEM_SUMMONFOE2) {
+				angle = ReadWord(stream); // shouldn't be this here even without my addon?
+				tid = ReadWord(stream);
+				special = ReadByte(stream);
+				for(i = 0; i < 5; i++) args[i] = ReadLong(stream);
+			}
 
-			s = ReadString (stream);
 			typeinfo = PClass::FindClass (s);
 			if (typeinfo != NULL && typeinfo->ActorInfo != NULL)
 			{
@@ -2138,8 +2149,13 @@ void Net_DoCommand (int type, BYTE **str
 						}
 						if (type >= DEM_SUMMON2 && type <= DEM_SUMMONFOE2)
 						{
-							int angle = ReadWord(stream);
-							spawned->angle = source->angle - (ANGLE_1 * angle);
+							spawned->angle = source->angle - (ANGLE_1 * angle);
+							spawned->tid = tid;
+							spawned->special = special;
+							for(i = 0; i < 5; i++) {
+								spawned->args[i] = args[i];
+							}
+							if(tid) spawned->AddToHash();
 						}
 					}
 				}
@@ -2404,10 +2420,13 @@ void Net_SkipCommand (int type, BYTE **s
 
 		case DEM_GIVECHEAT:
 		case DEM_TAKECHEAT:
+			skip = strlen ((char *)(*stream)) + 3;
+			break;
+
 		case DEM_SUMMON2:
 		case DEM_SUMMONFRIEND2:
 		case DEM_SUMMONFOE2:
-			skip = strlen ((char *)(*stream)) + 3;
+			skip = strlen ((char *)(*stream)) + 26;
 			break;
 
 		case DEM_MUSICCHANGE:
diff -rup zdoom-orig/src/info.cpp zdoom/src/info.cpp
--- zdoom-orig/src/info.cpp	2008-12-16 02:23:44.000000000 +0100
+++ zdoom/src/info.cpp	2009-07-20 18:50:26.000000000 +0200
@@ -372,7 +372,9 @@ CCMD (dumpmapthings)
 bool CheckCheatmode ();
 
 static void SummonActor (int command, int command2, FCommandLine argv)
-{
+{
+	int i;
+
 	if (CheckCheatmode ())
 		return;
 
@@ -387,8 +389,17 @@ static void SummonActor (int command, in
 		Net_WriteByte (argv.argc() > 2 ? command2 : command);
 		Net_WriteString (type->TypeName.GetChars());
 
-		if (argv.argc () > 2)
-			Net_WriteWord (atoi (argv[2]));
+		if (argv.argc () > 2) {
+			Net_WriteWord (atoi (argv[2])); // angle
+			if(argv.argc() > 3) Net_WriteWord(clamp(atoi(argv[3]), 0, 32767)); // TID
+			else Net_WriteWord(0);
+			if(argv.argc() > 4) Net_WriteByte(clamp(atoi(argv[4]), 0, 255)); // special
+			else Net_WriteByte(0);
+			for(i = 5; i < 10; i++) { // args[5]
+				if(i < argv.argc()) Net_WriteLong(atoi(argv[i]));
+				else Net_WriteLong(0);
+			}
+		}
 	}
 }
 
Oh and i think i found a bug ... Look to original d_net.cpp at line 2141, there is ReadWord. But what if someone call DEM_SUMMON2 to summon missile - wouldn't be there ReadWord missing? (line 2112)
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Update of "summon" commands

Post by Gez »

kgsws-CZ wrote:Ok here is for zdoom version 2.3.1
Well, it's still not good:
1. Please use the latest SVN version instead of the latest official version. The code base evolves so fast that it might be impossible for the patch tools to merge the diff, leading the devs to having to do it by hand.
2. Please attach (upload attachment) the diff as a zipped file or as a txt file rather than integrating it in a post. The forum software converts tabs into spaces, so the indentation is lost. To keep the code tidy and readable, the devs then have to reformat it by hand, which is tedious and time-wasting.
kgsws-CZ
Posts: 70
Joined: Sun Jul 19, 2009 9:50 pm

Re: Update of "summon" commands

Post by kgsws-CZ »

I hope its ok now.

Oh and about that bug - it is really bug
Look to original d_net.cpp at line 2143, there is ReadWord. But what if someone call DEM_SUMMON2 to summon missile - wouldn't be there ReadWord missing? (line 2112)
There is proof, try in (original) game "summon rocket 3855" - it will summon rocket ... but it will also kill you. (3855 = 0x0F0F; 0x0F = DEM_SUICIDE)

EDIT: new summon command is now "summon <item name> [angle [tid [special [arg1 [arg2 [arg3 [arg4 [arg5]]]]]]]]"
Attachments
summon.txt
Here it is, its update of zdoom revision r1727, it should be latest one. It also fixes that ReadWord bug.
(2.67 KiB) Downloaded 40 times
kgsws-CZ
Posts: 70
Joined: Sun Jul 19, 2009 9:50 pm

Re: Update of "summon" commands

Post by kgsws-CZ »

Nothing new about this? Or about summon bug?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Update of "summon" commands

Post by Graf Zahl »

I have been on vacation last week and had no means to add this patch. Don't be that impatient!

EDIT: This patch does not work. It reports a conflict in info.cpp.
kgsws-CZ
Posts: 70
Joined: Sun Jul 19, 2009 9:50 pm

Re: Update of "summon" commands

Post by kgsws-CZ »

Oh, ok sorry ...

But i dont know why that patch does not work for you, it works for me ... strange ...
This is output:

Code: Select all

patching file zdoom/src/d_net.cpp
patching file zdoom/src/info.cpp
Hunk #2 succeeded at 425 with fuzz 1.
User avatar
Macil
Posts: 2529
Joined: Mon Mar 22, 2004 7:00 pm
Preferred Pronouns: He/Him
Location: California, USA. Previously known as "Agent ME".
Contact:

Re: Update of "summon" commands

Post by Macil »

Works for me on r1748. Running "patch -p1 <../../../summon.txt" (had the diff in a different directory) from trunk outputs
patching file src/d_net.cpp
patching file src/info.cpp
Hunk #1 succeeded at 406 (offset -2 lines).
Hunk #2 succeeded at 423 with fuzz 1 (offset -2 lines).
The diff looks normal, nothing out of the ordinary (like git headers or anything). Not sure why TortoiseSVN would give any errors on applying it.
_________

I do have a small criticism of the code change though. In SummonActor(), i is declared immediately besides only being used once in a for loop, which isn't even executed in some cases:
Spoiler:
Shouldn't you define i in the for loop itself, so that way memory is only set aside for it in the case the loop is used and in loop scope? No need to have variables in scopes above what they need, makes it a lot more obvious what i is for this way.
Spoiler:
_________
EDIT

On second thought, it could be that TortoiseSVN's patch utility doesn't use a fuzz factor for context diffs, or is semi-strict to svn diff's exact format (both kinda ridiculous, but probable). Attached is a diff generated by svn from r1748 with the above change for convenience that I can't imagine wouldn't work.
Attachments
summon-am.diff.txt
Has summon.txt changes + i scope fix
(2.27 KiB) Downloaded 28 times
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Update of "summon" commands

Post by randi »

Agent ME wrote:Shouldn't you define i in the for loop itself, so that way memory is only set aside for it in the case the loop is used and in loop scope?
If it's a register variable, then it uses no memory. Since it's used as a loop counter, and there's nothing terribly complicated going on in the loop, you're pretty much guaranteed it will be in a register.

If it does get spilled to the stack, most compilers will only allocate one stack frame for the entire function at entry (and some calling conventions, such as x86-64, enforce this), so scoping variables inside a function won't save you any memory. A good compiler ought to be able to track the lifetime of each variable and reuse parts of the stack frame depending on what variables are live at each point in the code.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Update of "summon" commands

Post by Graf Zahl »

Actually, I have never seen a compiler which does allocate stack memory per sub-block. Changes like this for optimizations sake are totally useless so the only reason is to make the code look nicer.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”