1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_c_object_c = |
|
|
4 | * "$Id: c_object.C,v 1.14 2006/09/10 15:59:57 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
933 | nextinv = nextinv->below; |
927 | nextinv = nextinv->below; |
934 | if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED)) |
928 | if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED)) |
935 | { |
929 | { |
936 | switch (curinv->type) |
930 | switch (curinv->type) |
937 | { |
931 | { |
938 | case HORN: |
932 | case HORN: |
939 | case BOOK: |
933 | case BOOK: |
940 | case SPELLBOOK: |
934 | case SPELLBOOK: |
941 | case GIRDLE: |
935 | case GIRDLE: |
942 | case AMULET: |
936 | case AMULET: |
943 | case RING: |
937 | case RING: |
944 | case CLOAK: |
938 | case CLOAK: |
945 | case BOOTS: |
939 | case BOOTS: |
946 | case GLOVES: |
940 | case GLOVES: |
947 | case BRACERS: |
941 | case BRACERS: |
948 | case SCROLL: |
942 | case SCROLL: |
949 | case ARMOUR_IMPROVER: |
943 | case ARMOUR_IMPROVER: |
950 | case WEAPON_IMPROVER: |
944 | case WEAPON_IMPROVER: |
951 | case WAND: |
945 | case WAND: |
952 | case ROD: |
946 | case ROD: |
953 | case POTION: |
947 | case POTION: |
954 | drop (op, curinv); |
948 | drop (op, curinv); |
955 | curinv = nextinv; |
949 | curinv = nextinv; |
956 | break; |
950 | break; |
957 | default: |
951 | default: |
958 | curinv = nextinv; |
952 | curinv = nextinv; |
959 | break; |
953 | break; |
960 | } |
954 | } |
961 | } |
955 | } |
962 | curinv = nextinv; |
956 | curinv = nextinv; |
963 | } |
957 | } |
964 | } |
958 | } |
… | |
… | |
1139 | /* Anyone know why this used to use the clone value instead of the |
1133 | /* Anyone know why this used to use the clone value instead of the |
1140 | * maxhp field? This seems that it should give more accurate results. |
1134 | * maxhp field? This seems that it should give more accurate results. |
1141 | */ |
1135 | */ |
1142 | switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) |
1136 | switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) |
1143 | { /* From 1-4 */ |
1137 | { /* From 1-4 */ |
1144 | case 1: |
1138 | case 1: |
1145 | new_draw_info (NDI_UNIQUE, 0, op, "It is in a bad shape."); |
1139 | new_draw_info (NDI_UNIQUE, 0, op, "It is in a bad shape."); |
1146 | break; |
1140 | break; |
1147 | case 2: |
1141 | case 2: |
1148 | new_draw_info (NDI_UNIQUE, 0, op, "It is hurt."); |
1142 | new_draw_info (NDI_UNIQUE, 0, op, "It is hurt."); |
1149 | break; |
1143 | break; |
1150 | case 3: |
1144 | case 3: |
1151 | new_draw_info (NDI_UNIQUE, 0, op, "It is somewhat hurt."); |
1145 | new_draw_info (NDI_UNIQUE, 0, op, "It is somewhat hurt."); |
1152 | break; |
1146 | break; |
1153 | case 4: |
1147 | case 4: |
1154 | new_draw_info (NDI_UNIQUE, 0, op, "It is in excellent shape."); |
1148 | new_draw_info (NDI_UNIQUE, 0, op, "It is in excellent shape."); |
1155 | break; |
1149 | break; |
1156 | } |
1150 | } |
1157 | if (present_in_ob (POISONING, mon) != NULL) |
1151 | if (present_in_ob (POISONING, mon) != NULL) |
1158 | new_draw_info (NDI_UNIQUE, 0, op, "It looks very ill."); |
1152 | new_draw_info (NDI_UNIQUE, 0, op, "It looks very ill."); |
1159 | } |
1153 | } |
1160 | |
1154 | |
… | |
… | |
1170 | return ""; |
1164 | return ""; |
1171 | |
1165 | |
1172 | buf[0] = '\0'; |
1166 | buf[0] = '\0'; |
1173 | switch (tmp->type) |
1167 | switch (tmp->type) |
1174 | { |
1168 | { |
1175 | case RING: |
1169 | case RING: |
1176 | case SKILL: |
1170 | case SKILL: |
1177 | case WEAPON: |
1171 | case WEAPON: |
1178 | case ARMOUR: |
1172 | case ARMOUR: |
1179 | case BRACERS: |
1173 | case BRACERS: |
1180 | case HELMET: |
1174 | case HELMET: |
1181 | case SHIELD: |
1175 | case SHIELD: |
1182 | case BOOTS: |
1176 | case BOOTS: |
1183 | case GLOVES: |
1177 | case GLOVES: |
1184 | case AMULET: |
1178 | case AMULET: |
1185 | case GIRDLE: |
1179 | case GIRDLE: |
1186 | case BOW: |
1180 | case BOW: |
1187 | case ARROW: |
1181 | case ARROW: |
1188 | case CLOAK: |
1182 | case CLOAK: |
1189 | case FOOD: |
1183 | case FOOD: |
1190 | case DRINK: |
1184 | case DRINK: |
1191 | case FLESH: |
1185 | case FLESH: |
1192 | case SKILL_TOOL: |
1186 | case SKILL_TOOL: |
1193 | case POWER_CRYSTAL: |
1187 | case POWER_CRYSTAL: |
1194 | if (*(cp = describe_item (tmp, pl)) != '\0') |
1188 | if (*(cp = describe_item (tmp, pl)) != '\0') |
1195 | { |
1189 | { |
1196 | int len; |
1190 | int len; |
1197 | |
1191 | |
1198 | strncpy (buf, query_name (tmp), VERY_BIG_BUF - 1); |
1192 | assign (buf, query_name (tmp)); |
1199 | buf[VERY_BIG_BUF - 1] = 0; |
|
|
1200 | len = strlen (buf); |
1193 | len = strlen (buf); |
1201 | if (len < VERY_BIG_BUF - 5) |
1194 | if (len < VERY_BIG_BUF - 5) |
1202 | { |
1195 | { |
1203 | /* Since we know the length, we save a few cpu cycles by using |
1196 | /* Since we know the length, we save a few cpu cycles by using |
1204 | * it instead of calling strcat */ |
1197 | * it instead of calling strcat */ |
1205 | strcpy (buf + len, " "); |
1198 | strcpy (buf + len, " "); |
1206 | len++; |
1199 | len++; |
1207 | strncpy (buf + len, cp, VERY_BIG_BUF - len - 1); |
1200 | assign (buf + len, cp, VERY_BIG_BUF - len - 1); |
1208 | buf[VERY_BIG_BUF - 1] = 0; |
|
|
1209 | } |
1201 | } |
1210 | } |
1202 | } |
1211 | } |
1203 | } |
|
|
1204 | |
1212 | if (buf[0] == '\0') |
1205 | if (buf[0] == '\0') |
1213 | { |
1206 | assign (buf, query_name (tmp)); |
1214 | strncpy (buf, query_name (tmp), VERY_BIG_BUF - 1); |
|
|
1215 | buf[VERY_BIG_BUF - 1] = 0; |
|
|
1216 | } |
|
|
1217 | |
1207 | |
1218 | return buf; |
1208 | return buf; |
1219 | } |
1209 | } |
1220 | |
1210 | |
1221 | void |
1211 | void |
… | |
… | |
1243 | buf[0] = '\0'; |
1233 | buf[0] = '\0'; |
1244 | } |
1234 | } |
1245 | |
1235 | |
1246 | switch (tmp->type) |
1236 | switch (tmp->type) |
1247 | { |
1237 | { |
1248 | case SPELLBOOK: |
1238 | case SPELLBOOK: |
1249 | if (QUERY_FLAG (tmp, FLAG_IDENTIFIED) && tmp->inv) |
1239 | if (QUERY_FLAG (tmp, FLAG_IDENTIFIED) && tmp->inv) |
1250 | { |
1240 | { |
1251 | sprintf (buf, "%s is a %s level %s spell", &tmp->inv->name, get_levelnumber (tmp->inv->level), &tmp->inv->skill); |
1241 | sprintf (buf, "%s is a %s level %s spell", &tmp->inv->name, get_levelnumber (tmp->inv->level), &tmp->inv->skill); |
1252 | } |
1242 | } |
1253 | break; |
1243 | break; |
1254 | |
1244 | |
1255 | case BOOK: |
1245 | case BOOK: |
1256 | if (tmp->msg != NULL) |
1246 | if (tmp->msg != NULL) |
1257 | strcpy (buf, "Something is written in it."); |
1247 | strcpy (buf, "Something is written in it."); |
1258 | break; |
1248 | break; |
1259 | |
1249 | |
1260 | case CONTAINER: |
1250 | case CONTAINER: |
1261 | if (tmp->race != NULL) |
1251 | if (tmp->race != NULL) |
1262 | { |
1252 | { |
1263 | if (tmp->weight_limit && tmp->stats.Str < 100) |
1253 | if (tmp->weight_limit && tmp->stats.Str < 100) |
1264 | sprintf (buf, "It can hold only %s and its weight limit is %.1f kg.", |
1254 | sprintf (buf, "It can hold only %s and its weight limit is %.1f kg.", |
1265 | &tmp->race, tmp->weight_limit / (10.0 * (100 - tmp->stats.Str))); |
1255 | &tmp->race, tmp->weight_limit / (10.0 * (100 - tmp->stats.Str))); |
1266 | else |
1256 | else |
1267 | sprintf (buf, "It can hold only %s.", &tmp->race); |
1257 | sprintf (buf, "It can hold only %s.", &tmp->race); |
1268 | } |
1258 | } |
1269 | else if (tmp->weight_limit && tmp->stats.Str < 100) |
1259 | else if (tmp->weight_limit && tmp->stats.Str < 100) |
1270 | sprintf (buf, "Its weight limit is %.1f kg.", tmp->weight_limit / (10.0 * (100 - tmp->stats.Str))); |
1260 | sprintf (buf, "Its weight limit is %.1f kg.", tmp->weight_limit / (10.0 * (100 - tmp->stats.Str))); |
1271 | break; |
1261 | break; |
1272 | |
1262 | |
1273 | case WAND: |
1263 | case WAND: |
1274 | if (QUERY_FLAG (tmp, FLAG_IDENTIFIED)) |
1264 | if (QUERY_FLAG (tmp, FLAG_IDENTIFIED)) |
1275 | sprintf (buf, "It has %d charges left.", tmp->stats.food); |
1265 | sprintf (buf, "It has %d charges left.", tmp->stats.food); |
1276 | break; |
1266 | break; |
1277 | } |
1267 | } |
1278 | |
1268 | |
1279 | if (buf[0] != '\0') |
1269 | if (buf[0] != '\0') |
1280 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1270 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1281 | |
1271 | |
… | |
… | |
1534 | void |
1524 | void |
1535 | set_pickup_mode (object *op, int i) |
1525 | set_pickup_mode (object *op, int i) |
1536 | { |
1526 | { |
1537 | switch (op->contr->mode = i) |
1527 | switch (op->contr->mode = i) |
1538 | { |
1528 | { |
1539 | case 0: |
1529 | case 0: |
1540 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up."); |
1530 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up."); |
1541 | break; |
1531 | break; |
1542 | case 1: |
1532 | case 1: |
1543 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item."); |
1533 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item."); |
1544 | break; |
1534 | break; |
1545 | case 2: |
1535 | case 2: |
1546 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop."); |
1536 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop."); |
1547 | break; |
1537 | break; |
1548 | case 3: |
1538 | case 3: |
1549 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up."); |
1539 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up."); |
1550 | break; |
1540 | break; |
1551 | case 4: |
1541 | case 4: |
1552 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items."); |
1542 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items."); |
1553 | break; |
1543 | break; |
1554 | case 5: |
1544 | case 5: |
1555 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop."); |
1545 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop."); |
1556 | break; |
1546 | break; |
1557 | case 6: |
1547 | case 6: |
1558 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items."); |
1548 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items."); |
1559 | break; |
1549 | break; |
1560 | case 7: |
1550 | case 7: |
1561 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems"); |
1551 | new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems"); |
1562 | break; |
1552 | break; |
1563 | } |
1553 | } |
1564 | } |
1554 | } |
1565 | |
1555 | |
1566 | int |
1556 | int |
1567 | command_search_items (object *op, char *params) |
1557 | command_search_items (object *op, char *params) |
… | |
… | |
1641 | if (!closebrace) |
1631 | if (!closebrace) |
1642 | { |
1632 | { |
1643 | new_draw_info (NDI_UNIQUE, 0, op, "Syntax error!"); |
1633 | new_draw_info (NDI_UNIQUE, 0, op, "Syntax error!"); |
1644 | return 1; |
1634 | return 1; |
1645 | } |
1635 | } |
|
|
1636 | |
1646 | /* Sanity check for buffer overruns */ |
1637 | /* Sanity check for buffer overruns */ |
1647 | if ((closebrace - params) > 127) |
1638 | if ((closebrace - params) > 127) |
1648 | { |
1639 | { |
1649 | new_draw_info (NDI_UNIQUE, 0, op, "Old name too long (up to 127 characters allowed)!"); |
1640 | new_draw_info (NDI_UNIQUE, 0, op, "Old name too long (up to 127 characters allowed)!"); |
1650 | return 1; |
1641 | return 1; |
1651 | } |
1642 | } |
|
|
1643 | |
1652 | /* Copy the old name */ |
1644 | /* Copy the old name */ |
1653 | strncpy (buf, params + 1, closebrace - params - 1); |
1645 | assign (buf, params + 1, closebrace - params - 1); |
1654 | buf[closebrace - params - 1] = '\0'; |
|
|
1655 | |
1646 | |
1656 | /* Find best matching item */ |
1647 | /* Find best matching item */ |
1657 | item = find_best_object_match (op, buf); |
1648 | item = find_best_object_match (op, buf); |
1658 | if (!item) |
1649 | if (!item) |
1659 | { |
1650 | { |
… | |
… | |
1702 | new_draw_info (NDI_UNIQUE, 0, op, "New name too long (up to 127 characters allowed)!"); |
1693 | new_draw_info (NDI_UNIQUE, 0, op, "New name too long (up to 127 characters allowed)!"); |
1703 | return 1; |
1694 | return 1; |
1704 | } |
1695 | } |
1705 | |
1696 | |
1706 | /* Copy the new name */ |
1697 | /* Copy the new name */ |
1707 | strncpy (buf, params + 1, closebrace - params - 1); |
1698 | assign (buf, params + 1, closebrace - params - 1); |
1708 | buf[closebrace - params - 1] = '\0'; |
|
|
1709 | |
1699 | |
1710 | /* Let's check it for weird characters */ |
1700 | /* Let's check it for weird characters */ |
1711 | for (counter = 0; counter < strlen (buf); counter++) |
1701 | for (counter = 0; counter < strlen (buf); counter++) |
1712 | { |
1702 | { |
1713 | if (isalnum (buf[counter])) |
1703 | if (isalnum (buf[counter])) |