Commit Graph

48 Commits

Author SHA1 Message Date
nhmall
6c0ae092c6 distinguish global variables that get written to savefile
The g? structs had a mix of variables that were written to
the savefile, and those that were not.

For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.

This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.

Details:

    gb.bases            -> svb.bases
    gb.bbubbles         -> svb.bbubbles
    gb.branches         -> svb.branches
    gc.context          -> svc.context
    gd.disco            -> svd.disco
    gd.dndest           -> svd.dndest
    gd.doors            -> svd.doors
    gd.doors_alloc      -> svd.doors_alloc
    gd.dungeon_topology -> svd.dungeon_topology
    gd.dungeons         -> svd.dungeons
    ge.exclusion_zones  -> sve.exclusion_zones
    gh.hackpid          -> svh.hackpid
    gi.inv_pos          -> svi.inv_pos
    gk.killer           -> svk.killer
    gl.lastseentyp      -> svl.lastseentyp
    gl.level            -> svl.level
    gl.level_info       -> svl.level_info
    gm.mapseenchn       -> svm.mapseenchn
    gm.moves            -> svm.moves
    gm.mvitals          -> svm.mvitals
    gn.n_dgns           -> svn.n_dgns
    gn.n_regions        -> svn.n_regions
    gn.nroom            -> svn.nroom
    go.oracle_cnt       -> svo.oracle_cnt
    gp.pl_character     -> svp.pl_character
    gp.pl_fruit         -> svp.pl_fruit
    gp.plname           -> svp.plname
    gp.program_state    -> svp.program_state
    gq.quest_status     -> svq.quest_status
    gr.rooms            -> svr.rooms
    gs.sp_levchn        -> svs.sp_levchn
    gs.spl_book         -> svs.spl_book
    gt.timer_id         -> svt.timer_id
    gt.tune             -> svt.tune
    gu.updest           -> svu.updest
    gx.xmax             -> svx.xmax
    gx.xmin             -> svx.xmin
    gy.ymax             -> svy.ymax
    gy.ymin             -> svy.ymin

Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
          gf.ftrap, gl.light_base, gt.timer_base
2024-07-13 14:57:50 -04:00
nhkeni
9c0ed8ae63 NOSTATICFN for src/* 2024-03-14 17:41:51 -04:00
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
nhmall
2542f9bada follow-up correction 2023-12-22 11:42:19 -05:00
nhmall
c1fc52e644 assess write.c static functions for nonnull 2023-12-22 10:38:38 -05:00
PatR
c41cb1a7fa source reformatting
Fixup some of the inconsistently formatted code that has been
introduced recently or been building up for a while.  Done manually.
I wasn't systematic except for looking for lines ending in '&' or '|'
(which wouldn't find such things if they're followed by a comment)
so there might be lots more.  I changed a bunch of C++-style //...
comments to old style C /*...*/ so that they'll match the rest of
the core's code rather than because they shouldn't be used.
2023-12-08 00:30:10 -08:00
Alex Smith
319dfbdaa3 Wizards learn about spellbooks as they enhance their spell skills
Previously, Wizards got a boost to the chance of writing unknown
spellbooks based purely on being a Wizard (with the chance still
luck-based), leading to a very large power spike when the Wizard
gained access to a luckstone and the ability to max out luck.
This had two main issues: this power spike came *after* the major
early-game difficulty spike, often leaving Wizards forced to deal
with it without having appropriate spells; and it promotes
grinding (for Luck and for Magicbane) at an early point in the
game, meaning that the Wizard early game effectively followed a
sequence of extreme difficulty -> grinding -> minimal difficulty,
which isn't very good balance-wise.

With this commit, Wizards lose their advantage to writing unknown
spellbooks by guessing, and instead learn spellbook IDs based on
their spell skills (advancing a skill gives knowledge of higher-
level spellbooks). This means that writing unknown spellbooks
becomes guaranteed with sufficient skill, but has no advantage
over non-Wizards in schools where the Wixard does not have
sufficient skill.

Due to Wizards' skill caps, there are two spells which they can't
ever write guaranteed: create familiar and charm monster. Create
familiar is a fairly niche spell (that doesn't match the Wizard
playstyle that well) and being unable to write it is not a major
problem. The inability to easily write charm monster is
intentional.
2023-12-02 03:46:55 +00:00
vultur-cadens
72213bf48f writing an unknown spellbook when the spell is known
Allow hero to write an unknown spellbook if the spell is freshly known
(from divine knowledge).  If the spell is going stale, the chance of
successfully writing the spellbook depends on Luck, but only rnl(5)
(like a Wizard) instead of rnl(15).  Forgotten spells do not help when
writing unknown spellbooks.
2023-07-07 12:13:52 -07:00
nhmall
02a48aa8cf split g into multiple structures
The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.

