code suggestion: remove some hard-coded constants

Oct 26, 2017, 4:59 am
#1
Joined: Sep 5, 2010
Posts: 103
as we all know, many things in the engine are hard-coded, both in "ivandef.h", and in "define.dat". as the engine loads "define.dat" early at startup, and keeps it loaded, at least some hardcoded things can be changed to lookups in `game::GlobalValueMap`.

i think that it is most useful for special dungeons/levels, so if someone will want to change dungeon scripts (to make GC longer, for example, by inserting extra levels before Elpuri), it can be done entirely in script file.

also, adding level tags, and HomeLevel for monsters will allow to cleanup their `MustBeRemovedFromBone()` method, effectively replacing all special cases (Jenny, Enner, Elpuri, Oree, etc.) with one general case.

i did it all in my fork, and it seems to work ok. i'm suggesting to do the same in comm. version too. at least don't hardcode dungeon numbers anymore — this will allow authors to tweak (existing for now) dungeons that needs special processing without recompiling the code. i.e. after adding special processing to C++ side once, user will be able to test various dungeon designs without messing with the game sources.
Oct 26, 2017, 5:47 am
#2
Joined: Sep 8, 2010
Occupation: Petty Functionary
Location: Drinking pea soup in the world map
Interests: Mangoes
Posts: 1,192
We ported some features from your version, like splitting the dungeon files etc, but not the complete work.
It would be good to be able to handle 'MustBeRemovedFromBone()' like you did as well. Do you have a list of all the relevant commits on your branch to be able to implement these features?

k8ivan is on a git repository eh? Is it possible to do some git magic to merge things from another repo into GitHub?
Batman? wrote
its been so long since i had gotten that far i didnt think it through. arrrr!!!!!!
Oct 26, 2017, 6:30 am
#3
Joined: Sep 5, 2010
Posts: 103
for global consts, it is basically nothing more than adding this to `game` class:
sLong game::GetGlobalConst (cfestring &name) {
  auto it = GlobalValueMap.find(name);
  if (it == GlobalValueMap.end()) ABORT("Global constant '%s' not found!", name.CStr());
  return it->second;
}

and then replacing various defines in "ivandef.h" with it, like:
/* old: #define ELPURI_CAVE  1 */
#define ELPURI_CAVE  (game::GetGlobalConst("ELPURI_CAVE"))

you may need to replace several switches with `if`s too.


as for `'MustBeRemovedFromBone()`, see these commits:
http://repo.or.cz/k8-i-v-a-n.git/commit/73891ad66d8e339ffef3...
http://repo.or.cz/k8-i-v-a-n.git/commit/51f0feccf887bd97e1a5...

>k8ivan is on a git repository eh? Is it possible to do some git magic to merge things from another repo into GitHub?
i don't think that you will be able to simply merge my changes. first, my coding style is greatly differs from original one, so textual merges will definitely fail. second, my codebase has completely different file layout. third, i did alot of changes in various parts, including felib. not enough to prevent manual patch porting, but enough to confuse git automation. that's why i'm not simply attaching patches to comm. fork — it is impossible to automate this. sorry.


p.s.: i wonder why you didn't took my fork as a base. ok, ok, i never explained what i did with it, so it may be a little confusing. but it has much better modularization ("one file per entity" layout, for example), and reinstantiate windows support was really easy back then. but alas, that ship was sailed. tbh, i never really wanted to "go my own way", but that ship was sailed too. %-)
Oct 26, 2017, 6:47 am
#4
Joined: Sep 5, 2010
Posts: 103
p.s.: you may take a look at `character::GoOn()` too. i can't give you a list of commits to look for, as it is a complete rewrite of the original. but it worth porting, 'cause my `g`o command is smart enough to follow tunnels with turns, stop at "interesting" (read: previously unstepped onto) items, near the doors and before meeting an enemy. i.e. `g`o is really usable.

yet the changes require adding some new methods to various classes, so it will require some reverse-engineering work.
Jump to