Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old July 11, 2018, 16:11   #1
whiterhino123
Rookie
 
Join Date: Jul 2018
Posts: 4
whiterhino123 is on a distinguished road
Reading C code

So i've read

http://www.thangorodrim.net/developm...ing-guide.html

but I was actually hoping for something more involved?

Whats a good C++ source (book probably?) that can help me understand the logic behind the source code of angband?


is there a more indepth guide to understanding angbands code?
whiterhino123 is offline   Reply With Quote
Old July 11, 2018, 22:09   #2
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 9,022
Derakon is on a distinguished road
First off, just to clarify: Angband is written in C, not C++.

Second, what kinds of things are you having trouble with? Do you know how to code? If not, that's where you should start. If you want to know where something specific is (e.g. "where are spells defined" or "how do I change the monster AI") then just go ahead and ask your more specific questions.

If you want to figure out overall how the program works, then my advice would be to come up with some of those more specific questions, and try to figure them out. The usual way I do this is to find some in-game text that seems to be close to what I want to work on, and then search the code for that text, or a snippet of it. That should get me close to where I want to be, and then I just start tracing the program logic from there.
Derakon is offline   Reply With Quote
Old July 11, 2018, 22:41   #3
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,769
Donated: $40
Pete Mack will become famous soon enough
Kernighan and Richie is of course the classic. For basic programming design, it's hard to beat Design Patterns. (Some of them are used in Angband, and it really helps if you can recognize the general technique. There are some patterns that are not in the book, e.g. 'group join', which is used in the knowledge menu.)
Pete Mack is offline   Reply With Quote
Old July 12, 2018, 08:38   #4
fph
Veteran
 
Join Date: Apr 2009
Location: Pisa / DL0
Posts: 1,023
fph is on a distinguished road
In any case, look for a book on C, not C++. C++ is a rabbit hole that goes as deep as the center of the Earth.
__________________
Dive fast, die young, leave a high-CHA corpse.
--
You read a scroll labeled 'lol gtfo' of Teleport Level.
fph is offline   Reply With Quote
Old July 12, 2018, 20:46   #5
OmniNegro
Rookie
 
Join Date: Jul 2014
Posts: 17
OmniNegro is on a distinguished road
While this is for C++, if you want to learn, this site is probably one of the best I know of. (And free.)
www.learncpp.com
OmniNegro is offline   Reply With Quote
Old July 12, 2018, 22:47   #6
whiterhino123
Rookie
 
Join Date: Jul 2018
Posts: 4
whiterhino123 is on a distinguished road
i have a hard time understanding why the folders are there and what they do in the games source code

all i know about programming i know from some javascript

i know functions,assignment operators,loops,objects

and i think struct in c/ c++ is just a way to create an object?

thats just my guessing

Code:
struct account {
   int account_number;
   char *first_name;
   char *last_name;
   float balance;
};
var account = {
   account: undefined,
   first_name: undefined,
   last_name: undefined,
   balance: undefined
};
these look very similar, which is why im thinking structs are very similar to objects

Code:
bool feat_is_magma(int feat)
{
	return tf_has(f_info[feat].flags, TF_MAGMA);
}
so this is a bool function that can only return true or false.

and this function is returning another function, taking the parameters of the first function (feat) and passing it and TF_MAGMA, into the inner function.

but Id like to be able to see where the tf_has function is defined, but I dont know which folder to find it in, say, lib, or scripts or src

Last edited by whiterhino123; July 12, 2018 at 22:53.
whiterhino123 is offline   Reply With Quote
Old July 13, 2018, 00:40   #7
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,769
Donated: $40
Pete Mack will become famous soon enough
What OS are you on? You can find the definition for this function via grep on Linux, or on Windows if you have the unix tools installed (mingw or cygwin.) Windows PowerShell has it too, though the command is different. The function is declared in one or another .h file. The C file will have the corresponding definition. And you really need to look up how C works. I strongly recommend Kernighan and Ritchie. It is short and gets all the basics. Warning: C is Not object oriented. All functions are static. You can create "true" objects only with function pointers, which is done in a number of locations in Angband (Notably, in menus, spells, and commands.)
Pete Mack is offline   Reply With Quote
Old July 21, 2018, 16:53   #8
whiterhino123
Rookie
 
Join Date: Jul 2018
Posts: 4
whiterhino123 is on a distinguished road
thanks Pete, Could you explain how I'd find the definition with those tools?

I can search in windows for tf_has function, but that still pulls up a lot of files that have the function, meaning I still have to filter through all the files to see where it is declared, rather than called.

Would grep or mingw do something differently?
whiterhino123 is offline   Reply With Quote
Old July 21, 2018, 17:18   #9
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,769
Donated: $40
Pete Mack will become famous soon enough
Look at the .h files only. That is where functions are "declared", which makes them accessible from other files. So if function foo is defined in bar.c, it will be declared in bar.h
To find it:

$ grep -l "foo" *.h #note: grep -l just lists files where it is present.
bar.h
$ <edit> bar.c
or the Windows equivalent.
Pete Mack is offline   Reply With Quote
Old July 21, 2018, 20:23   #10
AnonymousHero
Veteran
 
AnonymousHero's Avatar
 
Join Date: Jun 2007
Posts: 1,391
AnonymousHero is on a distinguished road
I would suggest trying QtCreator or a similar IDE. Then you can Ctrl-click to "go through" any function/typedef/etc. you see.

(I mean Pete's method sort-of works, but it's incredibly cumbersome for commonly used "names" and it's pointlessly tedious.)
AnonymousHero is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
crash on reading unknown scroll quarague Development 7 September 6, 2016 20:41
Reading Silmarillion Bowman Idle chatter 53 January 29, 2016 20:20
?Acquirement location of reading revisited Ingwe Ingweron Vanilla 5 October 20, 2014 13:56
Reading scrolls from inventory menu Ingwe Ingweron Vanilla 1 October 22, 2013 12:42
strange C code in Angband (am I reading this right?) will_asher Idle chatter 3 February 4, 2008 09:07


All times are GMT +1. The time now is 22:58.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.