It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.

Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.

A global variable named 'amulets', would be found in ga.
    ga.amulets
     ^ ^
A global varable named 'move', would be found in gm.
    gm.moves
     ^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
    gv.val_for_n_or_more
     ^ ^
A global variable named 'youmonst' would be found in gy.
    gy.youmonst
     ^ ^
2022-11-29 21:53:21 -05:00
nhmall
17fe18d18a Merge branch 'fix-write-named-scroll' of https://github.com/entrez/NetHack into pr551 2022-05-27 16:35:30 -04:00
PatR
87749392b0 more writing novels
Instead of always retaining a blank spellbook when failing to write a
novel, make 2/3 chance to retain and 1/3 chance to destroy.  Same odds
(but separate chance) to attempt to write the Great Yendorian Novel
versus awful fan fiction.
2022-05-13 16:47:00 -07:00
Michael Meyer
92999914c8 Prevent hero from writing Pratchett books
The hero's ability to channel Pratchett and write his books with a magic
marker once she had read or IDed at least one of them seemed strange,
especially cases like an illiterate hero doing it as her first
introduction to the written word.  Block the hero from writing random
novels with a marker.

The image of the hero sitting down in the dungeon to write a novel is
funny, so it feels like a good spot for a funny message.  I'm not
sure if what I have there is perfect, but it can always be changed.
2022-05-13 16:01:04 -07:00
Pasi Kallinen
1e90f89203 Chronicle of major events, and livelog
Log game events, such as entering a new dungeon level, breaking
a conduct, or killing a unique monster, in a new "Major events"
chronicle. The entries record the turn when the event happened.
The log can be viewed with #chronicle -command, and the entries
also show up in the end-of-game dump, if that is available.

This feature is on by default, but can be disabled by
defining NO_CHRONICLE compile-time option.

This also contains "live logging", writing the events as they
happen into a single livelog-file. This is mostly useful for
public servers. The livelog is off by default, and must be
compiled in with LIVELOG, and then turned on in sysconf.

Mostly this a version of livelogging from the Hardfought server,
with some changes.
2022-02-09 22:49:25 +02:00
Pasi Kallinen
68b822e4dc Add "user canceled" as extended command return value
Instead of returning ECMD_OK, the commands now return ECMD_CANCEL
when user declined to pick a direction or an object to act on.

Note that this can be ORed with ECMD_TIME, if the command still
took a turn.

For now this has no gameplay meaning.
2022-01-08 20:04:57 +02:00
Pasi Kallinen
d53cd28d46 Make extended commands return defined flags
Instead of returning 0 or 1, we'll now use ECMD_OK or ECMD_TURN.
These have the same meaning as the hardcoded numbers; ECMD_TURN
means the command uses a turn.

In future, could add eg. a flag denoting "user cancelled command"
or "command failed", and should clear eg. the cmdq.

Mostly this was simply replacing return values with the defines
in the extended commands, so hopefully I didn't break anything.
2021-12-30 19:16:33 +02:00
PatR
6ae05df1c3 more reformatting - label placement
Indent all labels one space.  Having uniform placement makes spotting
them much easier.  (Having no indent at all would impact the change
bars of 'git diff'.  Those display the last unindented line--which
doesn't start with punctuation--occuring before each band of changes,
so usually the name of the function being changed now that we no
longer have unindented K&R-style function argument declarations.)

While in there, shorten or split various wide lines and replace a few
tabs with spaces.
2021-12-16 15:56:52 -08:00
Michael Meyer
c9cef70d51 Writing scrolls by type-name followup
Don't allow type-name of a scroll that has since been formally
identified to override a real scroll name.

For example, if a user typenames a scroll of fire 'earth', then IDs
fire but doesn't change the typename (reasonable, since it doesn't show
up anywhere in inventory at that point), if they try to write 'earth'
with a magic marker, don't produce a scroll of fire just because it's
still type-named 'earth'.  At that point they know it's not a scroll of
earth and it's no longer reasonable to assume they mean to use the
typename.

