New Group System, Room Events, and Event System Efficiency Upgrade... and a couple bug fixes.

This commit is contained in:
Vatiken 2013-02-15 03:54:25 +00:00
parent 82da0e8063
commit a2aaab144f
32 changed files with 612 additions and 322 deletions

View file

@ -15,6 +15,7 @@
#include "comm.h"
#include "db.h"
#include "handler.h"
#include "screen.h"
#include "interpreter.h"
#include "spells.h"
#include "dg_scripts.h"
@ -22,6 +23,7 @@
#include "class.h"
#include "fight.h"
#include "quest.h"
#include "mud_event.h"
/* local file scope variables */
static int extractions_pending = 0;
@ -910,6 +912,10 @@ void extract_char_final(struct char_data *ch)
if (ch->followers || ch->master)
die_follower(ch);
/* Check to see if we are grouped! */
if (GROUP(ch))
leave_group(ch);
/* transfer objects to room, if any */
while (ch->carrying) {
obj = ch->carrying;
@ -1386,3 +1392,100 @@ int find_all_dots(char *arg)
} else
return (FIND_INDIV);
}
/* Group Handlers */
struct group_data * create_group(struct char_data * leader)
{
struct group_data * new_group;
/* Allocate Group Memory & Attach to Group List*/
CREATE(new_group, struct group_data, 1);
add_to_list(new_group, group_list);
/* Allocate Members List */
new_group->members = create_list();
/* Clear Data */
new_group->group_flags = 0;
/* Assign Data */
SET_BIT(GROUP_FLAGS(new_group), GROUP_OPEN);
if (IS_NPC(leader))
SET_BIT(GROUP_FLAGS(new_group), GROUP_NPC);
join_group(leader, new_group);
return (new_group);
}
void free_group(struct group_data * group)
{
struct char_data *tch;
struct iterator_data Iterator;
if (group->members->iSize) {
for (tch = (struct char_data *) merge_iterator(&Iterator, group->members);
tch;
tch = next_in_list(&Iterator))
leave_group(tch);
remove_iterator(&Iterator);
}
free_list(group->members);
remove_from_list(group, group_list);
free(group);
}
void leave_group(struct char_data *ch)
{
struct group_data *group;
struct char_data *tch;
struct iterator_data Iterator;
bool found_pc = FALSE;
if ((group = ch->group) == NULL)
return;
send_to_group(NULL, group, "%s has left the group.\r\n", GET_NAME(ch));
remove_from_list(ch, group->members);
ch->group = NULL;
if (group->members->iSize) {
for (tch = (struct char_data *) merge_iterator(&Iterator, group->members);
tch; tch = next_in_list(&Iterator))
if (!IS_NPC(tch))
found_pc = TRUE;
remove_iterator(&Iterator);
}
if (!found_pc)
SET_BIT(GROUP_FLAGS(group), GROUP_NPC);
if (GROUP_LEADER(group) == ch && group->members->iSize) {
group->leader = (struct char_data *) random_from_list(group->members);
send_to_group(NULL, group, "%s has assumed leadership of the group.\r\n", GET_NAME(GROUP_LEADER(group)));
} else if (group->members->iSize == 0)
free_group(group);
}
void join_group(struct char_data *ch, struct group_data *group)
{
add_to_list(ch, group->members);
if (group->leader == NULL)
group->leader = ch;
ch->group = group;
if (IS_SET(group->group_flags, GROUP_NPC) && !IS_NPC(ch))
REMOVE_BIT(GROUP_FLAGS(group), GROUP_NPC);
if (group->leader == ch)
send_to_group(NULL, group, "%s becomes leader of the group.\r\n", GET_NAME(ch));
else
send_to_group(NULL, group, "%s joins the group.\r\n", GET_NAME(ch));
}