ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_object.C
(Generate patch)

Comparing deliantra/server/server/c_object.C (file contents):
Revision 1.41 by root, Sun Mar 18 03:05:40 2007 UTC vs.
Revision 1.42 by root, Mon Apr 23 18:09:57 2007 UTC

1041 } 1041 }
1042 1042
1043 return 0; 1043 return 0;
1044} 1044}
1045 1045
1046/* op is the player 1046std::string
1047 * tmp is the monster being examined. 1047object::describe_monster (object *who)
1048 */
1049void
1050examine_monster (object *op, object *tmp)
1051{ 1048{
1049 dynbuf_text buf (512, 512);
1050
1052 object *mon = tmp->head ? tmp->head : tmp; 1051 object *mon = head ? head : this;
1053 1052
1054 if (QUERY_FLAG (mon, FLAG_UNDEAD)) 1053 if (QUERY_FLAG (mon, FLAG_UNDEAD))
1055 new_draw_info (NDI_UNIQUE, 0, op, "It is an undead force."); 1054 buf << "It is an undead force.\n";
1055
1056 if (mon->level > op->level) 1056 if (mon->level > who->level)
1057 new_draw_info (NDI_UNIQUE, 0, op, "It is likely more powerful than you."); 1057 buf << "It is likely more powerful than you.\n";
1058 else if (mon->level < op->level) 1058 else if (mon->level < who->level)
1059 new_draw_info (NDI_UNIQUE, 0, op, "It is likely less powerful than you."); 1059 buf << "It is likely less powerful than you.\n";
1060 else 1060 else
1061 new_draw_info (NDI_UNIQUE, 0, op, "It is probably as powerful as you."); 1061 buf << "It is probably as powerful as you.\n";
1062
1062 if (mon->attacktype & AT_ACID) 1063 if (mon->attacktype & AT_ACID)
1063 new_draw_info (NDI_UNIQUE, 0, op, "You seem to smell an acrid odor."); 1064 buf << "You seem to smell an acrid odor.\n";
1064 1065
1065 /* Anyone know why this used to use the clone value instead of the 1066 /* Anyone know why this used to use the clone value instead of the
1066 * maxhp field? This seems that it should give more accurate results. 1067 * maxhp field? This seems that it should give more accurate results.
1067 */ 1068 */
1068 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) 1069 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1))
1069 { /* From 1-4 */ 1070 { /* From 1-4 */
1070 case 1: 1071 case 1:
1071 new_draw_info (NDI_UNIQUE, 0, op, "It is in a bad shape."); 1072 buf << "It is in a bad shape.\n";
1072 break; 1073 break;
1073 case 2: 1074 case 2:
1074 new_draw_info (NDI_UNIQUE, 0, op, "It is hurt."); 1075 buf << "It is hurt.\n";
1075 break; 1076 break;
1076 case 3: 1077 case 3:
1077 new_draw_info (NDI_UNIQUE, 0, op, "It is somewhat hurt."); 1078 buf << "It is somewhat hurt.\n";
1078 break; 1079 break;
1079 case 4: 1080 case 4:
1080 new_draw_info (NDI_UNIQUE, 0, op, "It is in excellent shape."); 1081 buf << "It is in excellent shape.\n";
1081 break; 1082 break;
1082 } 1083 }
1084
1083 if (present_in_ob (POISONING, mon) != NULL) 1085 if (present_in_ob (POISONING, mon))
1084 new_draw_info (NDI_UNIQUE, 0, op, "It looks very ill."); 1086 buf << "It looks very ill.\n";
1087
1088 return buf;
1085} 1089}
1086 1090
1087/* tmp is the object being described, pl is who is examing it. */ 1091/* tmp is the object being described, pl is who is examing it. */
1088const char * 1092const char *
1089long_desc (object *tmp, object *pl) 1093long_desc (object *tmp, object *pl)
1090{ 1094{
1091 static char buf[VERY_BIG_BUF]; 1095 static std::string s = tmp->long_desc (pl);
1092 const char *cp; 1096 return s.c_str ();
1097}
1093 1098
1094 if (tmp == NULL) 1099std::string
1095 return ""; 1100object::long_desc (object *who)
1101{
1102 std::string buf (query_name (this));
1096 1103
1097 buf[0] = '\0';
1098 switch (tmp->type) 1104 switch (type)
1099 { 1105 {
1100 case RING: 1106 case RING:
1101 case SKILL: 1107 case SKILL:
1102 case WEAPON: 1108 case WEAPON:
1103 case ARMOUR: 1109 case ARMOUR:
1114 case FOOD: 1120 case FOOD:
1115 case DRINK: 1121 case DRINK:
1116 case FLESH: 1122 case FLESH:
1117 case SKILL_TOOL: 1123 case SKILL_TOOL:
1118 case POWER_CRYSTAL: 1124 case POWER_CRYSTAL:
1119 if (*(cp = describe_item (tmp, pl))) 1125 {
1126 //TODO
1127 const char *cp = ::describe_item (this, who);
1128
1129 if (*cp)
1130 {
1131 buf.append (" ");
1132 buf.append (cp);
1133 }
1134 }
1135 }
1136
1137 return buf;
1138}
1139
1140/* op is the player
1141 * tmp is the monster being examined.
1142 */
1143void
1144examine_monster (object *op, object *tmp)
1145{
1146 new_draw_info (NDI_UNIQUE, 0, op, tmp->describe_monster (op).c_str ());
1147}
1148
1149std::string
1150object::describe (object *who)
1151{
1152 dynbuf_text buf (1024, 1024);
1153
1154 buf.printf ("That is %s\n", long_desc (who).c_str ());
1155
1156 if (custom_name)
1157 buf,printf ("You call it %s\n", &custom_name);
1158
1159 switch (type)
1160 {
1161 case SPELLBOOK:
1162 if (flag [FLAG_IDENTIFIED] && inv)
1163 buf.printf ("%s is a %s %s spell\n", &inv->name, get_levelnumber (inv->level), &inv->skill);
1164 break;
1165
1166 case BOOK:
1167 if (msg)
1168 buf << "Something is written in it.\n";
1169 break;
1170
1171 case CONTAINER:
1172 if (race != NULL)
1120 { 1173 {
1174 if (weight_limit && stats.Str < 100)
1175 buf.printf ("It can hold only %s and its weight limit is %.1f kg.\n",
1176 &race, weight_limit / (10.0 * (100 - stats.Str)));
1121 int len; 1177 else
1122 1178 buf.printf ("It can hold only %s.\n", &race);
1123 assign (buf, query_name (tmp));
1124 len = strlen (buf);
1125 if (len < VERY_BIG_BUF - 5)
1126 {
1127 /* Since we know the length, we save a few cpu cycles by using
1128 * it instead of calling strcat */
1129 strcpy (buf + len, " ");
1130 len++;
1131 assign (buf + len, cp, VERY_BIG_BUF - len - 1);
1132 }
1133 } 1179 }
1134 } 1180 else if (weight_limit && stats.Str < 100)
1135 1181 buf.printf ("Its weight limit is %.1f kg.\n", weight_limit / (10.0 * (100 - stats.Str)));
1136 if (buf[0] == '\0')
1137 assign (buf, query_name (tmp));
1138
1139 return buf;
1140}
1141
1142void
1143examine (object *op, object *tmp)
1144{
1145 char buf[VERY_BIG_BUF];
1146 int i;
1147
1148 if (tmp == NULL || tmp->type == CLOSE_CON)
1149 return;
1150
1151 strcpy (buf, "That is ");
1152 strncat (buf, long_desc (tmp, op), VERY_BIG_BUF - strlen (buf) - 1);
1153 buf[VERY_BIG_BUF - 1] = 0;
1154
1155 new_draw_info (NDI_UNIQUE, 0, op, buf);
1156 buf[0] = '\0';
1157
1158 if (tmp->custom_name)
1159 {
1160 strcpy (buf, "You call it ");
1161 strncat (buf, tmp->custom_name, VERY_BIG_BUF - strlen (buf) - 1);
1162 buf[VERY_BIG_BUF - 1] = 0;
1163 new_draw_info (NDI_UNIQUE, 0, op, buf);
1164 buf[0] = '\0';
1165 }
1166
1167 switch (tmp->type)
1168 {
1169 case SPELLBOOK:
1170 if (QUERY_FLAG (tmp, FLAG_IDENTIFIED) && tmp->inv)
1171 {
1172 sprintf (buf, "%s is a %s level %s spell", &tmp->inv->name, get_levelnumber (tmp->inv->level), &tmp->inv->skill);
1173 }
1174 break; 1182 break;
1175 1183
1176 case BOOK: 1184 case WAND:
1177 if (tmp->msg != NULL) 1185 if (flag [FLAG_IDENTIFIED])
1178 strcpy (buf, "Something is written in it."); 1186 buf.printf ("It has %s charges left.\n", stats.food);
1179 break; 1187 break;
1180
1181 case CONTAINER:
1182 if (tmp->race != NULL)
1183 {
1184 if (tmp->weight_limit && tmp->stats.Str < 100)
1185 sprintf (buf, "It can hold only %s and its weight limit is %.1f kg.",
1186 &tmp->race, tmp->weight_limit / (10.0 * (100 - tmp->stats.Str)));
1187 else
1188 sprintf (buf, "It can hold only %s.", &tmp->race);
1189 }
1190 else if (tmp->weight_limit && tmp->stats.Str < 100)
1191 sprintf (buf, "Its weight limit is %.1f kg.", tmp->weight_limit / (10.0 * (100 - tmp->stats.Str)));
1192 break;
1193
1194 case WAND:
1195 if (QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1196 sprintf (buf, "It has %d charges left.", tmp->stats.food);
1197 break;
1198 }
1199
1200 if (buf[0] != '\0')
1201 new_draw_info (NDI_UNIQUE, 0, op, buf);
1202
1203 if (tmp->materialname != NULL && !tmp->msg)
1204 { 1188 }
1189
1190 if (materialname && !msg)
1205 sprintf (buf, "It is made of: %s.", &tmp->materialname); 1191 buf.printf ("It is made of: %s.\n", &materialname);
1206 new_draw_info (NDI_UNIQUE, 0, op, buf); 1192
1207 } 1193 if (who)
1208 /* Where to wear this item */ 1194 /* Where to wear this item */
1209 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1195 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1210 {
1211 if (tmp->body_info[i] < -1) 1196 if (body_info [i])
1197 {
1198 buf << "It goes ";
1199 buf << (who->body_info[i] ? body_locations[i].use_name : body_locations[i].nonuse_name);
1200
1201 if (body_info[i] < -1 && who->body_info[i])
1202 buf.printf ("(%d)", -body_info[i]);
1203
1204 buf << ".\n";
1212 { 1205 }
1213 if (op->body_info[i]) 1206
1214 new_draw_info_format (NDI_UNIQUE, 0, op, "It goes %s (%d)", body_locations[i].use_name, -tmp->body_info[i]); 1207 if (weight)
1208 buf.printf (nrof > 1 ? "They weigh %3.3f kg.\n" : "It weighs %3.3f kg.\n", weight * (nrof ? nrof : 1) / 1000.0);
1209
1210 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who)
1211 {
1212 buf.printf ("You reckon %s worth %s.\n", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX));
1213
1214 if (is_in_shop (who))
1215 {
1216 if (flag [FLAG_UNPAID])
1217 buf.printf ("%s would cost you %s.\n", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP));
1215 else 1218 else
1216 new_draw_info_format (NDI_UNIQUE, 0, op, "It goes %s", body_locations[i].nonuse_name);
1217 }
1218 else if (tmp->body_info[i])
1219 {
1220 if (op->body_info[i])
1221 new_draw_info_format (NDI_UNIQUE, 0, op, "It goes %s", body_locations[i].use_name);
1222 else
1223 new_draw_info_format (NDI_UNIQUE, 0, op, "It goes %s", body_locations[i].nonuse_name);
1224 }
1225 }
1226
1227 if (tmp->weight)
1228 {
1229 sprintf (buf, tmp->nrof > 1 ? "They weigh %3.3f kg." : "It weighs %3.3f kg.", tmp->weight * (tmp->nrof ? tmp->nrof : 1) / 1000.0);
1230 new_draw_info (NDI_UNIQUE, 0, op, buf);
1231 }
1232
1233 if (tmp->value && !QUERY_FLAG (tmp, FLAG_STARTEQUIP) && !QUERY_FLAG (tmp, FLAG_NO_PICK))
1234 {
1235 sprintf (buf, "You reckon %s worth %s.", tmp->nrof > 1 ? "they are" : "it is", query_cost_string (tmp, op, F_TRUE | F_APPROX));
1236 new_draw_info (NDI_UNIQUE, 0, op, buf);
1237 if (is_in_shop (op))
1238 {
1239 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1240 sprintf (buf, "%s would cost you %s.", tmp->nrof > 1 ? "They" : "It", query_cost_string (tmp, op, F_BUY | F_SHOP));
1241 else
1242 sprintf (buf, "You are offered %s for %s.", query_cost_string (tmp, op, F_SELL + F_SHOP), tmp->nrof > 1 ? "them" : "it"); 1219 buf.printf ("You are offered %s for %s.\n", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it");
1243 new_draw_info (NDI_UNIQUE, 0, op, buf);
1244 } 1220 }
1245 } 1221 }
1246 1222
1247 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1223 if (flag [FLAG_MONSTER])
1248 examine_monster (op, tmp); 1224 buf << describe_monster (who);
1249 1225
1250 /* Is this item buildable? */ 1226 /* Is this item buildable? */
1251 if (QUERY_FLAG (tmp, FLAG_IS_BUILDABLE)) 1227 if (flag [FLAG_IS_BUILDABLE])
1252 new_draw_info (NDI_UNIQUE, 0, op, "This is a buildable item."); 1228 buf << "This is a buildable item.\n";
1253 1229
1254 /* Does the object have a message? Don't show message for all object 1230 /* Does the object have a message? Don't show message for all object
1255 * types - especially if the first entry is a match 1231 * types - especially if the first entry is a match
1256 */ 1232 */
1257 if (tmp->msg && tmp->type != EXIT && tmp->type != BOOK && tmp->type != CORPSE && !tmp->move_on && strncasecmp (tmp->msg, "@match", 7)) 1233 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && strncasecmp (msg, "@match", 7))
1258 { 1234 {
1259
1260 /* This is just a hack so when identifying the items, we print 1235 /* This is just a hack so when identifying the items, we print
1261 * out the extra message 1236 * out the extra message
1262 */ 1237 */
1263 if (need_identify (tmp) && QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1238 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1264 new_draw_info (NDI_UNIQUE, 0, op, "The object has a story:"); 1239 buf << "The object has a story:\n";
1265 1240
1241 buf << msg << '\n';
1242 }
1243
1244 buf << '\n';
1245
1246 return std::string (buf.linearise (), buf.size ());
1247}
1248
1249void
1250examine (object *op, object *tmp)
1251{
1252 std::string s = tmp->describe (op);
1253
1266 new_draw_info (NDI_UNIQUE, 0, op, tmp->msg); 1254 new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
1267 }
1268 new_draw_info (NDI_UNIQUE, 0, op, " "); /* Blank line */
1269} 1255}
1270 1256
1271/* 1257/*
1272 * inventory prints object's inventory. If inv==NULL then print player's 1258 * inventory prints object's inventory. If inv==NULL then print player's
1273 * inventory. 1259 * inventory.
1504 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1490 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1");
1505 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all"); 1491 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all");
1506 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'."); 1492 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'.");
1507 return 1; 1493 return 1;
1508 } 1494 }
1495
1509 op->contr->search_str[0] = '\0'; 1496 op->contr->search_str[0] = '\0';
1510 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1497 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1511 op->update_stats (); 1498 op->update_stats ();
1512 return 1; 1499 return 1;
1513 } 1500 }
1501
1514 if ((int) strlen (params) >= MAX_BUF) 1502 if ((int) strlen (params) >= MAX_BUF)
1515 { 1503 {
1516 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1504 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1517 return 1; 1505 return 1;
1518 } 1506 }
1507
1519 strcpy (op->contr->search_str, params); 1508 strcpy (op->contr->search_str, params);
1520 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1509 sprintf (buf, "Searching for '%s'.", op->contr->search_str);
1521 new_draw_info (NDI_UNIQUE, 0, op, buf); 1510 new_draw_info (NDI_UNIQUE, 0, op, buf);
1522 op->update_stats (); 1511 op->update_stats ();
1523 return 1; 1512 return 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines