LPMuds.net
September 09, 2010, 04:18:08 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: This is the forum page. For the main LPMuds page, visit http://lpmuds.net
 
   Home   SITE FAQ INTERMUD DOWNLOADS LINKS Help Search Login Register  
Pages: 1 [2]   Go Down
  Print  
Author Topic: Lenarics help thread  (Read 1309 times)
chaos
BFF
***
Offline Offline

Posts: 230


Job, school, social life, sleep. Pick 2.5.


View Profile WWW
« Reply #15 on: July 07, 2010, 07:13:43 PM »

Then I realized I hadn't documented the extension's hooks, so I had to do that.  STOP MAKING ME WORK.

Code:
[ Hooks ]

    Populace extensions support the following hooks, which may be interacted
    with using code like:
   
        void project_populace_do_start_travel(mapping args) {
            object who = args["who"];
            if(who->query_speech())
                who->init_command("say Okay, bye!");
        }

        void configure() {
            ::configure();
            add_extension(LS_Extension("populace"), (:
                $1->add_file_selector(Project_Room("street_*"));
                $1->add_populace(Project_Monster("citizen"), 10);
                $1->add_hook("do_populace_start_travel",
                    #'project_populace_do_start_travel);
            :));
        }

"can_populace_populate"

    Checked when a object is about to be deployed into the project.  If a failure
    result is obtained, normal deployment is prevented, and the object will be
    destructed if it has no environment after any "fail_populace_populate" hooks
    are checked.  If the failure result is a message, it is messaged from the
    room where deployment was to take place.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The object being deployed
        args["where"]               The room where the object is being deployed
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"do_populace_populate"

    Called when a object has been deployed into the project.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The object deployed
        args["where"]               The room where the object was deployed
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"fail_populace_populate"

    Checked when a object has failed to be deployed into the project because of
    a "can_populace_populate" hook.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The object being deployed
        args["where"]               The room where the object is being deployed
        args["populace"]            The populace extension
        args["control"]             The project control daemon
        args["message"]             A message failure result from the
                                    "can_populace_populate" hook, if one was
                                    obtained

"can_populace_start_travel"

    Checked when a managed person is about to be scheduled to pathfind from their
    current location to their "home" location.  If a failure result is obtained,
    travel scheduling is prevented.  If the failure result is a message, it is
    messaged from the person.  NOTE: this hook is also called in the person, with
    the same effects.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["destination"]         The person's home room
        args["night"]               Whether the populace extension considers
                                    it to be "night"
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"do_populace_start_travel"

    Checked when a managed person has been scheduled to pathfind from their
    current location to their "home" location.  NOTE: this hook is also called
    in the person.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["destination"]         The person's home room
        args["night"]               Whether the populace extension considers
                                    it to be "night"
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"fail_populace_start_travel"

    Checked when a managed person has failed to be scheduled to travel because
    of a "can_populace_start_travel" hook, either in the populace extension or
    the person.  NOTE: this hook is also called in the person.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["destination"]         The person's home room
        args["night"]               Whether the populace extension considers
                                    it to be "night"
        args["populace"]            The populace extension
        args["control"]             The project control daemon
        args["message"]             A message failure result from the
                                    "can_populace_start_travel" hook, if one
                                    was obtained

"can_populace_travel"

    Checked when a managed person is about to have a path added to their command
    queue for purposes of traveling from their current location to their "home"
    location.  If a failure result is obtained, this is prevented, and no further
    attempts to have the person travel home will take place within the current
    travel cycle.  If the failure result is a message, it is messaged from the
    person.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["destination"]         The person's home room
        args["path"]                The path descriptor containing the path
        args["pathfind"]            The pathfind descriptor for the pathfind
                                    that generated the path
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"do_populace_travel"

    Checked when a managed person has had a path added to their command queue for
    purposes of traveling from their current location to their "home" location.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["destination"]         The person's home room
        args["path"]                The path descriptor containing the path
        args["pathfind"]            The pathfind descriptor for the pathfind
                                    that generated the path
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"fail_populace_travel"

    Checked when a managed person has failed to have a path added to their command
    queue for purposes of traveling from their current location to their "home"
    location, because of a "can_populace_travel" hook.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["destination"]         The person's home room
        args["path"]                The path descriptor containing the path
        args["pathfind"]            The pathfind descriptor for the pathfind
                                    that generated the path
        args["populace"]            The populace extension
        args["control"]             The project control daemon
        args["message"]             A message failure result from the
                                    "can_populace_travel" hook, if one
                                    was obtained

"can_populace_end_travel"

    Checked when a managed person has completed traveling from their current
    location to their "home" location.  If a failure result is obtained, any
    "do_populace_end_travel" hooks will not be called.  If the failure result
    is a message, it is messaged from the person.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"do_populace_end_travel"

    Called when a managed person has completed traveling from their current
    location to their "home" location.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["populace"]            The populace extension
        args["control"]             The project control daemon

"fail_populace_end_travel"

    Called when a failure result has been obtained for a
    "can_populace_end_travel" hook.

    Hook arguments are passed in a mapping, as follows:

        args["who"]                 The person
        args["where"]               The person's current environment
        args["populace"]            The populace extension
        args["control"]             The project control daemon
        args["message"]             A message failure result from the
                                    "can_populace_end_travel" hook, if one
                                    was obtained
Logged

Lenaric
Acquaintance
*
Offline Offline

Posts: 10


View Profile
« Reply #16 on: July 10, 2010, 05:53:41 AM »

Wow. That intense.

Tomorrow I will pick through it more. Thanks for such a great example. I don't know how well I will understand everything going on but I will make some detailed notes and see if I can get the hang of the concept.

I'll let you know how it goes.
Logged
Nilrin
Acquaintance
*
Offline Offline

Posts: 47


View Profile
« Reply #17 on: July 10, 2010, 12:37:43 PM »

Here is a basic Daemon I did. It just does two very simple things.

1. Tracks general NPC population. Relatively useless.

2. Stores an array of pending re-spawns and slowly goes through each element of that array and spawns the NPC based on the given info.

Code:
/*    /daemon/census.c
 *    This daemon is desgined to recieve queries
      on the estimated population of the given NPC.
 */

#include <lib.h>
#include <dirs.h>

inherit LIB_DAEMON;

private mapping Population = ([]);
private string *Deaths;

int eventUpdatePopulation();
int eventSpawn();

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

    Deaths = ({ });
    Population = ([]);

    if( unguarded((: file_exists("/save/census.o") :)) ){
        RestoreObject("/save/census.o");
    }
    SetNoClean(1);
    eventUpdatePopulation();
    eventSpawn();
}

