You can use grep just fine since our codebase is pretty flat, with most relevant files directly in the source directory, but it can be better to use a tool like git grep, which will search any file in the tree automatically and knows how to do things like search for a context function. Here's what git grep shows if you use -p to show the preceding function:
- Code:
$ git grep -p calc_to_hit
attack.cc=bool attack::handle_phase_end()
attack.cc:int attack::calc_to_hit(bool random)
attack.cc=void attack::init_attack(skill_type unarmed_skill, int attack_number)
attack.cc: to_hit = calc_to_hit(true);
attack.h=public:
attack.h: virtual int calc_to_hit(bool random);
melee_attack.cc=void melee_attack::apply_staff_damage()
melee_attack.cc:int melee_attack::calc_to_hit(bool random)
melee_attack.cc: int mhit = attack::calc_to_hit(random);
melee_attack.h=public:
melee_attack.h: int calc_to_hit(bool random = true);
player.cc=static void _display_tohit()
player.cc: const int to_hit = attk.calc_to_hit(false);
ranged_attack.cc=ranged_attack::ranged_attack(actor *attk, actor *defn, item_de*p
roj,
ranged_attack.cc:int ranged_attack::calc_to_hit(bool random)
ranged_attack.cc: orig_to_hit = attack::calc_to_hit(random);
ranged_attack.h=public:
ranged_attack.h: int calc_to_hit(bool random);
The relevant function is attack::init_attack(), since you see:
- Code:
attack.cc=void attack::init_attack(skill_type unarmed_skill, int attack_number)
attack.cc: to_hit = calc_to_hit(true);
You should see the basic output you need if you did grep on *.cc and *.h files, and notice that second line in the output above. Once you have the file you need, it's often best to just open it and search for the relevant terms. You can use -n to print line numbers in grep or git grep output.
So attack::to_hit is where the resulting value is stored, and you'll want to look in attack.cc and melee_attack.cc for instances of to_hit to get further details on how to-hit is actually used. There are instances in both files, but melee_attack.cc will have most of the uses you're interested in.