Trouble with server src (modification)
-
- Posts: 26
- Joined: Wed Jan 13, 2010 5:16 pm
Trouble with server src (modification)
Deciding I wanted to make changes unavailable in the configuration, I decided to compile the game and run it in a virtualized Ubuntu environment after making some tweaks to the code. All but one of the modifications I have made work as expected.
Now, for starters, I have a barely manageable working knowledge of code, so I'm probably doing something completely wrong here, but I'm attempting to alter town / dungeon generation so that it is limited to a smaller area around Bree -- in my opinion (and those of my friends) the wilderness is functionally useless to the enjoyment of the game, and reducing potential travel time around the world map is my primary goal.
The code I'm looking at is in wild.c, line 271-272 (and again at line 317-318), which appears to be where town and dungeon placement is handled.
The initial code is
y = rand_int(MAX_WILD_Y);
x = rand_int(MAX_WILD_X);
Which I assume, based on context from the surrounding code, is used to generate the coordinates to that are checked for conflicts before the placement of the dungeon (or town) occurs at that coordinate.
So I figured, a simple adjustment would suffice, and changed it to
y = rand() % 30 + 17;
x = rand() % 30 + 17;
Which, based on my understanding of C++ (which is, by the way, extremely limited), generate a number between 17 and 46 for each.
Upon compiling, however, the server simply generates a world without any towns or dungeons. So clearly, somewhere along the line, my understanding of what is going on here is flawed.
Now, for starters, I have a barely manageable working knowledge of code, so I'm probably doing something completely wrong here, but I'm attempting to alter town / dungeon generation so that it is limited to a smaller area around Bree -- in my opinion (and those of my friends) the wilderness is functionally useless to the enjoyment of the game, and reducing potential travel time around the world map is my primary goal.
The code I'm looking at is in wild.c, line 271-272 (and again at line 317-318), which appears to be where town and dungeon placement is handled.
The initial code is
y = rand_int(MAX_WILD_Y);
x = rand_int(MAX_WILD_X);
Which I assume, based on context from the surrounding code, is used to generate the coordinates to that are checked for conflicts before the placement of the dungeon (or town) occurs at that coordinate.
So I figured, a simple adjustment would suffice, and changed it to
y = rand() % 30 + 17;
x = rand() % 30 + 17;
Which, based on my understanding of C++ (which is, by the way, extremely limited), generate a number between 17 and 46 for each.
Upon compiling, however, the server simply generates a world without any towns or dungeons. So clearly, somewhere along the line, my understanding of what is going on here is flawed.
Re: Trouble with server src (modification)
Actually, I don't really see why you wouldn't get any towns or dungeons after those changes. The only thing "wrong" with your changes is that you're using rand() which shouldn't be used since we have our own random number generator (see z-rand.c and z-rand.h in src/common). Maybe you made some other changes that broke town and dungeon generation?
-
- Posts: 26
- Joined: Wed Jan 13, 2010 5:16 pm
Re: Trouble with server src (modification)
Nope, no other change. Reverting that change alone causes normal expected behavior and I haven't changed anything else related to world and wilderness generation.
Re: Trouble with server src (modification)
did you seed the rand() correctly? rand generate a static number if seed doesnt change/rerun
-
- Posts: 26
- Joined: Wed Jan 13, 2010 5:16 pm
Re: Trouble with server src (modification)
Code: Select all
{R TomeNET server - v4.4.4
{r "Tales of Middle Earth"
{w http://www.tomenet.net/
{w http://koti.mbnet.fi/mikaelh/tomenet/
{w http://www.c-blue.de/rogue/
{y Documentation at http://www.c-blue.de/rogue/TomeNET-Guide.txt
[Initializing lua... (scripts)]
25 Aug (Thu) 19:58:41_SERVERSTARTUP_19:58:41-2011/8/25(4)
[Initializing arrays... (features)]
[Initializing arrays... (skills)]
[Initializing arrays... (objects)]
[Initializing arrays... (artifacts)]
[Initializing arrays... (ego-items)]
[Initializing arrays... (monsters)]
[Initializing arrays... (ego-monsters)]
[Initializing arrays... (dungeon types)]
[Initializing arrays... (vaults)]
[Initializing arrays... (traps)]
[Initializing arrays... (action types)]
[Initializing arrays... (owners types)]
[Initializing arrays... (stores types)]
[Initializing arrays... (other)]
[Initializing arrays... (alloc)]
[Initializing arrays... done]
GO_INIT: ---INIT---
GO_INIT: ---STARTING UP---
GO_INIT: ---INIT AI---
GO_ERROR: exec().
GO_COMMAND: <time_settings 0 0 0>
SIGPIPE received
GO_ENGINE: ERROR in fflush().
Server savefile does not exist
One other thing I forgot to mention is that approximately 75% of the time, the server hangs after "GO_COMMAND: <time_settings 0 0 0>", and does so even on completely unmodified source.
Re: Trouble with server src (modification)
Actually, I think most rand() implementations do return some numbers even if they are not seeded. The only problem is that the sequence of numbers is usually always the same.DeathGod wrote:did you seed the rand() correctly? rand generate a static number if seed doesnt change/rerun
Well, the server could be stuck in an infinite loop. Have you checked the CPU load? It could be that the server can't find a suitable random position for some town and is stuck running the loop endlessly. Especially since rand() isn't seeded, it could be doing something weird.Silvermoon wrote:This is what it returns, no matter what method I've tried. Leaving the code untouched will generate a world normally. Also, it appears to hang at "Server savefile does not exist", as I am unable to connect to it -- I never bothered checking before, I just assumed that it wasn't generating towns and dungeons because the console typically gives feedback for that. Again, everything operates fine if I compile without any changes to wild.c.
I suggest you use rand_int() instead of rand() like was done in the original code.
The server is trying to communicate with gnugo. Just comment out ENABLE_GO_GAME in defines.h to disable the Go game.Silvermoon wrote:One other thing I forgot to mention is that approximately 75% of the time, the server hangs after "GO_COMMAND: <time_settings 0 0 0>", and does so even on completely unmodified source.
-
- Posts: 26
- Joined: Wed Jan 13, 2010 5:16 pm
Re: Trouble with server src (modification)
Commenting out the Go game causes a ton of errors in w_util.c. I attempted to comment out the relevant sections of the code, only to find after starting to compile that the file itself (w_util.c) has had all changes reverted.
I quadruple-checked this issue. The changes I am making to w_util.c are being reverted somehow upon starting the compiler. Even my text editor informs me the file has been modified and asking me if I want to reload it. I am now absolutely convinced that either I have no understanding of computers in general anymore, or this machine is possessed.
So I'm just going to deal with it occasionally giving me trouble there for now.
I am concerned that I may be missing dependencies or libraries (or rather, using the wrong versions of them) causing unwanted behavior -- unless one of you can test and see if this isn't just behavior on my end.
In any case, the server does appear to be going into an infinite loop, and I can't discern why. As a test, I redownloaded the source from mikaelh's site, just to doubly ensure that no other changes I made are involved, and it still hangs.
I quadruple-checked this issue. The changes I am making to w_util.c are being reverted somehow upon starting the compiler. Even my text editor informs me the file has been modified and asking me if I want to reload it. I am now absolutely convinced that either I have no understanding of computers in general anymore, or this machine is possessed.
So I'm just going to deal with it occasionally giving me trouble there for now.
I am concerned that I may be missing dependencies or libraries (or rather, using the wrong versions of them) causing unwanted behavior -- unless one of you can test and see if this isn't just behavior on my end.
In any case, the server does appear to be going into an infinite loop, and I can't discern why. As a test, I redownloaded the source from mikaelh's site, just to doubly ensure that no other changes I made are involved, and it still hangs.
- the_sandman
- Developer
- Posts: 150
- Joined: Sun Dec 13, 2009 6:52 pm
Re: Trouble with server src (modification)
Did you `make clean' after editing the defines? :>
-
- Posts: 26
- Joined: Wed Jan 13, 2010 5:16 pm
Re: Trouble with server src (modification)
Yep. That's part of what I kept double-checking. I'm still confused on that, but it's not honestly my primary concern. At this point, I'm tempted to just rewrite recalls to get rid of coordinate checks so I can get the server up and playable. I really dislike generating one world after another trying to get decent geography.
Re: Trouble with server src (modification)
w_util.c is generated from util.pkg, that's why it gets rewritten every time you build the server. You need to edit util.pkg (which is also a lot easier to edit).Silvermoon wrote:Commenting out the Go game causes a ton of errors in w_util.c. I attempted to comment out the relevant sections of the code, only to find after starting to compile that the file itself (w_util.c) has had all changes reverted.
I quadruple-checked this issue. The changes I am making to w_util.c are being reverted somehow upon starting the compiler. Even my text editor informs me the file has been modified and asking me if I want to reload it. I am now absolutely convinced that either I have no understanding of computers in general anymore, or this machine is possessed.
The server doesn't really have any significant library dependencies.Silvermoon wrote:I am concerned that I may be missing dependencies or libraries (or rather, using the wrong versions of them) causing unwanted behavior -- unless one of you can test and see if this isn't just behavior on my end.
Well, I tested your changes myself. The server got stuck in an infinite loop in the town placement as I suspected. I was able to successfully start the server after I changed the code to this:Silvermoon wrote:In any case, the server does appear to be going into an infinite loop, and I can't discern why. As a test, I redownloaded the source from mikaelh's site, just to doubly ensure that no other changes I made are involved, and it still hangs.
Code: Select all
y = rand_int(30) + 17;
x = rand_int(30) + 17;