Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Modification to buy command
Modification to buy command
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Skaphia
(1 post) Bio
|
Date
| Sun 31 Oct 2004 08:32 PM (UTC) |
Message
| This is my first post here, let me know if I'm posting in the wrong place.
I have been a coder of C/C++ for 3 years, but I stopped using it for 3 years. I've re-read a book of mine, and I can build with C just fine. I understand it perfectly.
My issue is that to get back into the swing of things, I've taken on a pretty simplistic project for SMAUG codebase, which is obviously based in C. In a nutshell, this would be to create a command 'haggle' that would allow a player to 'haggle itemname price' and based on int/cha/lck and some randomization allow the player to either get a lower shop price on that item (for the rest of the shop's hours), or to fail and have ALL store prices go up for the rest of the store's hours.
My problem isn't constructing this in C. My problem is that I have to reference a number of functions to get information from them in order to do this. Character statistics, etc plus the shop commands to update. I'm not sure if this is really a question more than frustration.
If I started from scratch, the simple mathematics of it would be fine. Referencing other functions that are pretty large and confusing to me is my problem, and I'm finding myself unable to really construct it to pull those variables and "do" the command.
Could someone maybe give me a shell on how I might construct this? Feel free to use imaginary function names etc, just so I have an idea of maybe how to approach this better. I think my approach is overwhelming and I'm diving in the middle of the SMAUG codebase | Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 31 Oct 2004 09:36 PM (UTC) |
Message
| I'm not sure what the exact problem is here. It is quite time-consuming to make up a general example of something to solve a fairly undefined problem.
If you illustrate what you have tried, and where it went wrong, it is easier to help.
I've moved your question to "SMAUG coding" because that is what it is really about. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Reply #2 on Sun 31 Oct 2004 09:47 PM (UTC) |
Message
| Well, here is how I would do it.
There is a certain structure to each command, in which you take the characters data and what they put as input, which looks like:
void do_commandname( CHAR_DATA *ch, char *argument )
{
/* command stuff here */
}
Also, in order to add a command, you must add it in tables.c and do something such as DECLARE_DO_FUN( do_haggle ); in mud.h.
In this case, I think a better solution would be this. Modify do_buy and do_sell, and just add in a haggle function. That way you just call it from either do_sell or do_buy, and it automatically haggles.
Here's some code to give you some structure:
int haggle( CHAR_DATA *ch, CHAR_DATA *keeper, OBJ_INDEX_DATA * obj, bool is_selling )
{
int endprice = obj->price;
if ( !ch || !keeper || !obj )
return 100;
if ( ch->pcdata->learned[gsn_haggle] )
{
if ( is_selling == TRUE )
{
/* equations go here */
endprice += (int)(ch->pcdata->learned[gsn_haggle]/10);
if ( get_curr_int(ch) > get_curr_int(keeper) )
endprice += endprice*1.5;
if ( get_curr_lck(ch) > number_range( 5, 50 ) )
endprice += endprice*2;
}
else /* buying */
{
if ( get_curr_cha(ch) > get_curr_wis(keeper) )
endprice = endprice-(endprice*.5);
endprice = endprice-(ch->pcdata->learned[gsn_haggle]/10);
}
}
return endprice;
}
There is a VERY basic example. I wouldnt really support using that function, as it definitely needs a way to balance the cost of things. However, it does illustrate my thinking. The function returns the final cost of the object. But you will need to jump into the do_buy and do_sell code a lot more to get a good haggle function.
To call it from do_buy or do_sell, you just need to do something such as:
For do_buy:
buyprice = haggle( ch, keeper, obj, FALSE );
For do_sell:
sellprice = haggle(ch, keeper, obj, TRUE );
This code is also implying that you added haggle as a skill.
Hopefully that helpped you, maybe it didn't. Good luck :) |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Mirrodan
USA (28 posts) Bio
|
Date
| Reply #3 on Sun 31 Oct 2004 10:04 PM (UTC) |
Message
| I can give ya some advice...as to how to go about starting to look for the variables and functions that are already in place to do what you're asking...
first there's a few files that you'll need to become familiar with...
build.c
mud.h
player.c
save.c
shops.c
traditiondally in smaug most skills/commads start of like so....
void do_mynewcommand(CHAR_DATA * ch, char *argument)
{
arguements blah blah
{
ch-> will access player data or victim-> depending on the type of command/skill....
I'd give ya more but, I'm a little bit tired.. there's just some stuff to go off of...
-Mirrodan
|
Admin and Head Coder
For Techno-Magicka
techno-magicka.dreasphere.org 4000
AIM: tchnmgck
MSN: newell_everett@hotmail.com
YAHOO: everettnewell
| Top |
|
Posted by
| Robert Powell
Australia (367 posts) Bio
|
Date
| Reply #4 on Mon 01 Nov 2004 07:51 AM (UTC) |
Message
| All the different variables for pc's are in mud.h under pc data, and as Mirrodan has aluded to you can access them by ch->varname.
Peace. |
Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
16,571 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top