| 1 | /* |
| 2 | * Crossfire -- cooperative multi-player graphical RPG and adventure game |
| 3 | * |
| 4 | * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team |
| 5 | * Copyright (c) 1992 Frank Tore Johansen |
| 6 | * |
| 7 | * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are |
| 8 | * welcome to redistribute it under certain conditions. For details, please |
| 9 | * see COPYING and LICENSE. |
| 10 | * |
| 11 | * The authors can be reached via e-mail at <[email protected]>. |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * @file |
| 16 | * This file contains description-related methods that are common to many |
| 17 | * classes of objects. |
| 18 | */ |
| 19 | |
| 20 | #include "global.h" |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | #include "ob_methods.h" |
| 26 | #include "ob_types.h" |
| 27 | |
| 28 | /** |
| 29 | * Describes an object, seen by a given observer. |
| 30 | * @param context The method context |
| 31 | * @param op The object to describe |
| 32 | * @param observer The object to make the description to |
| 33 | * @param use_media_tags If set then media tags may be used in the description |
| 34 | * @param buf Buffer that will contain the description |
| 35 | * @param size buf's size. |
| 36 | */ |
| 37 | void common_ob_describe(const ob_methods *context, const object *op, const object *observer, int use_media_tags, char *buf, size_t size) { |
| 38 | char *desc; |
| 39 | |
| 40 | buf[0] = '\0'; |
| 41 | |
| 42 | if (op == NULL) |
| 43 | return; |
| 44 | |
| 45 | desc = stringbuffer_finish(describe_item(op, observer, use_media_tags, NULL)); |
| 46 | if (desc[0] != '\0') { |
| 47 | size_t len; |
| 48 | |
| 49 | query_name(op, buf, size-1); |
| 50 | buf[size-1] = 0; |
| 51 | len = strlen(buf); |
| 52 | if ((len+5) < size) { |
| 53 | /* Since we know the length, we save a few cpu cycles by using |
| 54 | * it instead of calling strcat */ |
| 55 | strcpy(buf+len, " "); |
| 56 | len++; |
| 57 | strncpy(buf+len, desc, size-len-1); |
| 58 | buf[size-1] = 0; |
| 59 | } |
| 60 | } |
| 61 | free(desc); |
| 62 | if (buf[0] == '\0') { |
| 63 | query_name(op, buf, size-1); |
| 64 | buf[size-1] = 0; |
| 65 | } |
| 66 | } |