int GetPopulation(string name) {
    return Population[name];
}

int AddPopulation(string name) {
    if(Population[name]){
        Population[name] += 1;
    }
    else Population += ([name : 1]);
    SaveObject("/save/census.o");
    return Population[name];
}

int SubtractPopulation(string name) {
    Population[name] -= 1;
    SaveObject("/save/census.o");
    return Population[name];
}

AddDeaths(string str) {
    if(Deaths){
        Deaths += ({ str });
    }
    else Deaths = ({ str });

    SaveObject("/save/census.o");
    return;
}

string array GetTotalDeaths(){
    return Deaths;
}

mapping GetTotalPopulation(){
    return (Population + ([]));
}

int eventUpdatePopulation(){
    foreach(object npc in livings()){
        if(environment(npc)){
            if(Population[npc->GetKeyName()]){
                Population[npc->GetKeyName()] += 1;
            }
            else Population += ([npc->GetKeyName() : 1]);
        }
    }
    SaveObject("/save/census.o");
    call_out("eventUpdatePopulation",300);
}

int eventSpawn(){

    string *temp = ({ });

    if(sizeof(Deaths)){
        temp = explode(Deaths[0],"#");
    }

    if(sizeof(temp)){
        new(temp[0])->eventMove(temp[1]);
        Deaths = Deaths[1..];
    }
//    call_out("eventSpawn",300 + random(300));
      call_out("eventSpawn",10);
}

Here is a sample NPC using the re-spawn daemon.

