Wrapper fuer ReceiveMsg()
Da die Wrapper im /std/room thematisch nirgendwo hin passten, wurde
/std/room/comm.c neu erstellt und ReceiveMsg() aus /std/room/items.c
dort hin verlegt.
Die lfun _notify() ist durch SendNotify() ueberfluessig und wurde
ersetzt.
Change-Id: Ia42d131228963cbf8023f6b1563c38f65a38bd63
diff --git a/std/living/comm.c b/std/living/comm.c
index a2ef665..ccfe92b 100644
--- a/std/living/comm.c
+++ b/std/living/comm.c
@@ -8,8 +8,13 @@
#pragma no_clone
#pragma range_check
+inherit "/std/living/comm_structs";
+
#include <defines.h>
+#include <thing/language.h>
+#define NEED_PROTOTYPES
#include <living/comm.h>
+#undef NEED_PROTOTYPES
void create_super()
{
@@ -135,3 +140,87 @@
return MT_LOOK;
}
+// Wrapper fuer ReceiveMsg()
+public int* ReceiveSay(string msg, string prefix = 0,
+ struct msg_s* sense_blocked =
+ ({(<msg_s>
+ msg: "@WER1 bewegt die Lippen, Du hoerst jedoch nichts.",
+ type: MT_LOOK)}))
+{
+ int* res = ({0, -1});
+
+ if(!prefix)
+ {
+ prefix = previous_object().Name(WER, 1) + " sagt: ";
+ }
+
+ res[0] = ReceiveMsg(
+ replace_personal(msg, ({previous_object(), this_player()}) - ({0}), 1),
+ MT_LISTEN | MSG_BS_LEAVE_LFS,
+ MA_SAY,
+ prefix);
+
+ if(res[0] == MSG_SENSE_BLOCK)
+ {
+ // Um eine Nummer zurueckzugeben, ist hier leider eine for-Schleife noetig.
+ for(int i = 0; i < sizeof(sense_blocked); ++i)
+ {
+ res[0] = ReceiveMsg(
+ replace_personal(sense_blocked[i].msg, ({previous_object(),
+ this_player()}) - ({0}), 1),
+ sense_blocked[i].type | MSG_BS_LEAVE_LFS,
+ MA_SAY,
+ sense_blocked[i].prefix);
+ if(res[0] != MSG_SENSE_BLOCK)
+ {
+ res[1] = i;
+ break;
+ }
+ }
+ }
+ return res;
+}
+
+public int ReceiveNotify(string msg, string action)
+{
+ // Da MT_NOTIFICATION immer zugestellt wird, ist keine Fehlerbehandlung
+ // notwendig.
+ return ReceiveMsg(
+ msg,
+ // MSG_DONT_IGNORE waere wegen MT_NOTIFICATION inhaltlich nicht noetig,
+ // spart aber ein paar Ticks.
+ MT_NOTIFICATION | MSG_BS_LEAVE_LFS | MSG_DONT_IGNORE,
+ action);
+}
+
+public int ReceiveTeilemit(string msg)
+{
+ // Blockierte Sinne sind hier kein Problem, ergo keine Fehlerbehandlung.
+ return ReceiveMsg(
+ replace_personal(msg, ({previous_object(), this_player()}) - ({0}), 1),
+ MT_COMM | MT_FAR | MSG_BS_LEAVE_LFS | MSG_DONT_STORE,
+ MA_TELL,
+ previous_object().Name(WER, 1) + "teilt Dir mit: ");
+}
+
+public int* ReceiveMultisense(struct msg_s* msgs,
+ string action = 0, int commontypes = 0)
+{
+ int* res = ({0, -1});
+
+ // Um eine Nummer zurueckzugeben, ist hier leider eine for-Schleife noetig.
+ for(int i = 0; i < sizeof(msgs); ++i)
+ {
+ res[0] = ReceiveMsg(
+ replace_personal(msgs[i].msg, ({previous_object(), this_player()}), 1),
+ msgs[i].type | MSG_BS_LEAVE_LFS | commontypes,
+ action,
+ msgs[i].prefix);
+ if(res[0] == MSG_DELIVERED)
+ {
+ res[1] = i;
+ break;
+ }
+ }
+ return res;
+}
diff --git a/std/living/comm_structs.c b/std/living/comm_structs.c
new file mode 100644
index 0000000..5105dbd
--- /dev/null
+++ b/std/living/comm_structs.c
@@ -0,0 +1,9 @@
+#pragma strict_types, save_types, pedantic, range_check
+#pragma no_clone
+
+protected struct msg_s
+{
+ string msg;
+ int type;
+ string prefix;
+};