Online roguelike gamedev @ ANSI C

All trinity of online roguelikes written in ANSI C programming language (~ C89-C99 standard) as they all were initially based at Angband source code.

C is a very powerful programming language. When I first asked C.Blue (TomeNET maintainer) about C, he said: “…some people even say that ANSI C is the most efficient C-variant and the Linux kernel is actually written in it (instead of for example C++)”.

And after I’ve read a few articles about C myself, I’ve recognized this: every programmer should know C language, no matter which language do you use in your daily work. And the most fun to learn it – is to look into online roguelikes code sources!
 
So for all those who want to come closer to understanding – how online roguelikes works or want to help with developing, I wanna share a few useful links, to begin with:
 
1) wiki: C language, ANSI C
2) online roguelikes source code repositories:

3) Read the book about C. There are a lot of books about ANSI C; my personal favorite one is “C Primer Plus” by Stephen Prata. C it’s a language which you should not learn fast, as you need to understand a lot of deep internal stuff. Don’t be hurry 🙂

 
So.. To get into the development process, you should:
 
1) learn ANSI C basics (book or online tutorial would do)
2) create very simple roguelike game yourself (good tutorial – RogueLulz, Part I: Drawing the Map, Walking Around, Basic Monsters and Attacking)
3) ‘read’ source code and understand how it works
4) add a tiny feature and make it work. Eg: change the color of UI, add an indicator of buff/debuff, add a new window with minimap etc
5) join our discord and catch up with the dev process together! 🙂
 
Please don’t hesitate to add more information, useful links, tutorials or anything considering this topic in our discord, so I’ll add it there.
 

Coding FAQ:

Explain why your ATTR is 16 bit? I gather you need more values than 127, but could you elaborate? Also, is this in V?

Yes, because tilesets can be bigger than 128×128. Also GCU client uses special attributes greater than 128 because of Necklace of the Eye frontend. For example: it’s not possible to use @ symbols because NotEye uses @ to track the position of the player so you could use a smily face instead (0x263A).

Give a bird’s-eye view of how the dungeon levels are aligned in memory in V/PWMA nowdays? (e.g., in mang it’s horrid cave[-4096 to 127] array, with wilderness indexes spiraling in negative dimensions (as you well know))

Levels are now stores in a [x/y/z] array. Wilderness is rectangular. Towns or wilderness areas are (x,y,0). Then at location (x,y) you can have a dungeon with floors from 1 to 127 on z axis.

Is there also a function like get_player_level(struct player*p) which uses p->world_x, p->world_y, p->depth or something similar? and are there accessors like that?

No, only a get_cave.

Are monsters/objects still stored globally with references into levels, or are they now part of level struct?

Part of level. Everyhting is in the cave now: mobs, objects, traps.

How to debug the game?

Install C++Builder Community Edition

  1. create new project
  2. counsole application → C
  3. specify project source, choose “main.c” in /src/server
  4. save the project with the name: mangband into /src/bcb6 (first it will save .h file; and afterwards new window appear with *.cbproj) // name is important so it will generate server binary as mangband.exe
  5. now lets configure the game: project tab → try to find the “options”
  6. Building →
    C++ Shared Options → Final output directory → choose PWMAngband (main source folder)
  7. C++ Compiler → ‘Use classic Borland compiler’ → true
  8. Directories and Conditionals → conditional defines:
    _DEBUG;STRICT;BCC_IDE;WINDOWS
  9. Directories and Conditionals → Include file search path we need to add ..\win and ..\common
    to do so click on “…” to add a line
  10. Directories and Conditionals → Object file output directory → PWMAngband
  11. Pre-compiled headers → cache: true
  12. now we need to add all files into the project; first the files in “common”, all .c files
    right click project.exe and click add
    in /common
    .c
    add everything except net-unix.c
    it will appear in project folder (expand to see the files)
  13. now add all the files from the /server except main.c
  14. last file to add is “angband.rc” from /win
  15. project -> make … if it’s linking – we are good 🙂
  16. check is .exe files generated (should be in PWMAngband folder)
  17. execute (green arrow)
  18. now open “game-world.c”
  19. find “exit_game_panic” (ctrl-f shoulds open search wndow)
  20. let’s make breakpoint here: click in the margin on the left, on the line (red marker dot will appear)
  21. now close the server window (which is running as you executed it previously); use ctrl+c for closing it (closing with “x” can crash)
  22. now we will luanch server in debug mode: click on button next to green arrow (Run)
  23. it is now in debug mode: “exit_game_panic” is the function that is called when there is a crash; so when the game crashes, the debugger will stop on that line
  24. open a window called “stack view” in debug menu: view → call stack (it will appear on the left)
  25. when the program stops, you get the line where the crash occurs, so you can fix the code immediately!

Leave a Reply

Your email address will not be published. Required fields are marked *