Problems with [message]?

Discussion of all aspects of the game engine, including development of new and existing features.

Moderator: Forum Moderators

Post Reply
Puck6633
Posts: 10
Joined: November 28th, 2005, 8:30 pm

Problems with [message]?

Post by Puck6633 »

While experimenting with WML I ran across a couple of problems with the [message] (see here), so I thought I would have a look at the source. After a quick look through the src directory* I came across the code in game_events.cpp dealing with [message].

A grep revealed that the error I'm recieving when trying to use messages with [option]s in multiplayer** is caused by a replay error that, according to the comments, is thrown when a message with choices was found during replay but no actual choice could be found. (line 1199 of game_events.cpp)

I'm not quite sure why this would be happening, though I don't know a lot about the inner workings of the game (is multiplayer movement implemented via replays?), but it would be nice for messages with options to be possible in multiplayer. Perhaps one of you devs out there with more experience with the code could give me a hand. :)


Also, I thought it would be nice if messages could only be shown to one side in multiplayer. And it seems to me that this could be implemented with a bit of code right after the speaker is determined:

Code: Select all

if(<in multiplayer mode> && cfg["speaker"] != "narrator" && (speaker.<side> != <this client's side> || cfg["show_to"] != <this client's side>)) {
	return <appropriate value>;
}
Where the parts in angle brackets are replaced with actual code. This would default to showing messages in multiplayer only to the side to whom the filtered unit belongs, with the possibility of showing the message to other sides, and narration would automatically be shown to all sides.

Anyway, I figured I would mention it. If I'm able to get wesnoth compiled I'll try to make the changes myself and post the code if I do. Unfortunately I'm stuck with Windows and no VC++ since my bootloader has been giving me trouble so my chances of getting it to compile are pretty slim, but we'll see. :)


* Compliments to the devs, the code is very intuitive and well laid out. :)
** "The file you have tried to load is corrupt", line 627 of playlevel.cpp


P.S. Thanks for all your hard work, Wesnoth is one of the best freeware games I've ever seen. :D
Yogibear
Retired Developer
Posts: 1086
Joined: September 16th, 2005, 5:44 am
Location: Hamburg, Germany

Post by Yogibear »

Hi Puck,

thank you for your work and thoughts so far :) .

I am dealing mostly with the replay code at the moment. Regarding that message bug, i will have a look at that (though i have to admit that there are other things on my todo list first :? ).

As you already noticed, the code for gameplay and replay is intertwined within one function (play_level). One of my biggest goals at the moment is resolving that into separate functionalities. That is the reason why in trunk you will find a replay_controller class. Right now, it exists side by side with play_level, not having much to do with it. Eventually i will get to a point where there is two classes, one for gameplay and one for replay, sharing all the common statements through a base class. But there is still some work to do to get there.

There is already a mechanism to prevent messages to be shown to everybody: Team talk in multiplayer. It is supposed to do almost exactly what you described in your post. But it is not linked to message wml tags, that would have to be added.

I am on windows too, using Visual C++. This seems to be an extincting species, looks like i am the only one at the moment :P (not counting Dave since he retreated from coding for the project). I would be happy if you could join me there. I heard that Microsoft relelased a free version of Visual C++. I have not tried it yet but you can check by yourself:
http://msdn.microsoft.com/vstudio/expre ... fault.aspx

Feel free to ask if you need more information :) .
Smart persons learn out of their mistakes, wise persons learn out of others mistakes!
Puck6633
Posts: 10
Joined: November 28th, 2005, 8:30 pm

Post by Puck6633 »

Wow! A free version of VC++? You may have just made my life a whole lot easier. :D I'm downloading the file now, though I can't say how long it will take.
There is already a mechanism to prevent messages to be shown to everybody: Team talk in multiplayer. It is supposed to do almost exactly what you described in your post. But it is not linked to message wml tags, that would have to be added.
That's a good point. Strangely though, I can't seem to find the team chat code anywhere. :? The normal chat code can be found easily enough in multiplayer_ui.cpp, but where it gets strange is here:

Code: Select all

