|
Post by The Abyss on Oct 23, 2006 21:47:02 GMT
any chance of our newest Arch posting some sample code?
|
|
|
Post by Tempest on Oct 23, 2006 22:37:19 GMT
ed /w/god/creation.c Editting New File: /w/god/creation.c :i
//Prototypes #pragma strict_laws
#define INFINITY 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFF**TRUNCATED**
//Inheritance private inherit "/lib/laws/physics"; private inherit "/lib/laws/morality";
//Variables public nosave object universe; public nosave object heavens; public savable object heaven; public nosave object heavenly_bodies; public nosave object earth; public nosave object *plants; public nosave object *animals; public conditionalsave object *man; private int time_of_destruction;
//Prototypes static void end();
//Implementation private void beginning() { int loop; int loop_end; object plant; object animal; object man; object woman; object satan; object apple; int armageddon;
heaven = find_object("/room/heaven");
/* Note this object is not moved to an environment, and thus resides * * in limbo */ universe = create_object_from("/obj/nothing");
heavens = create_object_from("/obj/nothing"); heavens->move(universe);
heavenly_bodies = ({}); for(loop = 0, loop_end = INFINITY; loop < loop_end; ++loop) { if(random(100) > 75) { heavenly_bodies += ({ clone_object("/obj/planet") }); } else { heavenly_bodies += ({ clone_object("/obj/star") }); } }
earth = create_object_from("/obj/nothing"); earth->set_light(1); earth->set_lit_name("Day"); earth->set_unlit_name("Night"); earth->add_firmament("Heaven"); earth->add_land(); earth->set_land_name("Earth"); earth->set_waters_name("Seas");
plants = ({}); for(loop = 0, loop_end = random(INFINITY); loop < loop_end; ++loop) { plant = clone_object("/obj/matter"); plant->set_life(1); plant->move(earth); plants += ({ plant }); }
animals = ({}); for(loop = 0, loop_end = random(INFINITY); loop < loop_end; ++loop) { animal = clone_object("/obj/matter"); animal->set_life(1); animal->move(earth); animals += ({ animal }); }
garden = clone_object("/obj/matter"); garden->move(earth);
inhabitants = ({});
man = clone_object("/obj/matter"); man->move(garden); man->set_life(1); inhabitants += ({ man });
woman = clone_object(man); woman->move(garden); woman->set_life(1); inhabitants += ({ woman });
woman->set_gullible(1); man->set_ignorant(1);
satan = clone_object("/lib/animals/snake"); satan->move(garden); apple = clone_object("/lib/plants/fruit/apple"); apple->move(satan); satan->deceive_object(woman);
time_of_destruction = physics::query_destruction_time(); set_heart_beat(1); //Begins the cycle of chaos and entropy. }
void heart_beat() { int immorality;
if(random(100) < 50) { immorality = morality::chaos(); time_of_destruction -= immortality; } else if(random(100) < 99) { physics::entropy(); } if(immortality < 1) { end(); } }
static void end() { inhabitants->move_or_destruct(heaven); destruct(universe); }
//EOF
|
|
|
Post by Gromlakh on Oct 23, 2006 23:13:03 GMT
Nicely done. ;D
|
|
|
Post by arams on Aug 13, 2007 18:25:37 GMT
nice code. anyone know if wolvie or frostbite still look at this site anyone more?
|
|
|
Post by Blain20 on Feb 29, 2008 9:37:10 GMT
#pragma strict_types #include <levels.h>
inherit "/obj/treasure";
private static int TTL;
void create() { ::create(); if(!is_clone(this_object())) return;
TTL = 100; set_name("ball"); set_short("a super ball"); set_alias(({ "super ball" })); set_long("This rubbery ball is super bouncy!"); set_weight(0); set_value(0); }
int valid_player(object ob) { if(!ob) return 0; if(!ob->query_is_player()) return 0; if(ob->query_level() < WIZLEVEL && !ob->query_test_char()) return 0; return 1; }
object query_owner() { object ob;
ob = environment(this_object()); if(valid_player(ob)) return ob; return 0; }
void init() { ::init(); if(valid_player(this_player())) { add_action("do_throw", "throw"); add_action("do_bounce", "bounce"); } }
void do_disappear() { object owner;
if(!(owner = query_owner())) tell_room(environment(this_object()), get_f_string( "A super ball bounces out of sight!")); destruct(this_object()); }
void do_catch(object catcher) { if(!catcher) return; if((random(100) < 10) || !random(TTL--)) { do_disappear(); return; } tell_object(catcher, get_f_string("You catch the ball in mid air!")); tell_room(environment(this_object()), get_f_string( (string)catcher->query_name()+" catches the ball in mid air!\n"), ({ catcher })); move(catcher); }
void bounce_back(object owner) { if(!owner) return; tell_room(environment(this_object()), get_f_string("A super ball "+ "bounces back up!")); do_catch(owner); }
int do_throw(string str) { string what; string whom; object target;
if(!str || sscanf(str, "%s to %s", what, whom) != 2) { notify_fail("Throw what to whom?\n"); return 0; } if(!id(what)) { notify_fail("Throw what?\n"); return 0; } if(!(target = find_player(whom))) { notify_fail("Throw the ball to whom?\n"); return 0; } if(!valid_player(target)) { writef("You can only throw the ball to other wizards."); return 1; } writef("You throw a super ball to "+(string)target->query_name()+"!"); tell_object(target, get_f_string((string)this_player()->query_name()+ " throw a super ball to you!")); tell_room(environment(this_player()), get_f_string( (string)this_player()->query_name()+" throws a super ball to "+ (string)target->query_name()+"!"), ({ this_player(), target })); move(environment(this_player())); call_out("do_catch", 0, target); return 1; }
int do_bounce(string str) { string what; string whom; object target;
if(!str || (!id(str) && sscanf(str, "%s to %s", what, whom) != 2)) { notify_fail("Bounce what?\n"); return 0; } if(what && !id(what)) { notify_fail("Bounce what?\n"); return 0; } if(!(target = find_player(whom))) { notify_fail("Bounce the ball to whom?\n"); return 0; } if(!valid_player(target)) { writef("You can only bounce the ball to other wizards."); return 1; } writef("You bounce a super ball to "+(string)target->query_name()+"!"); tell_object(target, get_f_string((string)this_player()->query_name()+ " bounces a super ball to you!")); tell_room(environment(this_player()), get_f_string( (string)this_player()->query_name()+" bounces a super ball to "+ (string)target->query_name()+"!"), ({ this_player(), target })); move(environment(this_player())); call_out("do_catch", 0, target); return 1; }
int drop() { object owner;
owner = query_owner(); if(!owner || !random(TTL--)) call_out("do_disappear", 0); else call_out("bounce_back", 0, owner); return 0; }
|
|
|
Post by Blain20 on Feb 29, 2008 9:52:48 GMT
#pragma strict_types
#include "../defs.h" #include "../w/base/weapon.h"
inherit OBJECT("base/object");
private static status branch_gotten;
void create() { ::create();
set_name("tree"); set_short("a tall, black tree"); set_alias(({ "tall tree", "black tree", "tall, black tree", "tall black tree" })); set_long("##calc_long"); set_smell("The dusty tree smells as if it may still be alive after "+ "all these ages."); set_sound("The tree makes no sound as it remains motionless in this "+ "breezeless temple."); set_taste("You lick the tree and taste dust and bark."); set_touch("You feel of the tree's rough bark."); set_identify("Evil permeates this ebonwood tree. This breed was "+ "originally derived from the beautiful, graceful trees of "+ "Sylvandor. The dark elves brought some of those trees beneath "+ "the surface when they were exiled by the surface elves. They then "+ "used their dark, evil magic to twist the trees into the ebonwood. "+ "The wood of this new breed of tree is very strong and durable, but "+ "is also very heavy. This wood was used by dark elves in every"+ "thing from weapon handles, to doors and furniture. The tree "+ "requires little to no water, and, conversely to most surface "+ "trees, the ebonwood would die if exposed to sunlight."); set_material(({ "wood" })); set_weight(1000); set_value(0);
add_item(({ "branch", "large branch", }), "The large branch juts out "+ "from the lower part of the tree's trunk. It is very thick and "+ "is devoid of offshoot branches."); }
void long() { string msg;
msg = "The tall, black tree is rooted into a square hole in the "+ "stone floor that is filled with dark soil. It has shingled "+ "bark and long, thin branches that reach out at chaotic angles. "+ "Its dark wooden branches are leafless, and its base has been "+ "The top of the tree nearly reaches the high ceiling of the "+ "temple. "; if(!branch_gotten) msg += "A large branch hangs low enough to reach. "; writef(msg); }
void init() { ::init(); add_action("do_snap", "snap"); add_action("do_snap", "pull"); add_action("do_snap", "tug"); add_action("do_snap", "break"); }
int get() { write("The tree is planted firmly in the ground.\n"); return 0; }
int do_snap(string arg) { object branch;
if(branch_gotten) { notify_fail("You see no branches worthy of the effort.\n"); return 0; } if((int)this_player()->query_str() < BRANCH_DIFF+4) { writef("You "+query_verb()+" on the branch, but to no avail.\n"+ "The wood is much too strong."); sayf((string)this_player()->query_name()+" struggles to pull "+ "a branch off of the tall tree, but fails."); return 1; } writef("You "+query_verb()+" off one of the larger branches from "+ "the tree."); sayf((string)this_player()->query_name()+" breaks off a large branch "+ "from the tall tree."); branch = clone_object(WEAPON("branch")); if(this_player()->add_weight((int)branch->query_weight())) branch->move(this_player()); else { writef("You cannot carry the branch, and so it falls to the "+ "ground."); sayf((string)this_player()->query_name()+" drops a branch."); branch->move(environment(this_player())); } branch_gotten = 1; return 1; }
|
|
|
Post by Blain20 on Feb 29, 2008 10:18:57 GMT
/* A matte black, full body jumpsuit. * * Long name. Amazing results. * * This piece of armour gives no protection. It covers the entire body * (in theme), and shows up in 'eq' as "Other" and is of the "clothes" * type. * * This object does two things: * * 1) It gives the wearer UP TO a +5 bonus to seclusion and stealth, each. * It will only bring the wearer's abilities up to +5. For example, if * the wearer has +4 in stealth from some other object, this object gives * +1. If the wearer has +5 or more already, it gives none. It checks * for changes in the wearer's abilities every 1 minute. * * 2) It covers the body and thus sets itself as the descriptor for the * wearer, if a player. This overrides the long() in the player, only * showing whatever this object returns in long_mod() and the player's * current body position. This object's long_mod() returns a description * of the garment being worn on the player, but does also prepend with * the name, gender, and race of the player for security reasons. Maybe * if I added a hood, I could completely hide the player. ;)~ While * worn, the object is invisible in the inventory since it is already * mentioned in the player's long. */
#pragma strict_types
#include "../defs.h" #include <classes.h>
inherit ARMOUR("base/armour");
private static int bonus_sec; private static int bonus_ste; private static int last_sec; private static int last_ste; private static int gave_bonus_sec; private static int gave_bonus_ste; private static object bonus_given;
void check_bonus();
void create() { ::create(); if(!is_clone()) return;
bonus_sec = 5; bonus_ste = 5; set_name("jumpsuit"); set_alias(({ "black jumpsuit", "full body jumpsuit", "matte black jumpsuit", "matte black", "full body jumpsuit", "suit", "black suit", "matte black suit", "full body suit", "matte black, fully body suit", "matte black full body suit" })); set_short("a matte black, full body jumpsuit"); set_long("This black jumpsuit is made of thin elastic cloth. It "+ "is designed to cover most of the wearer's body."); set_smell("The jumpsuit smells of cloth."); set_sound("You rub the material with your finger, but it makes no "+ "sound."); set_taste("It tastes like cloth."); set_touch("The material of the jumpsuit is somewhat smooth."); set_identify("This article of clothing was woven by a dark elf "+ "spinstress."); set_material(({ "cloth" })); set_armour_type("clothes"); set_weight(1); set_value(50); set_wear_func(this_object()); set_remove_func(this_object()); }
string long_mod() { object obj; string my_long;
if(!query_worn()) return 0; my_long = (string)obj->query_cap_name()+" is a "+ (string)obj->query_gender_string()+" "+(string)obj->query_race()+ ".\n"; my_long += capitalize((string)obj->query_objective())+" is wearing a "+ "matte black, full body jumpsuit.\n"; return my_long; }
string short() { if(query_worn() && environment(this_object()) && environment(this_object())->query_is_player()) return 0; return ::short(); }
void add_bonus() { int tmp;
if((string)this_player()->query_class() == ROGUE) { bonus_given = this_player(); if((tmp = (int)bonus_given->query_tmp_ability("seclusion")) > 0) gave_bonus_sec = bonus_sec - tmp; else gave_bonus_sec = bonus_sec; bonus_given->increase_tmp_ability("seclusion", gave_bonus_sec);
if((tmp = (int)bonus_given->query_tmp_ability("stealth")) > 0) gave_bonus_ste = bonus_ste - tmp; else gave_bonus_ste = bonus_ste; bonus_given->increase_tmp_ability("stealth", gave_bonus_ste); call_out("check_bonus", 60); } }
void remove_bonus() { if(bonus_given) { bonus_given->increase_tmp_ability("seclusion", -gave_bonus_sec); bonus_given->increase_tmp_ability("stealth", -gave_bonus_ste); bonus_given = 0; } }
void check_bonus() { if(!bonus_given) return; if(last_sec != (int)bonus_given->query_tmp_ability("seclusion") || last_ste != (int)bonus_given->query_tmp_ability("stealth")) { remove_bonus(); add_bonus(); last_sec = (int)bonus_given->query_tmp_ability("seclusion"); last_ste = (int)bonus_given->query_tmp_ability("stealth"); } call_out("check_bonus", 60); }
int can_wear() { if(this_player()->query_is_player()) this_player()->set_descriptor( (string)this_player()->query_real_name()); add_bonus(); return 1; }
int can_remove() { if(this_player()->query_is_player()) this_player()->set_descriptor(0); remove_bonus(); return 1; }
/* Will use if needed */ /* void move(mixed dest) { ::move(dest); remove_bonus(); } */
void is_destructed() { remove_bonus(); }
|
|
|
Post by Blain20 on Jun 11, 2008 13:54:04 GMT
public nosave object heavenly_bodies;
I just QCed my Creation file and found a typo which would have caused an error. The above should read: public nosave object *heavenly_bodies;
Ooh, and: s/immortality/immorality
|
|
|
Post by Pillar on Jun 11, 2008 14:23:09 GMT
i totally know what you're talking about...
|
|
|
Post by Blain20 on Jun 11, 2008 15:50:56 GMT
object heavenly_bodies;
object *heavenly_bodies;
In LPC, the * causes a variable to be an array of the given type. So the first one can be set to an object, but the second can be set to an array of objects.
An object in LPC can be understood simply as a room, weapon, armour, food, your character, and NPC, etc. An array is a list or multiple objects, e.g. ({ room1, room2, weapon, food })
So, as we see, an array is a list ({ elements... }), wherein the elements are things separated by commas. The "type" I mentioned refers to LPC data types. These include (but are not limited to) objects, integers (-1, 0, 1), strings ("Hello world!"), mapping (a special associated list [see below]), and so on.
A mapping is like an array, except it looks more like ([ "key1":"value1", "key2":"value2" ]). It is also made up of elements separated by commas, but there are two basic parts for element, and those are the key and the value. The value can be of ANY type, and the key can be of the non-array/mapping types (if I recall correctly). So you can have a mapping of player names, such as ([ "pillar":1289345743834853123, "calvin":092873918723,"mordecai":123]). This list is my mock representation of our post count on this board. Notice Pillar posts too much. Anyway, mappings are used a lot for keeping ordered lists of data by key. An array is used to keep an [usually] unordered list of data. I say usually because sometimes arrays are used to keep lists ordered by their position within the list. In this sense, an array is just like a mapping except that the key is the element's position, and thus uses less MUD Driver memory to keep. However, it is less helpful for more complex list-keeping.
*bow* --Dr. Blain
|
|
|
Post by Pillar on Jun 11, 2008 17:39:04 GMT
nice post, dr. dick.
|
|
|
Post by Blain20 on Jun 11, 2008 21:42:25 GMT
i totally know what you're talking about... I took your statement as sarcasm. ;)
|
|