Author Topic: Forge Daemon/Verb... assistance needed  (Read 10095 times)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #15 on: February 18, 2008, 09:09:11 pm »
I noticed the missing semi colon and replaced it, I forgot to update that here.. sorry.

What is the proper way to define mappings in this .h file?

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #16 on: February 18, 2008, 09:43:32 pm »
I'm not sure you gain much by defining it in an .h file.

I'd keep it in the body of the .c file.

For how to use mappings, see: help mappings

And also: http://dead-souls.net/ds-creator-faq.html#2.51

-Crat

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #17 on: February 19, 2008, 05:13:18 pm »

Hmm.  So confused!

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #18 on: February 19, 2008, 05:26:58 pm »
It's because jenny's variables get saved, but
ExternalDesc is a function for her, and so
it winds up getting set to 0 whenever she
is cloned. It's a fairly unusual situation. Most
npc's don't save state.

It'll be fixed in the next release. ExternalDesc in
/lib/events/look.c will be static.

Thanks for the heads up!

-Crat

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #19 on: February 19, 2008, 05:28:14 pm »
Erm...I should get around to fixing that edit thing, huh.

The correct reply was this:

:(

-Crat

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #20 on: February 19, 2008, 07:40:34 pm »

Hah.  I was going to say, that response made me even more confused.

I feel as if I properly defined the mapping in the .c file, do I need anything at all in the .h file?  Do I even really need it?

Ugh.

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #21 on: February 20, 2008, 08:22:00 am »
Quote
Hmm.  So confused!

I'm not really a fan of debugging someone's entire
file to get it to work, but in this case it's easier than
pointing out the problems piecemeal, since that
would take another couple of weeks.

Code: [Select]
#include <lib.h>
#include <save.h>
#include <privs.h>

#ifndef SAVE_FORGES
#define SAVE_FORGES DIR_SECURE_SAVE "/forges"
#endif

inherit LIB_DAEMON;

/* This is NOT an example of how to make a forge daemon.
 * This is an example of how to initialize a mapping
 * such that it does not error and such that it
 * makes some logical sense.
 *
 * I don't know exactly how you're visualizing the data for
 * your forges, or how they're supposed to work. I'm setting up
 * a sample mapping here that assumes you'll be storing the
 * data in the form of "what are the components for finished
 * products?" and "how much of those components are required?"
 * Here you see that a knife requires 50 steel, 10 wood, and 5 leather.
 * The units are just to illustrate quantity handling, I have no
 * idea (nor really do I want to know) the nature of your amounts.
 *
 * Therefore a query for "knife" in GetForgeRequirements() would return this:
 * ([ "steel" : 50, "wood" : 10, "leather" : 5 ])
 *
 * Internally to the object, that mapping above lives here:
 * Forges["requirements"]["knife"]
 *
 * Another way to write it is:
 * Forges["requirements"]["knife"] = ([ "steel" : 50, "wood" : 10, "leather" : 5 ]);
 *
 * I don't understand the idea behind the components element, but
 * I'm including it here since your original data set includes it.
 *
 */

private mapping Forges = ([
  "requirements" : ([ "knife" : ([ "steel" : 50, "wood" : 10, "leather" : 5 ]) ]),
  "components" : ({ "steel", "iron", "bronze", "copper", "wood", "leather" }),
]);

static void create() {
    daemon::create();

    if( unguarded((: file_size(SAVE_FORGES __SAVE_EXTENSION__) :)) > 0 )
        unguarded((: restore_object(SAVE_FORGES) :));

    if (!Forges) Forges = ([]);
}

static private void validate() {
    if( !((int)master()->valid_apply(({ PRIV_ASSIST }))) )
        error("Illegal attempt to modify forge data");
}

mixed GetForgeRequirements(string str){
    if(!Forges["requirements"][str]) return 0;
    return Forges["requirements"][str];
}

string array GetForgeComponents(string str){
    return Forges["components"];
}

/* I haven't really messed with the function below because I
 * don't want to get involved in how you're parsing
 * your config files. You'll eventually need to work out
 * string manipulation, it might as well be now.
 * I've only poked at it so it doesn't error.
 *
 * You'll need to go over the logic of it because it's
 * not doing what I think you want it to. For example,
 * it doesn't seem to be actually setting anything
 * in the Forges mapping.
 */

void AddForge(string file, int player) {
    string forge, requirements, components, test_string;
    int x, y, z;

    validate();
    if( !file_exists(file) ) error("No such file: " + file);
    forge = last_string_element(file,"/");

    foreach(string line in explode(read_file(file),"\n")){
        test_string = first_string_element(line," ");
        if(!test_string || !sizeof(test_string)) test_string = line;

        switch(test_string) {

        case "REQUIREMENT":
            requirements = replace_string(line, "REQUIREMENT ", "");
            return Forges["requirements"];
            break;

        case "COMPONENT":
            components = replace_string(line, "COMPONENT ", "");
            return Forges["components"];
            break;

        case "FORGE":
            forge = replace_string(line, "FORGE ", "");
            if( Forges[forge] ) error(forge+": Forge item already exists");
            break;

        default:
            break;
        }
    }

    save_object(SAVE_FORGES);
}

void RemoveForge(string forge) {
    validate();
    map_delete(Forges, forge);
    if(!Forges[forge])
        save_object(SAVE_FORGES);
}

You know I like you and want to encourage you, etc, so
I won't beat around the bush with excessive courtesy.

The main problem is that you're leaping directly into relatively
complicated data manipulation with very little groundwork
leading up to it. It's like skipping multiplication in school
and heading straight for algebra.

That's fine if you're up to the challenge of brute forcing
stuff into your brain without doing the homework first, but
chances are you're going to wind up with code that
doesn't update and you have no idea what it would look
like in a working form, because you don't understand
the principles behind how the working structure would operate.

I'm presenting your code to you in a form that updates, not
because it fixes your problem, but because it at least now
provides you a stepping stone toward understanding how
mappings work in relation to your forge idea.

At this point, you need to study why it does what it does, figure
out why the Set function doesn't change anything, and
make it so that it does.

-Crat


Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #22 on: February 20, 2008, 03:09:59 pm »
file_size(SAVE_FORGES __SAVE_EXTENSION__)
Why does this work? Does it?
man file_size is pretty clear that it takes only one arg.

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #23 on: February 20, 2008, 04:22:04 pm »
Quote
file_size(SAVE_FORGES __SAVE_EXTENSION__)
Why does this work? Does it?
man file_size is pretty clear that it takes only one arg.

It's one string argument.

-Crat

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #24 on: February 20, 2008, 05:08:21 pm »
Thanks Crat, I appreciate your input..  my confusion is, in part, that I wasnt sure how to use a daemon to do this.  I do understand, in part, that the data for each object that can be forged needs to be stored somewhere setting that up.

I was, and am, a little confused on where ALL of the data for say "knife" should be stored.  Should it be stored in the verb with a shell in the daemon? Is it better to store it all in the daemon?

Does that make sense too?

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #25 on: February 20, 2008, 05:13:59 pm »
Quote
Is it better to store it all in the daemon?


That's really the point of a daemon...a central repository of
mud-wide data and arbiter of related calculations.

-Crat

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #26 on: February 20, 2008, 05:35:26 pm »

That was my feeling, but I've had a lot of different advice from people and in many ways I've gotten all backwards on how to do this.

Thanks for the answer, I work a lot better seeing an actual example than I do talking theory or application.  I never did very well, in any field, the other way.   :-\

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #27 on: February 20, 2008, 05:43:56 pm »

Now that I have an understanding of what to put in the daemon, this is what I am thinking...

In the daemon I'll store everything for each object that can be forged....then in the forge skill/verb I can create an ifcheck that checks for the requisit associated skill.. ie.. forging swords for swords AND then tie in sword to sword.c from /lib/domains/standard/weap...

Is that the best way to go?

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Forge Daemon/Verb... assistance needed
« Reply #28 on: February 20, 2008, 06:20:10 pm »
Quote
In the daemon I'll store everything for each object that can be forged....then in the forge skill/verb I can create an ifcheck that checks for the requisit associated skill.. ie.. forging swords for swords AND then tie in sword to sword.c from /lib/domains/standard/weap...

Is that the best way to go?

Assuming I understand you, yes, it sounds like you've got the right idea there.

-Crat

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: Forge Daemon/Verb... assistance needed
« Reply #29 on: February 22, 2008, 03:30:00 pm »
Ok, I undstand what's going on here.. however.. in trying to make two different types of forgeable weapons I came across this syntax error and I cant quite beat it:

Code: [Select]
#include <lib.h>
#include <save.h>
#include <privs.h>

#ifndef SAVE_FORGES
#define SAVE_FORGES DIR_SECURE_SAVE "/forges"
#endif

inherit LIB_DAEMON;

/*
 * Therefore a query for "knife" in GetForgeRequirements() would return this:
 * ([ "steel" : 50, "wood" : 10, "leather" : 5 ])
 *
 * Internally to the object, that mapping above lives here:
 * Forges["requirements"]["knife"]
 *
 * Another way to write it is:
 * Forges["requirements"]["knife"] = ([ "steel" : 50, "wood" : 10, "leather" : 5 ]);
 *
 */

private mapping Forges = ([
  "components" : ([ "silver sword" : ([ "steel" : 10, "silver" : 5 ])]),
                 ([ "emerald dagger" : ([ "steel" : 5, "emerald" : 1 ])])


                 ]);

static void create() {
    daemon::create();

    if( unguarded((: file_size(SAVE_FORGES __SAVE_EXTENSION__) :)) > 0 )
        unguarded((: restore_object(SAVE_FORGES) :));

    if (!Forges) Forges = ([]);
}

static private void validate() {
    if( !((int)master()->valid_apply(({ PRIV_ASSIST }))) )
        error("Illegal attempt to modify forge data");
}

mixed GetForgeComponents(string str){
    if(!Forges["components"][str]) return 0;
    return Forges["components"][str];
}




Quote
> update forge.c
/daemon/forge.c line 28: syntax error
   
/daemon/forge.c line 36: Illegal LHS
   
/daemon/forge.c line 36: syntax error
   
---
2008.02.22-15.27
*Error in loading object '/daemon/forge'
Object: /secure/sefun/sefun at /secure/sefun/load_object.c:14

'<fake>' at /secure/save/creators/c/capo (/<driver>) at line 0
'cmdAll' at /secure/save/creators/c/capo (/lib/command.c) at line 162
'cmd' at /secure/cmds/creators/update at line 110
'eventUpdate' at /secure/cmds/creators/update at line 138
'load_object' at /secure/sefun/sefun at /secure/sefun/load_object.c:14
'CATCH' at /secure/sefun/sefun at /secure/sefun/load_object.c:14
Trace written to /log/catch
/daemon/forge.c line 28: syntax error
   
/daemon/forge.c line 36: Illegal LHS
   
/daemon/forge.c line 36: syntax error
   
---
2008.02.22-15.27
*Error in loading object '/daemon/forge'
Object: /secure/cmds/creators/update at line 151

'<fake>' at /secure/save/creators/c/capo (/<driver>) at line 0
'cmdAll' at /secure/save/creators/c/capo (/lib/command.c) at line 162
'cmd' at /secure/cmds/creators/update at line 110
'eventUpdate' at /secure/cmds/creators/update at line 151
'CATCH' at /secure/cmds/creators/update at line 151
Trace written to /log/catch
/daemon/forge: Error in update
*Error in loading object '/daemon/forge'