In other words, if a user-assigned typename matches a real scroll type,
write the scroll with the typename -- unless the player knows for sure
it doesn't match the actual scroll (whether because the actual scroll is
already IDed, or the typenamed scroll has been IDed as something else).
In that case write (or attempt to write) the actual scroll as though the
typename didn't exist.
2021-10-28 17:18:20 -04:00
Michael Meyer
a41176d22b Fix #436: writing type-named scrolls
When using a marker, it is possible to write a scroll based on the
type-name assigned to it by the user.  Somewhat unintuitively, this
system broke down if the assigned name was identical to the real name of
a scroll type: trying to write a scroll by its previously-assigned name
'scare mon' or 'id' would be guaranteed to succeed, but this wouldn't be
the case if the user-assigned name was 'scare monster' or 'identify'.

Revise dowrite(write.c) to prefer a user-assigned type-name to the
real name of a scroll that isn't already formally known, while
continuing to prefer the real name of an identified scroll to both.

Fixes #436
2021-07-20 15:03:26 -04:00
nhmall
f963c5aca7 switch source tree from k&r to c99 2021-01-26 21:06:16 -05:00
Dean Luick
f63d435c6d Fix text replacement warning
Using strncpy to cut off copying a terminating NUL yields a gcc
warning.  Just use memcpy instead.
2021-01-20 22:37:37 -06:00
copperwater
0b638592a4 Refactor getobj() to use callbacks on candidate objects
This replaces the arcane system previously used by getobj where the
caller would pass in a "string" whose characters were object class
numbers, with the first up to four characters being special constants
that effectively acted as flags and had to be in a certain order.
Because there are many places where getobj must behave more granularly
than just object class filtering, this was supplemented by over a
hundred lines enumerating all these special cases and "ugly checks", as
well as other ugly code spread around in getobj callers that formatted
the "string".

Now, getobj callers pass in a callback which will return one of five
possible values for any given object in the player's inventory. The
logic of determining the eligibility of a given object is handled in the
caller, which greatly simplifies the code and makes it clearer to read.
Particularly since there's no real need to cram everything into one if
statement.

This is related to pull request #77 by FIQ; it's largely a
reimplementation of its callbacks system, without doing a bigger than
necessary refactor of getobj or adding the ability to select a
floor/trap/dungeon feature with getobj. Differences in implementation
are mostly minor:
- using enum constants for returns instead of magic numbers
- 5 possible return values for callbacks instead of 3, due to trying to
  make it behave exactly as it did previously. PR #77 would sometimes
  outright exclude objects because it lacked semantics for invalid
  objects that should be selectable anyway, or give slightly different
  messages.
- passing a bitmask of flags to getobj rather than booleans (easier to
  add more flags later - such as FIQ's "allow floor features" flag, if
  that becomes desirable)
- renaming some of getobj's variables to clearer versions
- naming all callbacks consistently with "_ok"
- generally more comments explaining things

The callbacks use the same logic from getobj_obj_exclude,
getobj_obj_exclude_too and getobj_obj_acceptable_unlisted (and in a few
cases, from special cases still within getobj). In a number of them, I
added comments suggesting possible further refinements to what is and
isn't eligible (e.g. should a bullwhip really be presented as a
candidate for readying a thrown weapon?)

This also removed ALLOW_COUNT and ALLOW_NONE, relics of the old system,
and moved ALLOW_ALL's definition into detect.c which is the only place
it's used now (unrelated to getobj). The ALLOW_ALL functionality still
exists as the GETOBJ_PROMPT flag, because its main use is to force
getobj to prompt for input even if nothing is valid.

I did not refactor ggetobj() as part of this change.
2021-01-07 11:06:58 -05:00
nhmall
ac9ba38449 file header bump from "NetHack 3.6" to "NetHack 3.7" 2020-08-03 22:07:36 -04:00
nhmall
641eeeab49 Merge branch 'NetHack-3.6' 2019-11-09 21:50:18 -05:00
PatR
15dbf661d9 more slippery gloves
Move makeplural(body_part(FINGER)) into its own routine, with option
to substitute gloves when wearing such.

Wearing slippery gloves (ie, wearing gloves while having slippery
fingers) wouldn't let you put on a ring because you can't take the
gloves off, but removing a worn ring lacked the same restriction.

After changing that, teach prayer that slippery gloves is another
reason why a ring of levitation can't be removed.
2019-11-09 16:36:41 -08:00
nhmall
75d22a2dbf separate MAIL functionality from MAIL-related structure inclusion
With 3.7+ aspirations of improving savefile interoperability between 32-bit
and 64-bit builds, as well as between platforms, it is better to not have
the underlying struct/array content be conditional.

