Пример #1
0
void init_socials() {
  // create the social table
  social_table = newHashtable();

  // open up the storage set
  STORAGE_SET       *set = storage_read(SOCIALS_FILE);
  STORAGE_SET_LIST *list = read_list(set, "socials");
  STORAGE_SET    *social = NULL;

  // parse all of the socials
  while( (social = storage_list_next(list)) != NULL)
    add_social(socialRead(social));
  
  // close the storage set
  storage_close(set);

  // add all of the socials to the command table
  HASH_ITERATOR *hash_i = newHashIterator(social_table);
  const char       *cmd = NULL;
  SOCIAL_DATA     *data = NULL;

  ITERATE_HASH(cmd, data, hash_i) {
    add_cmd(cmd, NULL, cmd_social, "player", FALSE);
    if(data->min_pos == POS_SITTING)
      add_cmd_check(cmd, chk_conscious);
    else if(data->min_pos == POS_STANDING)
      add_cmd_check(cmd, chk_can_move);
    else if(data->max_pos == POS_STANDING)
      add_cmd_check(cmd, chk_grounded);
  } deleteHashIterator(hash_i);
Пример #2
0
//*****************************************************************************
//
// implementation of race.h
//
//*****************************************************************************
void init_races() {
  // create the table for holding race data
  race_table = newHashtable();

  // make the default human body
  BODY_DATA *body = newBody();
  bodySetSize(body, BODYSIZE_MEDIUM);
  bodyAddPosition(body, "right grip",              BODYPOS_HELD,          0);
  bodyAddPosition(body, "left grip",               BODYPOS_HELD,          0);
  bodyAddPosition(body, "right foot",              BODYPOS_RIGHT_FOOT,    2);
  bodyAddPosition(body, "left foot",               BODYPOS_LEFT_FOOT,     2);
  bodyAddPosition(body, "right leg",               BODYPOS_LEG,           9);
  bodyAddPosition(body, "left leg",                BODYPOS_LEG,           9);
  bodyAddPosition(body, "waist",                   BODYPOS_WAIST,         1);
  bodyAddPosition(body, "right finger",            BODYPOS_FINGER,        1);
  bodyAddPosition(body, "left finger",             BODYPOS_FINGER,        1);
  bodyAddPosition(body, "right hand",              BODYPOS_RIGHT_HAND,    2);
  bodyAddPosition(body, "left hand",               BODYPOS_LEFT_HAND,     2);
  bodyAddPosition(body, "right wrist",             BODYPOS_WRIST,         1);
  bodyAddPosition(body, "left wrist",              BODYPOS_WRIST,         1);
  bodyAddPosition(body, "right arm",               BODYPOS_ARM,           7);
  bodyAddPosition(body, "left arm",                BODYPOS_ARM,           7);
  bodyAddPosition(body, "about body",              BODYPOS_ABOUT,         0);
  bodyAddPosition(body, "torso",                   BODYPOS_TORSO,        50);
  bodyAddPosition(body, "neck",                    BODYPOS_NECK,          1);
  bodyAddPosition(body, "right ear",               BODYPOS_EAR,           0);
  bodyAddPosition(body, "left ear",                BODYPOS_EAR,           0);
  bodyAddPosition(body, "face",                    BODYPOS_FACE,          2);
  bodyAddPosition(body, "head",                    BODYPOS_HEAD,          2);
  bodyAddPosition(body, "floating about head",     BODYPOS_FLOAT,         0);
  //                                                                  ------
  //                                                                    100

  // add the basic races
  //add_race("human", "hum", body, TRUE);
  //********************************************************************
  // If you are wanting to add new, non-stock races it is suggested
  // you do so through a module and import them with add_race instead
  // of putting them directly into this folder. This will make your life
  // much easier whenever new versions of NakedMud are released and you
  // want to upgrade!
  //********************************************************************
}
Пример #3
0
void exampleHashtable()
{
	// Use pooling for efficiency, if you don't want to use pooling
	// then comment out this line.
	pool_hashtable(16);

	Hashtable* H = newHashtable(8);

	hashtable_put(H, 23, "Hello");
	hashtable_put(H, 16, "World");
	// Hash another entry to 0 (besides World)
	hashtable_put(H, 8, "Again");
	hashtable_put(H, 24, "And again");
	hashtable_put(H, 40, "And again again");

	// Print out the size
	printf("The hashtable has %d entries.\n", H->size);

	hashtable_display(H, &toString);

	// Test the get function based on the keys
	printf("%s ", (char*)hashtable_get(H, 23));
	printf("%s\n", (char*)hashtable_get(H, 16));
	printf("%s\n", (char*)hashtable_get(H, 8));
	printf("%s\n", (char*)hashtable_get(H, 24));

	// Try one that doesn't exist and goes to a completely empty entry
	if (hashtable_get(H, 1) == NULL)
		printf("Entry with key 1 not found.\n");
	// Try one that doesn't exist and goes to an existing entry
	if (hashtable_get(H, 32) == NULL)
		printf("Entry with key 32 not found.\n");

	// Test exists on all added data
	if (hashtable_exists(H, 23) && hashtable_exists(H, 16) && 
		 hashtable_exists(H, 8) && hashtable_exists(H, 24) && hashtable_exists(H, 40))
		printf("The hashtable's entries are sound.\n");

	// Test removing of an entry that doesn't exist in the list
	printf("Removed: %s\n", (char*)hashtable_remove(H, 32));
	// Test removing of the first entry in the list
	printf("Removed: %s\n", (char*)hashtable_remove(H, 16));
	// Test removing of a middle entry in the list
	printf("Removed: %s\n", (char*)hashtable_remove(H, 24));
	// Test removing of an end entry in the list
	printf("Removed: %s\n", (char*)hashtable_remove(H, 40));
	// Test removing of the only entry
	printf("Removed: %s\n", (char*)hashtable_remove(H, 8));
	
	// Test setting the last entry remaining
	printf("Before: %s", (char*)hashtable_get(H, 23));
	hashtable_set(H, 23, "Changed!");
	printf("\tAfter: %s\n", (char*)hashtable_get(H, 23));

	// Test the set method for a non existing key
	if (!hashtable_set(H, 45, "Foo"))
		printf("Cannot set 45 to 'Foo', key 45 doesn't exist.\n");

	// Print out the size
	printf("The hashtable has %d entries.\n", H->size);
	
	// Clear the table and print out the size
	hashtable_clear(H);
	printf("Cleared. The hashtable has %d entries.\n", H->size);
	
	// This will clear the list of any nodes and pool them and then free
	// the list itself from memory
	hashtable_free(H);
	
	// If you're not using pooling this can be commented out. This will
	// free all pooled nodes from memory. Always call this at the end 
	// of using any List.
	unpool_hashtable();
}
Пример #4
0
END_DESCRIBE

DESCRIBE(newPrimFunction, "tap_prim_fun* newPrimFunction (void(*address)(expression*[], int, exprvals*, datatype*), int minargs, int maxargs, typelist* types)")
	IT("Creates a new primitive tap function")
		tap_prim_fun* fun = newPrimFunction(prim_iAdd, 1, ARGLEN_INF, newTypelist(TYPE_INT));
		SHOULD_EQUAL(fun->address, prim_iAdd)
		SHOULD_EQUAL(fun->minargs, 1)
		SHOULD_EQUAL(fun->maxargs, ARGLEN_INF)
		SHOULD_EQUAL(fun->types->type, TYPE_INT)
		freePrimFun(fun);
	END_IT
END_DESCRIBE

DESCRIBE(newEnvironment, "environment* newEnvironment (hashtable* variables, int parent)")
	IT("Creates a new environment")
		environment* env = newEnvironment(newHashtable(100), 0);
		SHOULD_NOT_EQUAL(env->variables, NULL)
		insertPrimHash(env->variables, "+", newPrimFunction(&prim_iAdd, 1, ARGLEN_INF, newTypelist(TYPE_INT)));
		SHOULD_EQUAL(env->types, NULL)
		freeEnv(env);
	END_IT
END_DESCRIBE

DESCRIBE(newStringlist, "newStringlist (string* str, stringlist* next)")
	IT("Creates a new list of strings")
		string* str1 = newString(strDup("a"));
		string* str2 = newString(strDup("b"));
		string* str3 = newString(strDup("c"));
		stringlist* sl = newStringlist(str1, newStringlist(str2, newStringlist(str3, NULL)));
		SHOULD_EQUAL(strcmp(sl->str->content, "a"), 0)
		SHOULD_EQUAL(strcmp(sl->next->str->content, "b"), 0)
Пример #5
0
//*****************************************************************************
// implementation of olc_extender.h
//*****************************************************************************
OLC_EXTENDER *newExtender(void) {
  OLC_EXTENDER *data = calloc(1, sizeof(OLC_EXTENDER));
  data->opt_hash = newHashtable();
  return data;
}
Пример #6
0
void register_tedit_opt(const char *type, const char *desc) {
  if(tedit_opts == NULL)
    tedit_opts = newHashtable();
  hashPut(tedit_opts, type, strdupsafe(desc));
}