Code:
#include <lib.h>
#include <daemons.h>

inherit LIB_SENTIENT;

string *spawnpoints = ({ "/domains/kahara/virtual/dense_forest_sq/14,103","/domains/kahara/virtual/dense_forest_sq/20,98",
                         "/domains/kahara/virtual/dense_forest_sq/21,107","/domains/kahara/virtual/dense_forest_sq/17,91",
                         "/domains/kahara/virtual/dense_forest_sq/36,129","/domains/kahara/virtual/dense_forest_sq/59,108",
                         "/domains/kahara/virtual/dense_forest_sq/81,109","/domains/kahara/virtual/dense_forest_sq/85,146",
                         "/domains/kahara/virtual/dense_forest_sq/93,141","/domains/kahara/virtual/dense_forest_sq/95,150",
                         "/domains/kahara/virtual/dense_forest_sq/115,140","/domains/kahara/virtual/dense_forest_sq/114,164",
                         "/domains/kahara/virtual/dense_forest_sq/115,176","/domains/kahara/virtual/dense_forest_sq/137,159",
                         "/domains/kahara/virtual/dense_forest_sq/138,141","/domains/kahara/virtual/dense_forest_sq/173,109",
                         "/domains/kahara/virtual/dense_forest_sq/168,103","/domains/kahara/virtual/dense_forest_sq/172,84",
                         "/domains/kahara/virtual/dense_forest_sq/174,80","/domains/kahara/virtual/dense_forest_sq/169,73",
                         "/domains/kahara/virtual/dense_forest_sq/148,41","/domains/kahara/virtual/dense_forest_sq/122,155",
                         "/domains/kahara/virtual/dense_forest_sq/100,22","/domains/kahara/virtual/dense_forest_sq/85,20",
                         "/domains/kahara/virtual/dense_forest_sq/80,32","/domains/kahara/virtual/dense_forest_sq/70,29",
                         "/domains/kahara/virtual/dense_forest_sq/75,68","/domains/kahara/virtual/dense_forest_sq/53,77",
                         "/domains/kahara/virtual/dense_forest_sq/51,84","/domains/kahara/virtual/dense_forest_sq/48,81", });

static void create() {
    sentient::create();
    SetKeyName("grey squirrel");
    SetId( ({"squirrel", "grey squirrel"}) );
    SetAdjectives(({"non player"}));
    SetShort("a grey squirrel");
    SetLong("This is a generally small animal with a fairly sledner body, bushy tail, and large eyes. Its fur appears fairly soft and silky. This squirrel is dark grey in color. The hindlimbs are somewhat longer than the forelimbs, with five toes on each foot.");
    SetPermitLoad(1);
    SetWanderSpeed(5);
    SetLevel(1);
    SetRace("rodent");
    SetGender("male");
    SetMaxHealthPoints(20);
    SetHealthPoints(20);
    SetSkill("melee attack", 30);

}
void init(){
    ::init();
}

eventDie(agent){
    CENSUS_D->AddDeaths(base_name(this_object()) + "#" + spawnpoints[random(sizeof(spawnpoints))]);
    ::eventDie(agent);
}

Logged
Lenaric
Acquaintance
*
Offline Offline

Posts: 10


View Profile
« Reply #18 on: August 02, 2010, 03:26:34 PM »

First Thanks to all that have been helping me out. I <3 your quick responses.

I attempted to use the complex system first. It didn't work well with the simple way I would like to do things. K.I.S.S So I applied Nirlrins code to great avail. I like that I am able to tailor the spawns based on location.

Think danger levels. 1-5. The equation I am using is Danger Level * 50 zombies

So that would make one section of the city more or less dangerous based on players or attraction. The zombie horde appears to move in unison with the food sources. Be it NPC's or Players.


Now that my population control is in place I am learning how to properly use starmap. It is moving things along very fast compared to QCS. Creating the beautify described world full of destruction is the slow part but most fun.

I am going to post my entire checklist soon. So any help or input on my goals would be greatly appreciated. This is so far a complete solo project, but I think I am going to keep it that way. Nice to have some control.
Logged
Pages: 1 [2]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!