View Issue Details

IDProjectCategoryView StatusLast Update
0000471LDMud 3.3Implementationpublic2008-07-26 14:17
Reporterfufu Assigned Tofufu  
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
Summary0000471: use tell_object_str() function in e_say() and e_tell_room()
Description(was: The tell_object_str() function in object.c (and object.h) is unused and can be removed.)
See Gnomi's comment below.
TagsNo tags attached.

Relationships

related to 0000472 resolvedfufu say(), tell_room(), printf() and tell_object() efuns truncate output on \0 

Activities

zesstra

2008-07-08 17:06

administrator   ~0000687

I agree. Does anybody object to remove the function?

Gnomi

2008-07-09 02:55

manager   ~0000696

I vote for actually using this function.

e_say() and e_tell_room() do exactly the same thing as tell_object_str(), so if they would call tell_object_str instead we would have less double code.

zesstra

2008-07-09 03:45

administrator   ~0000699

Good point, that is even better. ;-) Removing duplicate code is always nice.
In this case, this is related to Fuchurs Bug 0000472.

2008-07-09 12:43

 

use-tell_object.patch (3,955 bytes)   
diff --git a/src/object.c b/src/object.c
index 86ab239..9a355fe 100644
--- a/src/object.c
+++ b/src/object.c
@@ -1299,34 +1299,6 @@ tell_object (object_t *ob, string_t *str)
 }
 
 /*-------------------------------------------------------------------------*/
-void
-tell_object_str (object_t *ob, const char *str)
-
-/* Send message <str> to object <ob>. If <ob> is an interactive player,
- * it will go to his screen (unless a shadow catches it - see shadow_catch_
- * message() ). If <ob> is not interactive, the message will go
- * to the lfun 'catch_tell()' via a call to tell_npc().
- */
-
-{
-    object_t *save_command_giver;
-    interactive_t *ip;
-
-    if (ob->flags & O_DESTRUCTED)
-        return;
-
-    if (O_SET_INTERACTIVE(ip, ob))
-    {
-        save_command_giver = command_giver;
-        command_giver = ob;
-        add_message("%s", str);
-        command_giver = save_command_giver;
-        return;
-    }
-    tell_npc_str(ob, str);
-}
-
-/*-------------------------------------------------------------------------*/
 Bool
 shadow_catch_message (object_t *ob, const char *str)
 
@@ -4607,7 +4579,7 @@ e_say (svalue_t *v, vector_t *avoid)
     object_t *ob;
     object_t *save_command_giver = command_giver;
     object_t *origin;
-    char *message;
+    string_t *message;
 #define INITIAL_MAX_RECIPIENTS 48
     int max_recipients = INITIAL_MAX_RECIPIENTS;
       /* Current size of the recipients table.
@@ -4626,7 +4598,6 @@ e_say (svalue_t *v, vector_t *avoid)
                  &first_recipients[INITIAL_MAX_RECIPIENTS-1];
       /* Last entry in the current table.
        */
-    object_t *save_again;
 
     /* Determine the command_giver to use */
     if (current_object->flags & O_ENABLE_COMMANDS)
@@ -4730,7 +4701,7 @@ e_say (svalue_t *v, vector_t *avoid)
     switch(v->type)
     {
     case T_STRING:
-        message = get_txt(v->u.str);
+        message = v->u.str;
         break;
 
     case T_OBJECT:
@@ -4777,22 +4748,12 @@ e_say (svalue_t *v, vector_t *avoid)
 
     for (curr_recipient = recipients; NULL != (ob = *curr_recipient++); )
     {
-        interactive_t *ip;
-
         if (ob->flags & O_DESTRUCTED)
             continue;
         stmp.u.ob = ob;
         if (lookup_key(&stmp, avoid) >= 0)
             continue;
-        if (!(O_SET_INTERACTIVE(ip, ob)))
-        {
-            tell_npc_str(ob, message);
-            continue;
-        }
-        save_again = command_giver;
-        command_giver = ob;
-        add_message("%s", message);
-        command_giver = save_again;
+        tell_object (ob, message);
     }
 
     pop_stack(); /* free avoid alist */
@@ -4901,12 +4862,11 @@ e_tell_room (object_t *room, svalue_t *v, vector_t *avoid)
 
 {
     object_t *ob;
-    object_t *save_command_giver;
     int num_recipients = 0;
     object_t *some_recipients[20];
     object_t **recipients;
     object_t **curr_recipient;
-    char *message;
+    string_t *message;
     static svalue_t stmp = { T_OBJECT, } ;
 
     /* Like in say(), collect the possible recipients.
@@ -4950,7 +4910,7 @@ e_tell_room (object_t *room, svalue_t *v, vector_t *avoid)
     switch(v->type)
     {
     case T_STRING:
-        message = get_txt(v->u.str);
+        message = v->u.str;
         break;
 
     case T_OBJECT:
@@ -5003,20 +4963,10 @@ e_tell_room (object_t *room, svalue_t *v, vector_t *avoid)
 
     for (curr_recipient = recipients; NULL != (ob = *curr_recipient++); )
     {
-        interactive_t *ip;
-
         if (ob->flags & O_DESTRUCTED) continue;
         stmp.u.ob = ob;
         if (lookup_key(&stmp, avoid) >= 0) continue;
-        if (!(O_SET_INTERACTIVE(ip, ob)))
-        {
-            tell_npc_str(ob, message);
-            continue;
-        }
-        save_command_giver = command_giver;
-        command_giver = ob;
-        add_message("%s", message);
-        command_giver = save_command_giver;
+        tell_object(ob, message);
     }
 } /* e_tell_room() */
 
use-tell_object.patch (3,955 bytes)   

fufu

2008-07-09 12:44

manager   ~0000705

In fact, we can do both:
e_say and e_tell_room extract their string from a string_t, only to let tell_object_str create a new one if the target is an npc. It's better to use tell_object.
This makes tell_object_str superfluous again.
(see patch)

Gnomi

2008-07-10 10:28

manager   ~0000719

Looks good.

zesstra

2008-07-10 16:24

administrator   ~0000721

Good idea. :)

fufu

2008-07-26 14:17

manager   ~0000751

fixed in commit 2395

Issue History

Date Modified Username Field Change
2006-06-05 12:20 fufu New Issue
2008-06-30 19:18 zesstra Status new => assigned
2008-06-30 19:18 zesstra Assigned To => zesstra
2008-07-08 17:06 zesstra Note Added: 0000687
2008-07-09 02:55 Gnomi Note Added: 0000696
2008-07-09 03:45 zesstra Relationship added related to 0000472
2008-07-09 03:45 zesstra Note Added: 0000699
2008-07-09 10:02 zesstra Assigned To zesstra => fufu
2008-07-09 10:03 fufu Summary remove tell_object_str() function => use tell_object_str() function in e_say() and e_tell_room()
2008-07-09 10:04 fufu Description Updated
2008-07-09 12:43 fufu File Added: use-tell_object.patch
2008-07-09 12:44 fufu Note Added: 0000705
2008-07-10 10:28 Gnomi Note Added: 0000719
2008-07-10 16:24 zesstra Note Added: 0000721
2008-07-26 14:17 fufu Status assigned => resolved
2008-07-26 14:17 fufu Resolution open => fixed
2008-07-26 14:17 fufu Note Added: 0000751