Pol  Revision:cb584c9
listenpt.cpp
Go to the documentation of this file.
1 
8 #include "listenpt.h"
9 
10 #include <stddef.h>
11 
12 #include "../bscript/bobject.h"
13 #include "globals/settings.h"
14 #include "globals/uvars.h"
15 #include "mobile/charactr.h"
16 #include "module/osmod.h"
17 #include "uconst.h"
18 #include "ufunc.h"
19 #include "uoexec.h"
20 #include "uoscrobj.h"
21 
22 namespace Pol
23 {
24 namespace Core
25 {
26 ListenPoint::ListenPoint( UObject* obj, UOExecutor* uoexec, int range, int flags )
27  : object( obj ), uoexec( uoexec ), range( range ), flags( flags )
28 {
29 }
30 
32 
33 const char* TextTypeToString( u8 texttype )
34 {
35  switch ( texttype )
36  {
37  case TEXTTYPE_WHISPER:
38  return "whisper";
39  case TEXTTYPE_YELL:
40  return "yell";
41  case TEXTTYPE_EMOTE:
42  return "emote";
43  default:
44  return "default";
45  }
46 }
47 
48 void sayto_listening_points( Mobile::Character* speaker, const char* p_text, int /*p_textlen*/,
49  u8 texttype, // DAVE
50  const u16* p_wtext /*=nullptr*/, const char* p_lang /*=nullptr*/,
51  int p_wtextlen /*=0*/, Bscript::ObjArray* speechtokens /*=nullptr*/ )
52 {
53  for ( ListenPoints::iterator itr = gamestate.listen_points.begin(),
54  end = gamestate.listen_points.end();
55  itr != end; )
56  {
57  ListenPoint* lp = ( *itr ).second;
58  if ( lp->object->orphan() )
59  {
60  ListenPoints::iterator next = itr;
61  ++next;
62  gamestate.listen_points.erase( itr );
63  delete lp;
64  itr = next;
65  end = gamestate.listen_points.end();
66  }
67  else
68  {
69  if ( !speaker->dead() || ( lp->flags & LISTENPT_HEAR_GHOSTS ) )
70  {
72  {
73  if ( speechtokens != nullptr && ( ( lp->flags & LISTENPT_HEAR_TOKENS ) == 0 ) )
74  {
75  ++itr;
76  continue;
77  }
78  else if ( speechtokens == nullptr && ( lp->flags & LISTENPT_NO_SPEECH ) )
79  {
80  ++itr;
81  continue;
82  }
83  }
84  const UObject* toplevel = lp->object->toplevel_owner();
85  if ( ( speaker->realm == toplevel->realm ) &&
86  ( inrangex( speaker, toplevel->x, toplevel->y, lp->range ) ) )
87  {
88  if ( p_wtext && p_lang && p_wtextlen > 0 )
90  speaker, p_text, TextTypeToString( texttype ), p_wtext, p_lang, speechtokens ) );
91  else
93  new Module::SpeechEvent( speaker, p_text, TextTypeToString( texttype ) ) );
94  }
95  }
96  ++itr;
97  }
98  }
99 }
100 
102 {
103  // ListenPoint lp( nullptr, uoexec, 0, 0 );
104  ListenPoints::iterator itr = gamestate.listen_points.find( uoexec );
105  if ( itr !=
106  gamestate.listen_points.end() ) // could have been cleaned up in sayto_listening_points
107  {
108  ListenPoint* lp = ( *itr ).second;
109  gamestate.listen_points.erase( uoexec );
110  delete lp;
111  }
112 }
113 
115 {
116  gamestate.listen_points[uoexec] = new ListenPoint( obj, uoexec, range, flags );
117 }
118 
120 {
122  for ( ListenPoints::iterator itr = gamestate.listen_points.begin(),
123  end = gamestate.listen_points.end();
124  itr != end; )
125  {
126  ListenPoint* lp = ( *itr ).second;
127  if ( lp == nullptr || lp->object->orphan() )
128  {
129  ListenPoints::iterator next = itr;
130  ++next;
131  gamestate.listen_points.erase( itr );
132  delete lp;
133  itr = next;
134  end = gamestate.listen_points.end();
135  }
136  else
137  {
138  arr->addElement( lp->object->make_ref() );
139 
140  ++itr;
141  }
142  }
143  return arr;
144 }
145 }
146 }
unsigned char u8
Definition: rawtypes.h:25
void register_for_speech_events(UObject *obj, UOExecutor *uoexec, int range, int flags)
Definition: listenpt.cpp:114
UObjectRef object
Definition: listenpt.h:35
const int LISTENPT_HEAR_TOKENS
Definition: listenpt.h:49
const int LISTENPT_HEAR_GHOSTS
Definition: listenpt.h:48
bool signal_event(Bscript::BObjectImp *eventimp)
Definition: osmod.cpp:769
void deregister_from_speech_events(UOExecutor *uoexec)
Definition: listenpt.cpp:101
void sayto_listening_points(Mobile::Character *speaker, const char *p_text, int, u8 texttype, const u16 *p_wtext, const char *p_lang, int p_wtextlen, Bscript::ObjArray *speechtokens)
Definition: listenpt.cpp:48
ListenPoint(UObject *obj, UOExecutor *uoexec, int range, int flags)
Definition: listenpt.cpp:26
ListenPoints listen_points
Definition: uvars.h:225
unsigned short u16
Definition: rawtypes.h:26
bool seperate_speechtoken
Definition: ssopt.h:93
GameState gamestate
Definition: uvars.cpp:74
const char * TextTypeToString(u8 texttype)
Definition: listenpt.cpp:33
SettingsManager settingsManager
Definition: settings.cpp:14
void addElement(BObjectImp *imp)
Definition: object.cpp:1399
Realms::Realm * realm
Definition: baseobject.h:56
Bscript::BObjectImp * GetListenPoints()
Definition: listenpt.cpp:119
UOExecutor * uoexec
Definition: listenpt.h:36
const int LISTENPT_NO_SPEECH
Definition: listenpt.h:50
bool inrangex(const Character *c1, const Character *c2, int maxdist)
Definition: ufunc.cpp:443
Definition: berror.cpp:12
bool dead() const
Definition: charactr.h:931
Module::OSExecutorModule * os_module
Definition: uoexec.h:37