std::string chat::format_message(const msg& message)
{
	return "<" + message.user + ">" + message.message + "\n";
}
I can't find the "*<username>* <message>" format for team chat anywhere in the code. I also can't figure out how to tell if the current game is multiplayer and what side the client is currently playing. I did, however, find out how to tell what side a unit is on. :)

Also, if I'm not mistaken the "replay bug" could be fixed by changing line 1181 of game_events.cpp from

Code: Select all

if(get_replay_source().at_end() || options.empty()) {
to

Code: Select all

if(<in multiplayer mode> || get_replay_source().at_end() || options.empty()) {
Though my understanding of how multiplayer works is very limited, so it's mostly just a shot in the dark, so to speak. I'll keep looking, and if I can find a way to reliably tell if the game is multiplayer I'll make the change and see if it works. :)

Edit:
Microsoft Visual C++ Express
This product cannot be installed on Microsoft Windows ME, Windows NT 4.0, or earlier. You must upgrade your operating system to Windows 2000 or later before installing this product.
:evil:
Puck6633
Posts: 10
Joined: November 28th, 2005, 8:30 pm

Post by Puck6633 »

Ugh. I've been trying to get Wesnoth to compile ever since my last post, but I still haven't had a lot of luck. I finally got all the dependencies installed and got the bugs ironed out of them, but wesnoth only compiles two .o files before complaining about snprintf() not being defined, which seems to be some sort of problem with my <cstdio> header. :?

I did, however, finally find the information I was looking for (I think), and fixed my code snippets. As far as I can tell the following changes should fix the problems I encountered:

Added at line 1115 of game_events.cpp:

Code: Select all

		//check to see if this message was intended for us
		if((defines_map_.find("MULTIPLAYER") != defines_map_.end()) && cfg["speaker"] != "narrator" && ((teams[speaker->second.side()].name != preferences::login()) && (teams[cfg["show_to"]].name != preferences::login()))) {
            return rval;
        }
Replacing line 1177 of game_events.cpp:

Code: Select all

		if((defines_map_.find("MULTIPLAYER") != defines_map_.end()) || get_replay_source().at_end() || options.empty()) {
I'm not entirely sure how teams[] is organized, and the references to it might need " - teams.begin()" or " - teams.begin() + 1" added to them (I.E. "teams[speaker.side() - teams.begin() + 1].name") But otherwise The code should work.

I'm going to keep trying to get wesnoth to compile, but I would be most appreciative if someone could give my changes a try. I'm anxious to get this fixed, since I have two more ideas for multiplayer scenarios that require messages with options. :)
Xan
Inactive Developer
Posts: 258
Joined: August 28th, 2005, 3:05 pm
Contact:

Post by Xan »

Puck6633 wrote:Ugh. I've been trying to get Wesnoth to compile ever since my last post, but I still haven't had a lot of luck. I finally got all the dependencies installed and got the bugs ironed out of them, but wesnoth only compiles two .o files before complaining about snprintf() not being defined, which seems to be some sort of problem with my <cstdio> header. :?
If you're using gcc on windows, you will need to edit src/global.hpp.
Change these lines:

Code: Select all

//for windows compilers
#ifdef __MSVCRT__
	#undef snprintf
	#define snprintf _snprintf
#endif
to

Code: Select all

//for windows compilers
#ifdef __MSVCRT__
#ifndef __GNUC__
	#undef snprintf
	#define snprintf _snprintf
#endif
#endif
"It is time people learned about their failures and my successes."
Puck6633
Posts: 10
Joined: November 28th, 2005, 8:30 pm

Post by Puck6633 »

Ha! That worked! :D It's compiling playturn.cpp now, and here I was just about to give up. ;) if everything works right I'll add my changes and test them, then post the finished changes for inclusion in the main distrobution if it's so desired. :)

Thanks for the help! :D
ott
Inactive Developer
Posts: 838
Joined: September 28th, 2004, 10:20 am

Post by ott »

Ideal would be a diff against current svn.
This quote is not attributable to Antoine de Saint-Exupéry.
Post Reply