This splits off some of the MAIL code into MAIL_STRUCTURES code. In theory,
since MAIL_STRUCTURES is unconditionally included, the macro could
just go away and leave that code unconditional, but this commit doesn't
go that far.
2019-11-09 16:19:05 -05:00
nhmall
0d34f43830 remove STATIC_DCL, STATIC_OVL, STATIC_VAR, STATIC_PTR from core 2019-07-14 17:24:58 -04:00
Bart House
8c1a4d9a97 invent, youmonst, hackdir moved to g. 2018-12-24 21:04:15 -08:00
Bart House
74edf42f1c Moved decl.c globals into instance globals. 2018-12-22 18:44:22 -08:00
Bart House
576eece500 More globals moved to instance_globals. 2018-12-19 21:26:35 -08:00
Pasi Kallinen
94ad7512a6 Compile-time option to allow some prompts remember the input
Define EDIT_GETLIN to make the tty, X11, and Qt4 windowports to
remember the input strings for wishing and annotation.
2018-03-26 23:04:53 +03:00
PatR
862d37c77a more recovered bits
Some worthwhile stuff from abandoned 'git stash':
 is_plural() macro wasn't comprehensive;
 a couple of return values where writing with a magic marker was
   causing time to elapse even though nothing happened;
 comment formatting for saddle being left in shop by dying steed.
2016-03-25 17:26:37 -07:00
PatR
af6887796f scrolls written while blind; scrolls of mail
Make a fix suggested during beta testing:  you can read scrolls while
blind if you know the label, and you can write a scroll with a magic
marker while blind, but the result was flagged as description unknown
so you couldn't read the newly written scroll until regaining sight
or obtaining object identification.  So change writing a previously
discovered scroll while blind to set dknown since a successful write
always yields the type of scroll requested.  Getting lucky while
attempting to write an undiscovered scroll--which has to be done by
scroll's type name (for instance "food detection") rather than by its
label ("YUM YUM")--still leaves the description flagged as unknown
since hero hasn't seen the what sort of label the new scroll has.

Along the way I got side-tracked by the possibilty of writing a scroll
of mail.  It's allowed and yielded the same result as finding such a
scroll in bones, or wishing for one:  when read, it was junk mail from
Larn.  Make one written via marker give different feedback since it
comes from creation of a stamped scroll without any stamps available.

Also, suppress an "argument not used" warning for readmail().
2015-12-16 02:23:32 -08:00
PatR
a447534b2f formatting: src/t*.c - z*.c continuation lines
End of first pass, but '[&|?:][ \t]*$' doesn't catch trailing operater
followed by end-of-line comment so more needs to be done.  As with the
past couple of batches, I've removed redundant parentheses from 'return'
statements but only for files that had continuation fix-ups.

I've also removed tabs from comments in some of the files, but didn't
start until part way through this subset of the sources.
2015-10-28 17:33:38 -07:00
PatR
80ca4e9837 novel bit
Feedback phrasing:  don't refer to a novel as a "spellbook" when
rejecting the attempt to write on one with a magic marker.
2015-09-14 17:18:05 -07:00
PatR
2b2ee0fbab formatting fixup (1 of 2)
Replace instances of strings split across lines which rely on C89/C90
implicit concatenation of string literals to splice them together
with single strings that are outdented relative to the code that uses
them.  It's uglier but it won't break compile for pre-ANSI compilers.

This covers many files in src/ that only have one or two such split
strings.  There are several more files which have three or more.  Those
will eventually be '(2 of 2)'.

Noticed along the way:  the fake mail message/subject
  Report bugs to devteam@nethack.org.
wasn't using its format string of "Report bugs to %s.", so would have
just shown our email address.  Doesn't anybody enable fake mail anymore?

