Changeset 36

Show
Ignore:
Timestamp:
04/09/07 10:03:24 (2 years ago)
Author:
takkaria
Message:

First go with #6. This still has some problems, especially with ease-of-use, but is an improvement over the old code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/birth.c

    r33 r36  
    745745{ 
    746746        return handler_aux(cmd, oid, &p_ptr->prace, z_info->p_max, 
    747                                                         0xffffffff, p_name+p_info[oid].name); 
     747                                                        0xffffffff, p_name + p_info[oid].name); 
    748748} 
    749749 
     
    759759{ 
    760760        return handler_aux(cmd, oid, &p_ptr->pclass, z_info->c_max, 
    761                                                         (rp_ptr->choice), c_name+c_info[oid].name); 
     761                                                        (rp_ptr->choice), c_name + c_info[oid].name); 
    762762} 
    763763 
    764764 
    765765static const menu_iter menu_defs[] = { 
    766         {0, 0, 0, display_gender, gender_handler }, 
    767         {0, 0, 0, display_race, race_handler }, 
    768         {0, 0, 0, display_class, class_handler }, 
     766        { 0, 0, 0, display_gender, gender_handler }, 
     767        { 0, 0, 0, display_race, race_handler }, 
     768        { 0, 0, 0, display_class, class_handler }, 
    769769}; 
    770770 
     
    773773static bool choose_character() 
    774774{ 
    775         int i; 
    776  
    777         const region *regions [] = {&gender_region, &race_region, &class_region}; 
    778         byte *values [] = {&p_ptr->psex, &p_ptr->prace, &p_ptr->pclass}; 
    779         int limits [] = {SEX_MALE+1, z_info->p_max, z_info->c_max}; 
    780         const char *hints [] = { 
     775        int i = 0; 
     776 
     777        const region *regions[] = { &gender_region, &race_region, &class_region }; 
     778        byte *values[] = { &p_ptr->psex, &p_ptr->prace, &p_ptr->pclass }; 
     779        int limits[] = { SEX_MALE + 1, z_info->p_max, z_info->c_max }; 
     780 
     781        menu_type menu; 
     782 
     783        const char *hints[] = 
     784        { 
    781785                "Your 'sex' does not have any significant gameplay effects.", 
    782786                "Your 'race' determines various intrinsic factors and bonuses.", 
    783                 "Your 'class' determines various intrinsic abilities and bonuses" }; 
     787                "Your 'class' determines various intrinsic abilities and bonuses" 
     788        }; 
    784789         
    785790        typedef void (*browse_f) (int oid, void *, const region *loc); 
    786         browse_f browse [] = {NULL, race_aux_hook, class_aux_hook }; 
    787         menu_type menu; 
     791        browse_f browse[] = {NULL, race_aux_hook, class_aux_hook }; 
     792 
     793 
    788794        WIPE(&menu, menu); 
    789795        menu.cmd_keys = "?=*\r\n\x18";           /* ?, ,= *, \n, <ctl-X> */ 
    790796 
    791         i = 0; 
    792         while(i < N_ELEMENTS(menu_defs)) 
     797        while (i < (int)N_ELEMENTS(menu_defs)) 
    793798        { 
    794799                event_type cx; 
    795800                int cursor = *values[i]; 
     801 
    796802                menu.flags = MN_NO_TAGS | MN_DBL_TAP; 
    797803                menu.count = limits[i]; 
    798804                menu.browse_hook = browse[i]; 
    799805                menu_init2(&menu, find_menu_skin(MN_SCROLL), &menu_defs[i], regions[i]); 
     806 
    800807                clear_question(); 
    801  
    802808                Term_putstr(QUESTION_COL, QUESTION_ROW, -1, TERM_YELLOW, hints[i]); 
     809 
    803810                cx = menu_select(&menu, &cursor, 0); 
    804                 if(cx.key == ESCAPE) { 
    805                         return FALSE; /* restart */ 
    806                 } 
    807                 else if(cx.type == EVT_BACK) { 
     811 
     812                if (cx.key == ESCAPE) 
     813                { 
     814                        /* Restart */ 
     815                        return FALSE; 
     816                } 
     817                else if (cx.type == EVT_BACK) 
     818                { 
     819                        /* Move back one menu */ 
    808820                        *values[i] = cursor; 
    809821                        region_erase(regions[i]); 
    810822                        i--; 
    811823                } 
    812                 else if(cx.key == '*') { 
     824                else if (cx.key == '*') 
     825                { 
    813826                        /* Force refresh */ 
    814827                        Term_key_push('6'); 
    815828                        continue; 
    816829                } 
     830 
    817831                else i++; 
    818832        } 
     833 
    819834        return TRUE; 
    820835} 
     
    15001515void player_birth(void) 
    15011516{ 
    1502         int i, n; 
    1503  
    1504  
    15051517        /* Create a new character */ 
    15061518        while (1) 
     
    15261538 
    15271539 
    1528         /* Shops */ 
    1529         for (n = 0; n < MAX_STORES; n++) 
    1530         { 
    1531                 /* Initialize */ 
    1532                 store_init(n); 
    1533  
    1534                 /* Ignore home */ 
    1535                 if (n == STORE_HOME) continue; 
    1536  
    1537                 /* Maintain the shop (ten times) */ 
    1538                 for (i = 0; i < 10; i++) store_maint(n); 
    1539         } 
    1540 
     1540        /* Initialise the stores */ 
     1541        store_init(); 
     1542
  • trunk/src/defines.h

    r34 r36  
    252252/* 
    253253 * Store constants 
     254 * 
     255 * Special note about STORE_MAX_KEEP; not only must it be below 
     256 * STORE_INVEN_MAX, it must actually be below (STORE_INVEN_MAX - maximum 
     257 * staple items across all stores); i.e. if the General Store has three 
     258 * staple items (and no other store has more than three staple items), 
     259 * then STORE_MAX_KEEP > (STORE_INVEN_MAX - 3), or > 21 (in this case). 
    254260 */ 
    255261#define STORE_INVEN_MAX 24              /* Max number of discrete objs in inven */ 
    256262#define STORE_OBJ_LEVEL 5               /* Magic Level for normal stores */ 
    257263#define STORE_TURNOVER  9               /* Normal shop turnover, per day */ 
    258 #define STORE_MIN_KEEP  6               /* Min slots to "always" keep full */ 
     264#define STORE_MIN_KEEP  6               /* Min slots to "always" keep full - 
     265                                           must be above 0 */ 
    259266#define STORE_MAX_KEEP  18              /* Max slots to "always" keep full */ 
    260267#define STORE_SHUFFLE   25              /* 1/Chance (per day) of an owner changing */ 
    261268#define STORE_TURNS             1000    /* Number of turns between turnovers */ 
     269#define STORE_CHOICES   32              /* Number of choices in the store selection table */ 
    262270 
    263271 
  • trunk/src/externs.h

    r33 r36  
    7171extern cptr inscrip_text[MAX_INSCRIP]; 
    7272extern const grouper object_text_order[]; 
     73extern const byte store_choices[MAX_STORES-2][STORE_CHOICES][2]; 
    7374 
    7475/* variable.c */ 
     
    670671extern void store_shuffle(int which); 
    671672extern void store_maint(int which); 
    672 extern void store_init(int which); 
     673extern void store_init(void); 
    673674 
    674675/* util.c */ 
     
    682683extern void flush(void); 
    683684extern void flush_fail(void); 
    684 extern char anykey(void); 
    685685extern char inkey(void); 
    686686extern event_type inkey_ex(void); 
     687extern char anykey(void); 
    687688extern void bell(cptr reason); 
    688689extern void sound(int val); 
  • trunk/src/init2.c

    r27 r36  
    11231123/*** Initialize others ***/ 
    11241124 
    1125 #define STORE_CHOICES   32              /* Number of items to choose stock from */ 
    1126  
    1127  
    1128 /* 
    1129  * Hack -- Objects sold in the stores -- by tval/sval pair. 
    1130  */ 
    1131 static const byte store_table[MAX_STORES-2][STORE_CHOICES][2] = 
    1132 { 
    1133         { 
    1134                 /* General Store */ 
    1135  
    1136                 { TV_FOOD, SV_FOOD_RATION }, 
    1137                 { TV_FOOD, SV_FOOD_RATION }, 
    1138                 { TV_FOOD, SV_FOOD_RATION }, 
    1139                 { TV_FOOD, SV_FOOD_RATION }, 
    1140                 { TV_FOOD, SV_FOOD_RATION }, 
    1141                 { TV_FOOD, SV_FOOD_BISCUIT }, 
    1142                 { TV_FOOD, SV_FOOD_JERKY }, 
    1143                 { TV_FOOD, SV_FOOD_JERKY }, 
    1144  
    1145                 { TV_FOOD, SV_FOOD_PINT_OF_WINE }, 
    1146                 { TV_FOOD, SV_FOOD_PINT_OF_ALE }, 
    1147                 { TV_LITE, SV_LITE_TORCH }, 
    1148                 { TV_LITE, SV_LITE_TORCH }, 
    1149                 { TV_LITE, SV_LITE_TORCH }, 
    1150                 { TV_LITE, SV_LITE_TORCH }, 
    1151                 { TV_LITE, SV_LITE_LANTERN }, 
    1152                 { TV_LITE, SV_LITE_LANTERN }, 
    1153  
    1154                 { TV_FLASK, 0 }, 
    1155                 { TV_FLASK, 0 }, 
    1156                 { TV_FLASK, 0 }, 
    1157                 { TV_FLASK, 0 }, 
    1158                 { TV_FLASK, 0 }, 
    1159                 { TV_FLASK, 0 }, 
    1160                 { TV_SPIKE, 0 }, 
    1161                 { TV_SPIKE, 0 }, 
    1162  
    1163                 { TV_SHOT, SV_AMMO_NORMAL }, 
    1164                 { TV_ARROW, SV_AMMO_NORMAL }, 
    1165                 { TV_BOLT, SV_AMMO_NORMAL }, 
    1166                 { TV_DIGGING, SV_SHOVEL }, 
    1167                 { TV_DIGGING, SV_PICK }, 
    1168                 { TV_CLOAK, SV_CLOAK }, 
    1169                 { TV_CLOAK, SV_CLOAK }, 
    1170                 { TV_CLOAK, SV_CLOAK } 
    1171         }, 
    1172  
    1173         { 
    1174                 /* Armoury */ 
    1175  
    1176                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS }, 
    1177                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS }, 
    1178                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS }, 
    1179                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS }, 
    1180                 { TV_HELM, SV_HARD_LEATHER_CAP }, 
    1181                 { TV_HELM, SV_HARD_LEATHER_CAP }, 
    1182                 { TV_HELM, SV_METAL_CAP }, 
    1183                 { TV_HELM, SV_IRON_HELM }, 
    1184  
    1185                 { TV_SOFT_ARMOR, SV_ROBE }, 
    1186                 { TV_SOFT_ARMOR, SV_ROBE }, 
    1187                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR }, 
    1188                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR }, 
    1189                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR }, 
    1190                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR }, 
    1191                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER }, 
    1192                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER }, 
    1193  
    1194                 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL }, 
    1195                 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL }, 
    1196                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL }, 
    1197                 { TV_HARD_ARMOR, SV_CHAIN_MAIL }, 
    1198                 { TV_HARD_ARMOR, SV_CHAIN_MAIL }, 
    1199                 { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL }, 
    1200                 { TV_HARD_ARMOR, SV_BAR_CHAIN_MAIL }, 
    1201                 { TV_HARD_ARMOR, SV_DOUBLE_CHAIN_MAIL }, 
    1202  
    1203                 { TV_HARD_ARMOR, SV_METAL_BRIGANDINE_ARMOUR }, 
    1204                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES }, 
    1205                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES }, 
    1206                 { TV_GLOVES, SV_SET_OF_GAUNTLETS }, 
    1207                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }, 
    1208                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }, 
    1209                 { TV_SHIELD, SV_LARGE_LEATHER_SHIELD }, 
    1210                 { TV_SHIELD, SV_SMALL_METAL_SHIELD } 
    1211         }, 
    1212  
    1213         { 
    1214                 /* Weaponsmith */ 
    1215  
    1216                 { TV_SWORD, SV_DAGGER }, 
    1217                 { TV_SWORD, SV_MAIN_GAUCHE }, 
    1218                 { TV_SWORD, SV_RAPIER }, 
    1219                 { TV_SWORD, SV_SMALL_SWORD }, 
    1220                 { TV_SWORD, SV_SHORT_SWORD }, 
    1221                 { TV_SWORD, SV_SABRE }, 
    1222                 { TV_SWORD, SV_CUTLASS }, 
    1223                 { TV_SWORD, SV_TULWAR }, 
    1224  
    1225                 { TV_SWORD, SV_BROAD_SWORD }, 
    1226                 { TV_SWORD, SV_LONG_SWORD }, 
    1227                 { TV_SWORD, SV_SCIMITAR }, 
    1228                 { TV_SWORD, SV_KATANA }, 
    1229                 { TV_SWORD, SV_BASTARD_SWORD }, 
    1230                 { TV_POLEARM, SV_SPEAR }, 
    1231                 { TV_POLEARM, SV_AWL_PIKE }, 
    1232                 { TV_POLEARM, SV_TRIDENT }, 
    1233  
    1234                 { TV_POLEARM, SV_PIKE }, 
    1235                 { TV_POLEARM, SV_BEAKED_AXE }, 
    1236                 { TV_POLEARM, SV_BROAD_AXE }, 
    1237                 { TV_POLEARM, SV_LANCE }, 
    1238                 { TV_POLEARM, SV_BATTLE_AXE }, 
    1239                 { TV_HAFTED, SV_WHIP }, 
    1240                 { TV_BOW, SV_SLING }, 
    1241                 { TV_BOW, SV_SHORT_BOW }, 
    1242  
    1243                 { TV_BOW, SV_LONG_BOW }, 
    1244                 { TV_BOW, SV_LIGHT_XBOW }, 
    1245                 { TV_SHOT, SV_AMMO_NORMAL }, 
    1246                 { TV_SHOT, SV_AMMO_NORMAL }, 
    1247                 { TV_ARROW, SV_AMMO_NORMAL }, 
    1248                 { TV_ARROW, SV_AMMO_NORMAL }, 
    1249                 { TV_BOLT, SV_AMMO_NORMAL }, 
    1250                 { TV_BOLT, SV_AMMO_NORMAL }, 
    1251         }, 
    1252  
    1253         { 
    1254                 /* Temple */ 
    1255  
    1256                 { TV_HAFTED, SV_WHIP }, 
    1257                 { TV_HAFTED, SV_QUARTERSTAFF }, 
    1258                 { TV_HAFTED, SV_MACE }, 
    1259                 { TV_HAFTED, SV_MACE }, 
    1260                 { TV_HAFTED, SV_BALL_AND_CHAIN }, 
    1261                 { TV_HAFTED, SV_WAR_HAMMER }, 
    1262                 { TV_HAFTED, SV_LUCERN_HAMMER }, 
    1263                 { TV_HAFTED, SV_MORNING_STAR }, 
    1264  
    1265                 { TV_HAFTED, SV_FLAIL }, 
    1266                 { TV_HAFTED, SV_FLAIL }, 
    1267                 { TV_HAFTED, SV_LEAD_FILLED_MACE }, 
    1268                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE }, 
    1269                 { TV_SCROLL, SV_SCROLL_BLESSING }, 
    1270                 { TV_SCROLL, SV_SCROLL_HOLY_CHANT }, 
    1271                 { TV_POTION, SV_POTION_BOLDNESS }, 
    1272                 { TV_POTION, SV_POTION_HEROISM }, 
    1273  
    1274                 { TV_POTION, SV_POTION_CURE_LIGHT }, 
    1275                 { TV_POTION, SV_POTION_CURE_SERIOUS }, 
    1276                 { TV_POTION, SV_POTION_CURE_SERIOUS }, 
    1277                 { TV_POTION, SV_POTION_CURE_CRITICAL }, 
    1278                 { TV_POTION, SV_POTION_CURE_CRITICAL }, 
    1279                 { TV_POTION, SV_POTION_RESTORE_EXP }, 
    1280                 { TV_POTION, SV_POTION_RESTORE_EXP }, 
    1281                 { TV_POTION, SV_POTION_RESTORE_EXP }, 
    1282  
    1283                 { TV_PRAYER_BOOK, 0 }, 
    1284                 { TV_PRAYER_BOOK, 0 }, 
    1285                 { TV_PRAYER_BOOK, 0 }, 
    1286                 { TV_PRAYER_BOOK, 1 }, 
    1287                 { TV_PRAYER_BOOK, 1 }, 
    1288                 { TV_PRAYER_BOOK, 2 }, 
    1289                 { TV_PRAYER_BOOK, 2 }, 
    1290                 { TV_PRAYER_BOOK, 3 } 
    1291         }, 
    1292  
    1293         { 
    1294                 /* Alchemy shop */ 
    1295  
    1296                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT }, 
    1297                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM }, 
    1298                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR }, 
    1299                 { TV_SCROLL, SV_SCROLL_IDENTIFY }, 
    1300                 { TV_SCROLL, SV_SCROLL_IDENTIFY }, 
    1301                 { TV_SCROLL, SV_SCROLL_IDENTIFY }, 
    1302                 { TV_SCROLL, SV_SCROLL_IDENTIFY }, 
    1303                 { TV_SCROLL, SV_SCROLL_LIGHT }, 
    1304  
    1305                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR }, 
    1306                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR }, 
    1307                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR }, 
    1308                 { TV_SCROLL, SV_SCROLL_MONSTER_CONFUSION }, 
    1309                 { TV_SCROLL, SV_SCROLL_MAPPING }, 
    1310                 { TV_SCROLL, SV_SCROLL_DETECT_GOLD }, 
    1311                 { TV_SCROLL, SV_SCROLL_DETECT_ITEM }, 
    1312                 { TV_SCROLL, SV_SCROLL_DETECT_TRAP }, 
    1313  
    1314                 { TV_SCROLL, SV_SCROLL_DETECT_DOOR }, 
    1315                 { TV_SCROLL, SV_SCROLL_DETECT_INVIS }, 
    1316                 { TV_SCROLL, SV_SCROLL_RECHARGING }, 
    1317                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER }, 
    1318                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL }, 
    1319                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL }, 
    1320                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL }, 
    1321                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL }, 
    1322  
    1323                 { TV_POTION, SV_POTION_RESIST_HEAT }, 
    1324                 { TV_POTION, SV_POTION_RESIST_COLD }, 
    1325                 { TV_POTION, SV_POTION_RES_STR }, 
    1326                 { TV_POTION, SV_POTION_RES_INT }, 
    1327                 { TV_POTION, SV_POTION_RES_WIS }, 
    1328                 { TV_POTION, SV_POTION_RES_DEX }, 
    1329                 { TV_POTION, SV_POTION_RES_CON }, 
    1330                 { TV_POTION, SV_POTION_RES_CHR } 
    1331         }, 
    1332  
    1333         { 
    1334                 /* Magic-User store */ 
    1335  
    1336                 { TV_RING, SV_RING_SEARCHING }, 
    1337                 { TV_RING, SV_RING_FEATHER_FALL }, 
    1338                 { TV_RING, SV_RING_PROTECTION }, 
    1339                 { TV_AMULET, SV_AMULET_CHARISMA }, 
    1340                 { TV_AMULET, SV_AMULET_SLOW_DIGEST }, 
    1341                 { TV_AMULET, SV_AMULET_RESIST_ACID }, 
    1342                 { TV_WAND, SV_WAND_SLOW_MONSTER }, 
    1343                 { TV_WAND, SV_WAND_CONFUSE_MONSTER }, 
    1344  
    1345                 { TV_WAND, SV_WAND_SLEEP_MONSTER }, 
    1346                 { TV_WAND, SV_WAND_MAGIC_MISSILE }, 
    1347                 { TV_WAND, SV_WAND_STINKING_CLOUD }, 
    1348                 { TV_WAND, SV_WAND_WONDER }, 
    1349                 { TV_STAFF, SV_STAFF_LITE }, 
    1350                 { TV_STAFF, SV_STAFF_MAPPING }, 
    1351                 { TV_STAFF, SV_STAFF_DETECT_TRAP }, 
    1352                 { TV_STAFF, SV_STAFF_DETECT_DOOR }, 
    1353  
    1354                 { TV_STAFF, SV_STAFF_DETECT_GOLD }, 
    1355                 { TV_STAFF, SV_STAFF_DETECT_ITEM }, 
    1356                 { TV_STAFF, SV_STAFF_DETECT_INVIS }, 
    1357                 { TV_STAFF, SV_STAFF_DETECT_EVIL }, 
    1358                 { TV_STAFF, SV_STAFF_TELEPORTATION }, 
    1359                 { TV_STAFF, SV_STAFF_TELEPORTATION }, 
    1360                 { TV_STAFF, SV_STAFF_IDENTIFY }, 
    1361                 { TV_STAFF, SV_STAFF_IDENTIFY }, 
    1362  
    1363                 { TV_MAGIC_BOOK, 0 }, 
    1364                 { TV_MAGIC_BOOK, 0 }, 
    1365                 { TV_MAGIC_BOOK, 0 }, 
    1366                 { TV_MAGIC_BOOK, 1 }, 
    1367                 { TV_MAGIC_BOOK, 1 }, 
    1368                 { TV_MAGIC_BOOK, 2 }, 
    1369                 { TV_MAGIC_BOOK, 2 }, 
    1370                 { TV_MAGIC_BOOK, 3 } 
    1371         } 
    1372 }; 
    1373  
    1374  
    1375  
    13761125static void autoinscribe_init(void) 
    13771126{ 
     
    15081257 
    15091258                        /* Extract the tval/sval codes */ 
    1510                         int tv = store_table[i][k][0]; 
    1511                         int sv = store_table[i][k][1]; 
     1259                        int tv = store_choices[i][k][0]; 
     1260                        int sv = store_choices[i][k][1]; 
    15121261 
    15131262                        /* Look for it */ 
  • trunk/src/store.c

    r1 r36  
    22 
    33/* 
    4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke 
     4 * Copyright (c) 1997-2005 Andrew Sidwell, Ben Harrison, James E. Wilson, 
     5 *                         Robert A. Koeneke 
    56 * 
    67 * This software may be copied and distributed for educational, research, 
     
    1011 
    1112#include "angband.h" 
    12  
    1313#include "script.h" 
    1414 
    15  
    16 #define MAX_COMMENT_ACCEPT      6 
    17  
    18 static cptr comment_accept[MAX_COMMENT_ACCEPT] = 
     15/*** Various file-wide definitions ***/ 
     16 
     17/** Store display stuff **/ 
     18 
     19/* Easy names for the elements of the 'scr_places' arrays. */ 
     20enum 
     21
     22        LOC_PRICE = 0, 
     23        LOC_OWNER, 
     24        LOC_HEADER, 
     25        LOC_ITEMS_START, 
     26        LOC_ITEMS_END, 
     27        LOC_MORE, 
     28        LOC_HELP_CLEAR, 
     29        LOC_HELP_PROMPT, 
     30        LOC_AU, 
     31 
     32        LOC_MAX 
     33}; 
     34 
     35/* Places for the various things displayed onscreen */ 
     36static unsigned int scr_places_x[LOC_MAX]; 
     37static unsigned int scr_places_y[LOC_MAX]; 
     38 
     39/* State flags */ 
     40#define STORE_HELP             0x000001 
     41#define STORE_INVEN_CHANGE     0x000002 
     42#define STORE_GOLD_CHANGE      0x000004 
     43#define STORE_HELP_CHANGE      0x000008 
     44#define STORE_FRAME_CHANGE     0x000010 
     45#define STORE_MORE_CHANGE      0x000020 
     46#define STORE_SIZE_CHANGE      0x000040 
     47 
     48/* Compound flag for the initial display of a store */ 
     49#define STORE_INIT_CHANGE \ 
     50        (STORE_INVEN_CHANGE | STORE_FRAME_CHANGE | STORE_GOLD_CHANGE | \ 
     51         STORE_HELP_CHANGE | STORE_SIZE_CHANGE) 
     52 
     53 
     54/** Variables to maintain state -- these shouldn't really exist ***/ 
     55 
     56/* Current store number */ 
     57static int store_current; 
     58 
     59/* Item at the top of the current store display */ 
     60static int store_top; 
     61 
     62/* Flags for the display */ 
     63static u32b store_flags; 
     64 
     65 
     66 
     67 
     68/*** Utility function ***/ 
     69 
     70/* 
     71 * Return the owner struct for the given store. 
     72 */ 
     73owner_type *store_owner(int st) 
     74
     75        store_type *st_ptr = &store[st]; 
     76        return &b_info[(st * z_info->b_max) + st_ptr->owner]; 
     77
     78 
     79 
     80 
     81/*** Flavour text stuff ***/ 
     82 
     83/* 
     84 * Messages for reacting to purchase prices. 
     85 */ 
     86static const char *comment_worthless[] = 
     87
     88        "Arrgghh!", 
     89        "You bastard!", 
     90        "You hear someone sobbing...", 
     91        "The shopkeeper howls in agony!" 
     92}; 
     93 
     94static const char *comment_bad[] = 
     95
     96        "Damn!", 
     97        "You fiend!", 
     98        "The shopkeeper curses at you.", 
     99        "The shopkeeper glares at you." 
     100}; 
     101 
     102static const char *comment_accept[] = 
    19103{ 
    20104        "Okay.", 
     
    26110}; 
    27111 
    28  
    29 #define MAX_COMMENT_INSULT      8 
    30  
    31 static cptr comment_insult[MAX_COMMENT_INSULT] = 
    32 
    33         "Try again.", 
    34         "Ridiculous!", 
    35         "You will have to do better than that!", 
    36         "Do you wish to do business or not?", 
    37         "You've got to be kidding!", 
    38         "You'd better be kidding!", 
    39         "You try my patience.", 
    40         "Hmmm, nice weather we're having." 
    41 }; 
    42  
    43  
    44 #define MAX_COMMENT_NONSENSE    4 
    45  
    46 static cptr comment_nonsense[MAX_COMMENT_NONSENSE] = 
    47 
    48         "I must have heard you wrong.", 
    49         "I'm sorry, I missed that.", 
    50         "I'm sorry, what was that?", 
    51         "Sorry, what was that again?" 
    52 }; 
    53  
    54  
    55  
    56 /* 
    57  * Successful haggle. 
    58  */ 
    59 static void say_comment_accept(void) 
    60 
    61         message(MSG_STORE5, 0, comment_accept[rand_int(MAX_COMMENT_ACCEPT)]); 
    62 
    63  
    64  
    65 /* 
    66  * You are insulting me 
    67  */ 
    68 static void say_comment_insult(void) 
    69 
    70         msg_print(comment_insult[rand_int(MAX_COMMENT_INSULT)]); 
    71 
    72  
    73  
    74 /* 
    75  * You are making no sense. 
    76  */ 
    77 static void say_comment_nonsense(void) 
    78 
    79         msg_print(comment_nonsense[rand_int(MAX_COMMENT_NONSENSE)]); 
    80 
    81  
    82  
    83  
    84 /* 
    85  * Messages for reacting to purchase prices. 
    86  */ 
    87  
    88 #define MAX_COMMENT_WORTHLESS   4 
    89  
    90 static cptr comment_worthless[MAX_COMMENT_WORTHLESS] = 
    91 
    92         "Arrgghh!", 
    93         "You bastard!", 
    94         "You hear someone sobbing...", 
    95         "The shopkeeper howls in agony!" 
    96 }; 
    97  
    98 #define MAX_COMMENT_BAD 4 
    99  
    100 static cptr comment_bad[MAX_COMMENT_BAD] = 
    101 
    102         "Damn!", 
    103         "You fiend!", 
    104         "The shopkeeper curses at you.", 
    105         "The shopkeeper glares at you." 
    106 }; 
    107  
    108 #define MAX_COMMENT_GOOD        4 
    109  
    110 static cptr comment_good[MAX_COMMENT_GOOD] = 
     112static const char *comment_good[] = 
    111113{ 
    112114        "Cool!", 
     
    116118}; 
    117119 
    118 #define MAX_COMMENT_GREAT       4 
    119  
    120 static cptr comment_great[MAX_COMMENT_GREAT] = 
     120static const char *comment_great[] = 
    121121{ 
    122122        "Yipee!", 
     
    126126}; 
    127127 
     128/* Randomly select one of the entries in an array */ 
     129#define ONE_OF(x)       x[rand_int(N_ELEMENTS(x))] 
     130 
    128131 
    129132/* 
     
    136139        /* Item was worthless, but we bought it */ 
    137140        if ((value <= 0) && (price > value)) 
    138         { 
    139                 /* Comment */ 
    140                 message(MSG_STORE1, 0, comment_worthless[rand_int(MAX_COMMENT_WORTHLESS)]); 
    141         } 
     141                message(MSG_STORE1, 0, ONE_OF(comment_worthless)); 
    142142 
    143143        /* Item was cheaper than we thought, and we paid more than necessary */ 
    144144        else if ((value < guess) && (price > value)) 
    145         { 
    146                 /* Comment */ 
    147                 message(MSG_STORE2, 0, comment_bad[rand_int(MAX_COMMENT_BAD)]); 
    148         } 
     145                message(MSG_STORE2, 0, ONE_OF(comment_bad)); 
    149146 
    150147        /* Item was a good bargain, and we got away with it */ 
    151148        else if ((value > guess) && (value < (4 * guess)) && (price < value)) 
    152         { 
    153                 /* Comment */ 
    154                 message(MSG_STORE3, 0, comment_good[rand_int(MAX_COMMENT_GOOD)]); 
    155         } 
     149                message(MSG_STORE3, 0, ONE_OF(comment_good)); 
    156150 
    157151        /* Item was a great bargain, and we got away with it */ 
    158152        else if ((value > guess) && (price < value)) 
    159         { 
    160                 /* Comment */ 
    161                 message(MSG_STORE4, 0, comment_great[rand_int(MAX_COMMENT_GREAT)]); 
    162         } 
    163 
    164  
    165  
    166 static int get_store_choice(int store_num) 
    167 
    168         return store[store_num].table[rand_int(store[store_num].table_num)]; 
     153                message(MSG_STORE4, 0, ONE_OF(comment_great)); 
    169154} 
    170155 
     
    319304 
    320305 
    321 /* 
    322  * We store the current "store number" here so everyone can access it 
    323  */ 
    324 static int store_num = 7; 
    325  
    326 /* 
    327  * We store the current "store page" here so everyone can access it 
    328  */ 
    329 static int store_top = 0; 
    330  
    331 /* 
    332  * We store the current "store pointer" here so everyone can access it 
    333  */ 
    334 static store_type *st_ptr = NULL; 
    335  
    336 /* 
    337  * We store the current "owner type" here so everyone can access it 
    338  */ 
    339 static owner_type *ot_ptr = NULL; 
    340  
    341  
    342  
    343  
    344  
     306/*** Basics: pricing, generation, etc. ***/ 
    345307 
    346308/* 
    347309 * Determine the price of an object (qty one) in a store. 
     310 * 
     311 * `flip` == TRUE  means the shop is buying, player selling 
     312 *        == FALSE means the shop is selling, player buying 
    348313 * 
    349314 * This function takes into account the player's charisma, and the 
     
    363328 * "greed" value is always something (?). 
    364329 */ 
    365 static s32b price_item(const object_type *o_ptr, int greed, bool flip) 
     330static s32b price_item(const object_type *o_ptr, bool flip) 
    366331{ 
    367332        int factor; 
     
    369334        s32b price; 
    370335 
     336        owner_type *ot_ptr = store_owner(store_current); 
     337 
     338        /* The greed value is always of the current store's owner */ 
     339        int greed = ot_ptr->inflate; 
     340 
    371341 
    372342        /* Get the value of one of the items */ 
     
    394364 
    395365                /* Mega-Hack -- Black market sucks */ 
    396                 if (store_num == STORE_B_MARKET) price = price / 2; 
     366                if (store_current == STORE_B_MARKET) price = price / 2; 
    397367        } 
    398368 
     
    407377 
    408378                /* Mega-Hack -- Black market sucks */ 
    409                 if (store_num == STORE_B_MARKET) price = price * 2; 
     379                if (store_current == STORE_B_MARKET) price = price * 2; 
    410380        } 
    411381 
     
    556526 
    557527/* 
    558  * Convert a store item index into a one character label 
    559  * 
    560  * We use labels "a"-"l" for page 1, and labels "m"-"x" for page 2. 
    561  */ 
    562 static s16b store_to_label(int i) 
    563 { 
    564         /* Assume legal */ 
    565         return (I2A(i)); 
    566 } 
    567  
    568  
    569 /* 
    570  * Convert a one character label into a store item index. 
    571  * 
    572  * Return "-1" if the label does not indicate a real store item. 
    573  */ 
    574 static s16b label_to_store(int c) 
    575 { 
    576         int i; 
    577  
    578         /* Convert */ 
    579         i = (islower((unsigned char)c) ? A2I(c) : -1); 
    580  
    581         /* Verify the index */ 
    582         if ((i < 0) || (i >= st_ptr->stock_num)) return (-1); 
    583  
    584         /* Return the index */ 
    585         return (i); 
    586 } 
    587  
    588  
    589  
    590 /* 
    591528 * Determine if a store object can "absorb" another object. 
    592529 * 
     
    679616 * adding them to a pile which was already full. 
    680617 */ 
    681 static bool store_check_num(const object_type *o_ptr) 
     618static bool store_check_num(int st, const object_type *o_ptr) 
    682619{ 
    683620        int i; 
    684621        object_type *j_ptr; 
    685622 
     623        store_type *st_ptr = &store[st]; 
     624 
    686625        /* Free space is always usable */ 
    687626        if (st_ptr->stock_num < st_ptr->stock_size) return TRUE; 
    688627 
    689628        /* The "home" acts like the player */ 
    690         if (store_num == STORE_HOME) 
     629        if (st == STORE_HOME) 
    691630        { 
    692631                /* Check all the objects */ 
     
    725664static bool store_will_buy_tester(const object_type *o_ptr) 
    726665{ 
    727         return store_will_buy(store_num, o_ptr); 
    728 } 
    729  
    730  
    731 /* 
    732  * Add an object to the inventory of the "Home" 
     666        return store_will_buy(store_current, o_ptr); 
     667} 
     668 
     669 
     670/* 
     671 * Add an object to the inventory of the Home. 
    733672 * 
    734673 * In all cases, return the slot (or -1) where the object was placed. 
     
    736675 * Note that this is a hacked up version of "inven_carry()". 
    737676 * 
    738  * Also note that it may not correctly "adapt" to "knowledge" bacoming 
    739  * known, the player may have to pick stuff up and drop it again. 
     677 * Also note that it may not correctly "adapt" to "knowledge" becoming 
     678 * known: the player may have to pick stuff up and drop it again. 
    740679 */ 
    741680static int home_carry(object_type *o_ptr) 
    742681{ 
    743682        int i, slot; 
    744         s32b value, j_value; 
     683        u32b value, j_value; 
    745684        object_type *j_ptr; 
    746685 
     686        store_type *st_ptr = &store[STORE_HOME]; 
    747687 
    748688        /* Check each existing object (try to combine) */ 
     
    834774 * In all cases, return the slot (or -1) where the object was placed 
    835775 */ 
    836 static int store_carry(object_type *o_ptr) 
     776static int store_carry(int st, object_type *o_ptr) 
    837777{ 
    838778        int i, slot; 
    839         s32b value, j_value; 
     779        u32b value, j_value; 
    840780        object_type *j_ptr; 
    841781 
     782        store_type *st_ptr = &store[st]; 
    842783 
    843784        /* Evaluate the object */ 
     
    916857 
    917858/* 
    918  * Increase, by a given amount, the number of a certain item 
    919  * in a certain store.  This can result in zero items. 
    920  */ 
    921 static void store_item_increase(int item, int num) 
     859 * Increase, by a 'num', the number of an item 'item' in store 'st'. 
     860 * This can result in zero items. 
     861 */ 
     862static void store_item_increase(int st, int item, int num) 
    922863{ 
    923864        int cnt; 
    924865        object_type *o_ptr; 
     866 
     867        store_type *st_ptr = &store[st]; 
    925868 
    926869        /* Get the object */ 
     
    931874        if (cnt > 255) cnt = 255; 
    932875        else if (cnt < 0) cnt = 0; 
    933         num = cnt - o_ptr->number; 
    934876 
    935877        /* Save the new number */ 
    936         o_ptr->number += num
    937 } 
    938  
    939  
    940 /* 
    941  * Remove a slot if it is empty 
    942  */ 
    943 static void store_item_optimize(int item) 
     878        o_ptr->number = cnt
     879} 
     880 
     881 
     882/* 
     883 * Remove a slot if it is empty, in store 'st'. 
     884 */ 
     885static void store_item_optimize(int st, int item) 
    944886{ 
    945887        int j; 
    946888        object_type *o_ptr; 
    947889 
     890        store_type *st_ptr = &store[st]; 
     891 
    948892        /* Get the object */ 
    949893        o_ptr = &st_ptr->stock[item]; 
     
    969913 
    970914 
    971 /* 
    972  * This function will keep 'crap' out of the black market. 
    973  * Crap is defined as any object that is "available" elsewhere 
    974  * Based on a suggestion by "Lee Vogt" <lvogt@cig.mcel.mot.com> 
    975  */ 
    976 static bool black_market_crap(const object_type *o_ptr) 
     915 
     916/* 
     917 * Delete a random object from store 'st', or, if it is a stack, perhaps only 
     918 * partially delete it. 
     919 * 
     920 * This function is used when store maintainance occurs, and is designed to 
     921 * imitate non-PC purchasers making purchases from the store. 
     922 */ 
     923static void store_delete_item(int st) 
     924
     925        int what, num; 
     926        object_type *o_ptr; 
     927 
     928        store_type *st_ptr = &store[st]; 
     929 
     930        /* Paranoia */ 
     931        if (st_ptr->stock_num <= 0) return; 
     932 
     933        /* Pick a random slot */ 
     934        what = rand_int(st_ptr->stock_num); 
     935 
     936        /* Get the object */ 
     937        o_ptr = &st_ptr->stock[what]; 
     938 
     939        /* Determine how many objects are in the slot */ 
     940        num = o_ptr->number; 
     941 
     942        /* Deal with stacks */ 
     943        if (num > 1) 
     944        { 
     945                /* Sometimes destroy a single object */ 
     946                if (rand_int(100) < 50) num = 1; 
     947 
     948                /* Sometimes destroy half the objects */ 
     949                else if (rand_int(100) < 50) num = (num + 1) / 2; 
     950 
     951                /* Hack -- decrement the maximum timeouts and total charges of rods and wands. */ 
     952                if ((o_ptr->tval == TV_ROD) || 
     953                    (o_ptr->tval == TV_STAFF) || 
     954                    (o_ptr->tval == TV_WAND)) 
     955                { 
     956                        o_ptr->pval -= num * o_ptr->pval / o_ptr->number; 
     957                } 
     958        } 
     959 
     960        /* Delete the item */ 
     961        store_item_increase(st, what, -num); 
     962        store_item_optimize(st, what); 
     963
     964 
     965 
     966 
     967/* 
     968 * This makes sure that the black market doesn't stock any object that other 
     969 * stores have, unless it is an ego-item or has various bonuses. 
     970 * 
     971 * Based on a suggestion by Lee Vogt <lvogt@cig.mcel.mot.com>. 
     972 * 
     973 * If the stores ever become truly externalised, i.e. if Lua becomes more 
     974 * integrated, then there should be some way to get this out of the compiled 
     975 * code, as it is a little hacky.  XXX 
     976 */ 
     977static bool black_market_ok(const object_type *o_ptr) 
    977978{ 
    978979        int i, j; 
    979980 
    980         /* Ego items are never crap */ 
    981         if (o_ptr->name2) return (FALSE); 
    982  
    983         /* Good items are never crap */ 
    984         if (o_ptr->to_a > 0) return (FALSE); 
    985         if (o_ptr->to_h > 0) return (FALSE); 
    986         if (o_ptr->to_d > 0) return (FALSE); 
     981        /* Ego items are always fine */ 
     982        if (o_ptr->name2) return (TRUE); 
     983 
     984        /* Good items are normally fine */ 
     985        if (o_ptr->to_a > 2) return (TRUE); 
     986        if (o_ptr->to_h > 1) return (TRUE); 
     987        if (o_ptr->to_d > 2) return (TRUE); 
     988 
     989 
     990        /* No cheap items */ 
     991        if (object_value(o_ptr) < 10) return (FALSE); 
    987992 
    988993        /* Check the other stores */ 
     
    991996                /* Skip home and black market */ 
    992997                if (i == STORE_B_MARKET || i == STORE_HOME)