/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
/***************************************************************************
* ROM 2.4 is copyright 1993-1996 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@efn.org) *
* Gabrielle Taylor *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************/
#include <glib.h>
#if defined(macintosh)
#include <types.h>
#include <time.h>
#endif
#if defined(unix)
#include <sys/types.h>
#include <sys/time.h>
#endif
#if defined( _WIN32)
#include <sys/types.h>
#include <time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <merc.h>
#include <recycle.h>
extern GMemChunk *ban_mem_chunk;
extern GMemChunk *known_mem_chunk;
extern GMemChunk *mobmem_mem_chunk;
extern GMemChunk *mprog_mem_chunk;
BAN_DATA *ban_free;
BAN_DATA *new_ban(void)
{
BAN_DATA *ban;
if (ban_free == NULL)
ban = g_chunk_new (BAN_DATA, ban_mem_chunk);
else
{
ban = ban_free;
ban_free = ban_free->next;
}
VALIDATE(ban);
ban->next = NULL;
ban->ban_flags = 0;
ban->level = 0;
ban->name = &str_empty[0];
ban->reason = &str_empty[0];
return ban;
}
void free_ban(BAN_DATA *ban)
{
if (!IS_VALID(ban))
return;
INVALIDATE(ban);
ban->next = ban_free;
ban_free = ban;
}
long last_pc_id;
long last_mob_id;
long get_pc_id(void)
{
int val;
val = (current_time <= last_pc_id) ? last_pc_id + 1 : current_time;
last_pc_id = val;
return val;
}
long get_mob_id(void)
{
last_mob_id++;
return last_mob_id;
}
const int buf_size[MAX_BUF_LIST] =
{
16,32,64,128,256,1024,2048,4096,8192,16384
};
/* local procedure for finding the next acceptable size */
/* -1 indicates out-of-boundary error */
int get_size (int val)
{
int i;
for (i = 0; i < MAX_BUF_LIST; i++)
if (buf_size[i] >= val)
{
return buf_size[i];
}
return -1;
}
KNOWN_DATA *known_free;
KNOWN_DATA *new_known(void)
{
KNOWN_DATA *known;
if (known_free == NULL)
known = g_chunk_new (KNOWN_DATA, known_mem_chunk);
else
{
known = known_free;
known_free = known_free->next;
}
VALIDATE(known);
return known;
}
void free_known(KNOWN_DATA *known)
{
if (!IS_VALID(known))
return;
INVALIDATE(known);
known->next = known_free;
known_free = known;
}
MEM_DATA *mem_data_free;
/*
* Mobile Memory.. as in I remember YOU!
*/
MEM_DATA *new_mem_data(void)
{
MEM_DATA *memory;
if (mem_data_free == NULL)
memory = g_chunk_new (MEM_DATA, mobmem_mem_chunk);
else
{
memory = mem_data_free;
mem_data_free = mem_data_free->next;
}
memory->next = NULL;
memory->id = 0;
memory->reaction = 0;
memory->when = 0;
VALIDATE(memory);
return memory;
}
void free_mem_data(MEM_DATA *memory)
{
if (!IS_VALID(memory))
return;
memory->next = mem_data_free;
mem_data_free = memory;
INVALIDATE(memory);
}
/* stuff for recycling mobprograms */
extern MPROG_LIST *mprog_free;
MPROG_LIST *new_mprog(void)
{
MPROG_LIST *mp;
if (mprog_free == NULL)
{
mp = g_chunk_new (MPROG_LIST, mprog_mem_chunk);
mp->code = g_string_new("");
mp->trig_phrase = g_string_new("");
}
else
{
mp = mprog_free;
mprog_free=mprog_free->next;
}
mp->vnum = 0;
mp->trig_type = 0;
VALIDATE(mp);
return mp;
}
void free_mprog(MPROG_LIST *mp)
{
if (!IS_VALID(mp))
return;
INVALIDATE(mp);
mp->next = mprog_free;
mprog_free = mp;
}