I modified that format to enclose the address within angle brackets and
made a similar change for the 'contact' choice of the '?' command.
2015-07-12 19:35:06 -07:00
Sean Hunt
1c081b1647 Remove stale version control lines. 2015-05-25 09:21:31 +09:00
Sean Hunt
97d6fade74 Reformat all C files.
I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
2015-05-09 13:43:16 -04:00
karnov
2a907f894e Version number increment 2015-05-06 22:04:27 -04:00
keni
03140969ee Bulk recovery of file CVS headers and addition of NHDT- headers. 2015-02-26 09:19:03 -05:00
cohrs
8a5ff16e99 gcc warning 2010-12-28 19:54:41 +00:00
nethack.rankin
fefeda5422 fix #H2161 - writing scrolls based on description (trunk only)
From a bug report, you could write scrolls
by type name ("magic mapping") if you had that type of scroll in your
discoveries list via assigning a name to an unknown scroll ("scroll
labeled FOOBIE BLETCH called foo").  Being on that list was enough to
treat the type as known when writing scrolls and books.  And he fealt
that it was abusive to be able to collect and name a lot of unknown
scrolls and then write favorite ones which had good odds of being in the
collected set.

     This changes it to the original intent:  if your discoveries list
has FOOBIE BLETCH on it, you can write a scroll by that label (since we
decided way back when that a scroll's label was its magic, to explain how
a blind hero can read any scroll whose description is known even though
they aren't constructed in braille).  If you have identified the type
("scroll of magic mapping labeled FOOBIE BLETCH") then you can write by
type or by description, but you can no longer write one by type when only
the description is known.  There is a potential can-of-worms bug here:
if you walked across a "scroll labeled YUM YUM" but have not assigned it
any name, you've still learned its magic words and ought to be able to
write a scroll of YUM YUM.  We don't have any mechanism to track items
which have been observed but not been put on the discoveries list.  This
patch plugs one obvious hole, by scanning inventory to treat any seen
scroll labels there as an extension of the discoveries list.  But the
more general case of something once seen but not named or currently held
is ignored.

     This also adds writing scrolls by the user-assigned name, so if
your discoveries list has "scroll labeled FOOBIE BLETCH called foo" you
can write either foo or FOOBIE BLETCH to get the scroll.  I'm not sure
the bug report advocated that--parts of it were a bit confusing, at
least to me--and I'm not completely sure that we want to have it, but it
does work.  Without it, you got "no such thing as \"foo\"", which seems
counter-intuitive when "foo" is there in plain sight on your discoveries
list.  The new code chooses randomly if multiple scrolls have been called
"foo".  And if you've called something by an actual object name, it uses
your knowledge of that object rather than anything you've given its name
to.  In other words, if you have "scroll labeled YUM YUM called magic
mapping" and try to write magic mapping, it will use your knowledge--or
lack of same--about scroll of magic mapping rather than scroll labeled
YUM YUM to decide whether you'll succeed.

     There is also a minor tweak in the chance to write a completely
unknown scroll or book.  Wizards almost never failed once their Luck was
5 or more; using rnl(5) instead of rnl(3) requires Luck 11 rather than
just 5 to get that ~39/40 chance of success.  Non-wizards didn't change.

     Lastly, this fixes an unrelated bug when writing spellbooks.  The
message "the spellbook warps strangely, then turns <new description>"
works okay when <new description> is "red" or even "ragged", but not so
well when it's "vellum".  A handful of book descriptions refer to the
item composition rather than the appearance of the cover, and turning
into a new composition needs different phrasing.  I just tweaked it to
be "turns into vellum", which is probably suboptimal (particularly for
the book description "cloth" :-).
2010-08-14 00:31:59 +00:00
nethack.rankin
403dd4ef95 fix #H2059 - writing spellbooks while blind
From a bug report, you could write a
spellbook with a magic marker while blind and were told the description
(often a color) of the resulting book.  This prevents books from being
written while blind, just as they can't be read in that situation, and
it adds an extra test when attempting to write scrolls while blind.
(When you succeed in writing a scroll while blind, you're just told that
the result is ``x - a scroll'' as it's moved to its new inventory slot.)

     This also removes a couple of overly hyper exclamations when writing
fails.  Someday somebody ought to go through the whole program and decide
which messages actually warrant exclamation points, but I doubt that
that'll ever happen.
2009-12-14 23:46:30 +00:00
keni
4eabcee787 Add RCS version lines 2009-05-06 10:50:32 +00:00
nethack.allison
5fa8f73af8 housekeeping: mark trunk sources 3.5 (src) 2005-01-02 16:44:46 +00:00
cohrs
bcf47b7663 missing altar drop messages
Most callers of dropx did not check for altars, but should have.  Rather
than add such checks, I moved the check from drop to dropx.  I also found
several callers of dropx that could generate out-of-order messages for some
cases (not new) and fixed them. FYI - callers of dropy don't seem to want
altar checks or already do them.
2002-12-17 03:36:42 +00:00
cohrs
aac7f717c2 verb agreement
add and use new APIs, Tobjnam, otense and vtense, is_plural
to determine tense/form of verbs and a few pronouns as well
2002-02-09 00:30:33 +00:00
nethack.allison
742e1e8c90 3.3.2 to 3.4.0 2002-02-04 16:11:00 +00:00
jwalz
e754e5c561 *** empty log message *** 2002-01-05 21:05:53 +00:00