blob: 2491d9315457a49a6beae52ba8b4f419ab5f7fdc [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// npc/chat.c -- Labernde NPCs
4//
5// $Id: chat.c 6801 2008-03-21 23:34:46Z Zesstra $
6#pragma strong_types
7#pragma save_types
8#pragma range_check
9#pragma no_clone
MG Mud User88f12472016-06-24 23:31:02 +020010
11#include <properties.h>
12#define NEED_PROTOTYPES
13#include <living/combat.h>
14#include <thing/properties.h>
15#undef NEED_PROTOTYPES
16
17#define ME this_object()
18
19/*
20 * Some simple chat variables
21 */
22
23/*
24 * heart_beat is called so the monster may chat.
25 */
26void SetChats(int chance, mixed strs) {
27 if (!pointerp(strs))
28 return;
29 SetProp(P_CHAT_CHANCE,chance);
30 SetProp(P_CHATS,strs);
31}
32
33void SetAttackChats(int chance, mixed strs) {
34 if (!pointerp(strs))
35 return;
36 SetProp(P_ACHAT_CHANCE,chance);
37 SetProp(P_ACHATS,strs);
38}
39
Christian Georg Beckera32ae762017-04-03 01:06:34 +020040#define SR_CHAT_MSG 0
41#define SR_CHAT_TYP 1
42
43protected void process_chat(mixed strs) {
44 if(pointerp(strs) && sizeof(strs)) {
45 int msg_typ;
46 mixed entry = strs[random(sizeof(strs))];
47
48 if(pointerp(entry) && sizeof(entry)>=2 && intp(entry[SR_CHAT_TYP])) {
49 msg_typ = entry[SR_CHAT_TYP];
50 entry = entry[SR_CHAT_MSG];
51 }
52 if(closurep(entry))
53 entry = funcall(entry, &msg_typ);
Arathorn4fbd0b82018-02-05 15:33:55 +010054 entry = process_string(entry);
Christian Georg Beckera32ae762017-04-03 01:06:34 +020055
56 if(msg_typ)
57 msg_typ|=MSG_DONT_STORE|MSG_DONT_BUFFER;
Arathorn4fbd0b82018-02-05 15:33:55 +010058
59 // Nur nicht-leere Meldungen ausgeben, und nur dann, wenn der NPC noch
60 // existiert, denn im Falle von Attack-Chats koennte dieser z.B. durch
61 // reflektierten Schaden zerstoert worden sein.
62 if ( stringp(entry) && sizeof(entry) && objectp(this_object()) )
63 send_room(environment(),
64 entry,
65 msg_typ||(MT_LOOK|MT_LISTEN|MT_FEEL|MT_SMELL|
66 MSG_DONT_STORE|MSG_DONT_BUFFER|MSG_DONT_WRAP));
Christian Georg Beckera32ae762017-04-03 01:06:34 +020067 }
68}
69
MG Mud User88f12472016-06-24 23:31:02 +020070void DoAttackChat() {
MG Mud User88f12472016-06-24 23:31:02 +020071 if (!ME || !environment(ME))
72 return;
73 if (QueryProp(P_DISABLE_ATTACK)>0)return ;
74 if (random(100) < QueryProp(P_ACHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020075 process_chat(QueryProp(P_ACHATS));
MG Mud User88f12472016-06-24 23:31:02 +020076}
77
78void DoChat() {
MG Mud User88f12472016-06-24 23:31:02 +020079 if (!ME || !environment(ME))
80 return;
81 if (random(100) < QueryProp(P_CHAT_CHANCE))
Christian Georg Beckera32ae762017-04-03 01:06:34 +020082 process_chat(QueryProp(P_CHATS));
MG Mud User88f12472016-06-24 23:31:02 +020083}
84
85protected void heart_beat()
86{
87 if( InFight() ) DoAttackChat();
88 else DoChat();
89}