Discussion:
custom damage nouns
b***@umd.umich.edu
2006-03-07 07:37:03 UTC
Permalink
Hello List!

Just two quick questions.

1. Even though the ROM is technically written in C, and C (as specified AFAIK)
does not support default values for function arguments, if I am using a recent
version of gcc, can I use default values for function arguments? Sort of the
same way I can use // for comments?

I want to be able to send a string to the damage() (and subsequently to
dam_message()) function to use as an arbitrary attack noun and I do not want to
have to find every call to damage() and tack a ', NULL' on the end for all the
places I'm still using the attack table/skill table damage noun.

I am adding an 'alternate' attack to weapons and I want the damage noun for the
attack to be able to be defined/ changed without having to add to the attack
table so builders could conceivably make hidden weapons for mobs that allows
them to add 'special attacks' easily or to create 'hybrid' type weapons for
players, like a short sword that can both slash and stab but I always want the
second attack noun to be entered manually (at least right now), this ties into
my second question a little.

2. I have extended the number of 'values' on items to ten to make some room for
some different sorts of changes. I would like to use the last value (v9) to
hold some string, should I put this string in single quotes and read it with
fread_word, or can I terminate it with a tilde and read the tenth value as a
string with fread_string? Does fread_string start reading from the place the
file pointer left off or does it read in an entire line? ie. could I put
something like a custom wear-off message in this place or atoi() a number out
of it all the same?


Thanks for your time!

Brian
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
Chad Simmons
2006-03-09 01:41:32 UTC
Permalink
Post by b***@umd.umich.edu
1. Even though the ROM is technically written in C, and C (as specified
AFAIK) does not support default values for function arguments, if I am using
a
Post by b***@umd.umich.edu
recent version of gcc, can I use default values for function arguments? Sort
of the same way I can use // for comments?
No, C doesn't have any ability to default function arguments. You can however
compile it as C++ with only a few changes, and then you'd have no trouble
defaulting the arguments to your function.
Post by b***@umd.umich.edu
I want to be able to send a string to the damage() (and subsequently to
dam_message()) function to use as an arbitrary attack noun and I do not want
to have to find every call to damage() and tack a ', NULL' on the end for all
the places I'm still using the attack table/skill table damage noun.
You could do this with either a preprocessor macro, or a wrapper function. I
prefer the wrapper method as it is less likely to mess with gdb. Just take the
meat from your damage() function and move it to a new function called
custom_damage which takes all the normal arguements you'd pass to damage as
well as this new custom attack noun. Then just have your damage function call
custom_damage and pass it's args and NULL for the last one.
Post by b***@umd.umich.edu
Does fread_string start reading from the place the file pointer left off or
does it read in an entire line?
All the fread functions start reading at the current position in the file
AFAIK.


HTH

~Kender


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
b***@umd.umich.edu
2006-03-14 19:33:34 UTC
Permalink
Post by Chad Simmons
Post by b***@umd.umich.edu
1. Even though the ROM is technically written in C, and C (as specified
AFAIK) does not support default values for function arguments, if I am using
a
Post by b***@umd.umich.edu
recent version of gcc, can I use default values for function
arguments? Sort
of the same way I can use // for comments?
No, C doesn't have any ability to default function arguments. You can however
compile it as C++ with only a few changes, and then you'd have no trouble
defaulting the arguments to your function.
Post by b***@umd.umich.edu
I want to be able to send a string to the damage() (and subsequently to
dam_message()) function to use as an arbitrary attack noun and I do not want
to have to find every call to damage() and tack a ', NULL' on the end for all
the places I'm still using the attack table/skill table damage noun.
You could do this with either a preprocessor macro, or a wrapper function. I
prefer the wrapper method as it is less likely to mess with gdb. Just take the
meat from your damage() function and move it to a new function called
custom_damage which takes all the normal arguments you'd pass to damage as
well as this new custom attack noun. Then just have your damage function call
custom_damage and pass it's args and NULL for the last one.
Thanks for the help. I went with the wrapper method and things seem to be
working out great! Now I just need my builders to start adding these
things to
weapons! I didn't do it exactly like how you describe, I more or less just
duplicated the whole damage function and dam_message function and added my
custom bits; it occurred to me that there had to be a way to consolidate them
but it hadn't occurred to me until I read this. I'll be changing that soon
since my fight.c file seems bloated now (~130k)
Post by Chad Simmons
Post by b***@umd.umich.edu
Does fread_string start reading from the place the file pointer left off or
does it read in an entire line?
All the fread functions start reading at the current position in the file
AFAIK.
Good good, with items having 10 values, in area files I'm reading in the last
value in as a string then depending on the item type I either store it in a
non-type specific char pointer or pass it through atoi and store the value in
'value[9]'.

I think it would probably be 'better' to just leave the 10 values as
numbers and
simply add another text field to area files... but, with OLC no one
really has a
need to look at the area file (except me when I forgot to save the ~ at
the end
of the line when I was first testing things, area file have version
numbers now
so I don't have to deal with that) so I should not have to concern myself with
their format right? Would it make any difference if the string was on its own
line as opposed to the end of another line?

Anyways, thanks a bunch and keep up the good work.

Jaagari
AnimeMUD II (pending name change)
anime2.ipupdater.net 7000
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
Chad Simmons
2006-03-14 20:27:17 UTC
Permalink
Post by b***@umd.umich.edu
Thanks for the help. I went with the wrapper method and things seem to be
working out great! Now I just need my builders to start adding these
things to weapons! I didn't do it exactly like how you describe, I more or
less just duplicated the whole damage function and dam_message function and
added my custom bits; it occurred to me that there had to be a way to
consolidate them but it hadn't occurred to me until I read this. I'll be
changing that soon since my fight.c file seems bloated now (~130k)
Yeah, generally copying code is a bad idea. If there are bugs, you've suddenly
duplicated them, so once they are discovered you'll have to remember to change
them in 2 different places, etc. It just becomes a maintenance nightmare. Much
better to simply call existing functions to do what you need.
Post by b***@umd.umich.edu
Good good, with items having 10 values, in area files I'm reading in the last
value in as a string then depending on the item type I either store it in a
non-type specific char pointer or pass it through atoi and store the value in
'value[9]'.
I don't generally recommend doing this sort of thing, as it becomes difficult
later on to remember the magic formula for how this works. Again maintenance
nightmare. It's much more important to do a little extra work and have
everything be as consistant as possible.
Post by b***@umd.umich.edu
Would it make any difference if the string was on its own line as opposed to
the end of another line?
Same answer. Try to go for consistancy. It will make debugging and updating
much easier in the long term.

HTH,
~Kender

-----BEGIN GEEK CODE BLOCK-----
Version 3.12
GCS/IT/L/S/O d-(+) s++: a-(?) C++++$ UBLS++++$
P+++(--)$ L++++$ E--- W+$ N !o K? w(---) !O
M- !V PS+ PE(-) Y+ PGP->+ t+ 5 X++ R(+) tv+@
b+(++) !DI+++ D G(-) e>+++ h---() r+++ y+++(++)
------END GEEK CODE BLOCK------

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
ROM mailing list
***@rom.org
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
Continue reading on narkive:
Loading...