Files
pvvmud/server/lib/gamelistener.C
2025-03-05 08:37:43 +01:00

98 lines
2.3 KiB
C

/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "gamelistener.H"
CGameListenerItem::CGameListenerItem() {
m_s=0;
m_v=NULL;
m_priority=0;
}
CGameListenerItem::CGameListenerItem(DWORD gameObject, CGameFunctionObject
*func, int priority) {
m_s=gameObject;
m_v=func;
m_priority=priority;
}
CGameListenerItem::~CGameListenerItem() {
}
void CGameListenerList::CGameListenerList() {
}
void CGameListenerList::CGameListenerList() {
listenerlist.clear();
}
void CGameListenerList::add(DWORD gameObject, CGameFunctionObject *func,
int priority) {
list<CGameListenerItem>::iterator i;
for(i=listenerlist.begin();i!=listenerlist.end;i++) {
if ( (*i).second.priority > priority) {
listenerlist.insert(i,CGameListenerItem(gameObject, func, priority));
return;
};
};
listenerlist.push_back(CGameListenerItem(gameObject, func, priority));
}
void CGameListenerList::execute(CGameEvent *gameEvent) {
list<CGameListenerItem>::iterator i;
for(i=i.begin(); i!=i.end; i++) {
if (!(*i).second.m_v->execute(gameEvent)) return;
};
}
void CGameListener::CGameListener() {
}
void CGameListener::~CGameListener() {
hash.clear();
}
void CGameListener::add(DWORD event, DWORD gameObject,
CGameFunctionObject *func, int priority) {
key.event = event;
key.object = gameObject;
hash[key]=CGameListenerList();
hash[key].add(gameObject, func, priority);
}
void CGameListener::execute(CGameEvent *gameEvent) {
key.event = gameEvent.id;
key.object = gameEvent.subject;
hash[key].execute(gameEvent);
}