Changeset 137

Show
Ignore:
Timestamp:
05/14/07 04:47:59 (1 year ago)
Author:
takkaria
Message:

Finish up S-style object handling: (Leon Marrick)

  • Make the game correctly update the view before prompting to pick up
  • Compress the treasure pickup messages
  • List a single object in the message line instead of showing a list just for it

Closes #54.

Files:

Legend:

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

    r48 r137  
    41414141        } 
    41424142 
     4143        /* Cancel auto-pickup if badly wounded  XXX XXX */ 
     4144        if ((p_ptr->notice & (PN_PICKUP0 | PN_PICKUP1)) && 
     4145            (p_ptr->chp < (p_ptr->mhp * op_ptr->hitpoint_warn / 10))) 
     4146        { 
     4147                p_ptr->auto_pickup_okay = FALSE; 
     4148        } 
     4149 
    41434150        /* Flush the input if requested */ 
    41444151        if (flush_disturb) flush(); 
  • trunk/src/cmd1.c

    r124 r137  
    667667        bool msg = TRUE; 
    668668 
     669        s32b total_gold = 0L; 
     670        byte *treasure; 
     671 
    669672 
    670673        /* Nothing to pick up -- return */ 
     
    675678 
    676679 
    677         /* Scan the objects */ 
     680        /* Allocate and wipe an array of ordinary gold objects */ 
     681        C_MAKE(treasure, SV_GOLD_MAX, byte); 
     682        (void)C_WIPE(treasure, SV_GOLD_MAX, byte); 
     683 
     684        /* Pick up all the ordinary gold objects */ 
    678685        for (this_o_idx = cave_o_idx[py][px]; this_o_idx; this_o_idx = next_o_idx) 
    679686        { 
     687                int gold_type; 
     688 
    680689                /* Get the object */ 
    681690                o_ptr = &o_list[this_o_idx]; 
     
    687696                if (!o_ptr->marked) continue; 
    688697 
     698                /* Ignore if not legal treasure */ 
     699                if ((o_ptr->tval != TV_GOLD) || 
     700                    (o_ptr->sval >= SV_GOLD_MAX)) continue; 
     701 
     702                /* Hack -- adjust treasure type (to avoid picking up "gold, gold, and gold") */ 
     703                gold_type = o_ptr->sval; 
     704                if ((gold_type == SV_COPPER2) || (gold_type == SV_COPPER3)) 
     705                        gold_type = SV_COPPER1; 
     706                if ((gold_type == SV_SILVER2) || (gold_type == SV_SILVER3)) 
     707                        gold_type = SV_SILVER1; 
     708                if ((gold_type == SV_GOLD2)   || (gold_type == SV_GOLD3)) 
     709                        gold_type = SV_GOLD1; 
     710                if (gold_type == SV_GARNETS2) 
     711                        gold_type = SV_GARNETS1; 
     712 
     713                /* Note that we have this kind of treasure */ 
     714                treasure[gold_type]++; 
     715 
     716                /* Increment total value */ 
     717                total_gold += (s32b)o_ptr->pval; 
     718 
     719                /* Delete the gold */ 
     720                delete_object_idx(this_o_idx); 
     721        } 
     722 
     723        /* Pick up the gold, if present */ 
     724        if (total_gold) 
     725        { 
     726                char buf[1024]; 
     727                char tmp[80]; 
     728                int i, count, total, k_idx; 
     729 
     730                /* Build a message */ 
     731                (void)strnfmt(buf, sizeof(buf), "You have found %ld gold pieces worth of ",  total_gold); 
     732 
     733                /* Count the types of treasure present */ 
     734                for (total = 0, i = 0; i < SV_GOLD_MAX; i++) 
     735                { 
     736                        if (treasure[i]) total++; 
     737                } 
     738 
     739                /* List the treasure types */ 
     740                for (count = 0, i = 0; i < SV_GOLD_MAX; i++) 
     741                { 
     742                        /* Skip if no treasure of this type */ 
     743                        if (!treasure[i]) continue; 
     744 
     745                        /* Get this object index */ 
     746                        k_idx = lookup_kind(TV_GOLD, i); 
     747 
     748                        /* Skip past errors  XXX */ 
     749                        if (k_idx <= 0) continue; 
     750 
     751                        /* Get the object name */ 
     752                        strip_name(tmp, k_idx, TRUE); 
     753 
     754                        /* Build up the pickup string */ 
     755                        my_strcat(buf, tmp, sizeof(buf)); 
     756 
     757                        /* Added another kind of treasure */ 
     758                        count++; 
     759 
     760                        /* Add a comma if necessary */ 
     761                        if ((total > 2) && (count < total)) strcat(buf, ","); 
     762 
     763                        /* Add an "and" if necessary */ 
     764                        if ((total >= 2) && (count == total-1)) strcat(buf, " and"); 
     765 
     766                        /* Add a space or period if necessary */ 
     767                        if (count < total) strcat(buf, " "); 
     768                        else               strcat(buf, "."); 
     769                } 
     770 
     771                /* Determine which sound to play */ 
     772                if      (total_gold < 200) sound_msg = MSG_MONEY1; 
     773                else if (total_gold < 600) sound_msg = MSG_MONEY2; 
     774                else                       sound_msg = MSG_MONEY3; 
     775 
     776                /* Display the message */ 
     777                message_format(sound_msg, 0, "%s", buf); 
     778 
     779                /* Add gold to purse */ 
     780                p_ptr->au += total_gold; 
     781 
     782                /* Redraw gold */ 
     783                p_ptr->redraw |= (PR_GOLD); 
     784 
     785                /* Window stuff */ 
     786                p_ptr->window |= (PW_PLAYER_0 | PW_PLAYER_1); 
     787        } 
     788 
     789        /* Free the gold array */ 
     790        FREE(treasure); 
     791 
     792 
     793        /* Scan the remaining objects */ 
     794        for (this_o_idx = cave_o_idx[py][px]; this_o_idx; this_o_idx = next_o_idx) 
     795        { 
     796                /* Get the object */ 
     797                o_ptr = &o_list[this_o_idx]; 
     798 
     799                /* Get the next object */ 
     800                next_o_idx = o_ptr->next_o_idx; 
     801 
     802                /* Ignore all hidden objects */ 
     803                if (!o_ptr->marked) continue; 
     804 
    689805                /* Paranoia -- ignore all dead objects  XXX */ 
    690806                if (!o_ptr->k_idx) continue; 
     
    694810 
    695811 
    696                 /* Pick up gold */ 
    697                 if (o_ptr->tval == TV_GOLD) 
    698                 { 
    699                         /* Determine which sound to play */ 
    700                         if ((long)o_ptr->pval < 200) sound_msg = MSG_MONEY1; 
    701                         else if ((long)o_ptr->pval < 600) sound_msg = MSG_MONEY2; 
    702                         else sound_msg = MSG_MONEY3; 
    703                          
    704                         /* Describe the object */ 
    705                         object_desc(o_name, sizeof(o_name), o_ptr, TRUE, 3); 
    706  
    707                         /* Message */ 
    708                         message_format(sound_msg, 0, "You have found %s worth %ld gold pieces.", 
    709                                 o_name, (long)o_ptr->pval); 
    710  
    711                         /* Collect the gold */ 
    712                         p_ptr->au += o_ptr->pval; 
    713  
    714                         /* Redraw gold */ 
    715                         p_ptr->redraw |= (PR_GOLD); 
    716  
    717                         /* Window stuff */ 
    718                         p_ptr->window |= (PW_PLAYER_0 | PW_PLAYER_1); 
    719  
    720                         /* Delete the gold */ 
    721                         delete_object_idx(this_o_idx); 
    722  
    723                         /* Check the next object */ 
    724                         continue; 
    725                 } 
    726  
    727812                /* Automatically pick up items into the backpack */ 
    728                 if ((pickup) && (auto_pickup_okay(o_ptr, TRUE))) 
     813                if ((p_ptr->auto_pickup_okay) && (pickup) && (auto_pickup_okay(o_ptr, TRUE))) 
    729814                { 
    730815                        /* Pick up the object (with a message) */ 
     
    765850        { 
    766851                /* Optionally, display more information about floor items */ 
    767                 if (query_floor
     852                if ((query_floor) && (floor_num > 1)
    768853                { 
    769854                        /* Scan all marked objects in the grid */ 
     
    899984                 * potentially unsafe, ask the player to confirm all pickups. 
    900985                 */ 
    901                 if ((query_floor) && (pickup <= 1)) 
     986                if (((query_floor) || (!p_ptr->auto_pickup_okay)) && (pickup <= 1)) 
    902987                { 
    903988                        /* Save screen */ 
     
    15911676                } 
    15921677 
    1593                 /* Handle objects now.  XXX XXX XXX */ 
    1594                 p_ptr->energy_use += py_pickup(do_pickup) * 10; 
    1595  
    1596                 /* 
    1597                  * The correct thing to do is to pick up objects *after* the map 
    1598                  * display updates post-move.  This involves about 30 lines of code 
    1599                  * and will be done on request.  -LM- 
    1600                  */ 
    1601  
    16021678 
    16031679                /* Handle "store doors" */ 
     
    16131689                        /* Free turn XXX XXX XXX */ 
    16141690                        p_ptr->energy_use = 0; 
    1615                 } 
     1691 
     1692                        /* Handle objects now.  XXX */ 
     1693                        p_ptr->energy_use += py_pickup(do_pickup) * 10; 
     1694                } 
     1695 
     1696                /* All other grids (including traps) */ 
     1697                else 
     1698                { 
     1699                        /* Handle objects (later) */ 
     1700                        if (do_pickup) p_ptr->notice |= (PN_PICKUP1); 
     1701                        else           p_ptr->notice |= (PN_PICKUP0); 
     1702                } 
     1703 
    16161704 
    16171705                /* Discover invisible traps */ 
    1618                 else if (cave_feat[y][x] == FEAT_INVIS) 
     1706                if (cave_feat[y][x] == FEAT_INVIS) 
    16191707                { 
    16201708                        /* Disturb */ 
  • trunk/src/defines.h

    r123 r137  
    13631363#define SV_FOOD_PINT_OF_WINE    39 
    13641364 
     1365/* The "sval" codes for TV_GOLD */ 
     1366#define SV_COPPER1                        1 
     1367#define SV_COPPER2                        2 
     1368#define SV_COPPER3                        3 
     1369#define SV_SILVER1                        4 
     1370#define SV_SILVER2                        5 
     1371#define SV_SILVER3                        6 
     1372#define SV_GARNETS1                       7 
     1373#define SV_GARNETS2                       8 
     1374#define SV_GOLD1                          9 
     1375#define SV_GOLD2                         10 
     1376#define SV_GOLD3                         11 
     1377#define SV_OPALS                         12 
     1378#define SV_SAPPHIRES                     13 
     1379#define SV_RUBIES                        14 
     1380#define SV_DIAMONDS                      15 
     1381#define SV_EMERALDS                      16 
     1382#define SV_MITHRIL                       17 
     1383#define SV_ADAMANTITE                    18 
     1384 
     1385#define SV_GOLD_MAX                      19 
     1386 
     1387 
    13651388 
    13661389/* 
     
    14001423 */ 
    14011424#define SQUELCH_NEVER               0 /* Allow pickup, defer to OPT_always_pickup */ 
    1402 #define NO_SQUELCH_NEVER_PICKUP     1 /* Never pickup, override OPT_always_pickup */  
     1425#define NO_SQUELCH_NEVER_PICKUP     1 /* Never pickup, override OPT_always_pickup */ 
    14031426#define NO_SQUELCH_ALWAYS_PICKUP    2 /* Always pickup, override all other options */ 
    14041427#define SQUELCH_ALWAYS              3 /* Destroy when player walks over */ 
     
    15761599#define PN_REORDER              0x00000002L     /* Reorder the pack */ 
    15771600#define PN_AUTOINSCRIBE 0x00000004L     /* Autoinscribe items */ 
     1601#define PN_PICKUP0      0x00000008L     /* Notice stuff (allow pickup) */ 
     1602#define PN_PICKUP1      0x00000010L     /* Pick up stuff */ 
    15781603/* xxx (many) */ 
    15791604 
  • trunk/src/dungeon.c

    r136 r137  
    12621262                } 
    12631263 
     1264                /* Picking up objects */ 
     1265                else if (p_ptr->notice & (PN_PICKUP1)) 
     1266                { 
     1267                        /* Recursively call the pickup function, use energy */ 
     1268                        p_ptr->energy_use = py_pickup(1) * 10; 
     1269                        p_ptr->notice &= ~(PN_PICKUP0 | PN_PICKUP1); 
     1270                } 
     1271 
     1272                /* Noticing objects (allow pickup) */ 
     1273                else if (p_ptr->notice & (PN_PICKUP0)) 
     1274                { 
     1275                        /* Recursively call the pickup function, use energy */ 
     1276                        p_ptr->energy_use = py_pickup(0) * 10; 
     1277                        p_ptr->notice &= ~(PN_PICKUP0 | PN_PICKUP1); 
     1278                } 
     1279 
    12641280                /* Resting */ 
    12651281                else if (p_ptr->resting) 
     
    14551471                } 
    14561472        } 
     1473 
    14571474        while (!p_ptr->energy_use && !p_ptr->leaving); 
     1475 
     1476 
     1477        /* Allowed to automatically pick up things again */ 
     1478        p_ptr->auto_pickup_okay = TRUE; 
    14581479} 
    14591480 
  • trunk/src/randname.c

    r116 r137  
    11/* 
    2  * randname.c - random name generation 
    3  * Copyright (c) 2007 Antony Sidwell and others, 
     2 * File: randname.c 
     3 * Purpose: Random name generation 
    44 * Based on W. Sheldon Simms name generator originally in randart.c 
    55 * 
    6  * This file is distributed under the terms of both the Angband licence and 
    7  * under the GPL licence (version 2 or any later version).  It may be  
    8  * redistributed under the terms of either licence.  
     6 * Copyright (c) 2007 Antony Sidwell and others 
     7 * 
     8 * This work is free software; you can redistribute it and/or modify it 
     9 * under the terms of either: 
     10 * 
     11 * a) the GNU General Public License as published by the Free Software 
     12 *    Foundation, version 2, or 
     13 * 
     14 * b) the "Angband licence": 
     15 *    This software may be copied and distributed for educational, research, 
     16 *    and not for profit purposes provided that this copyright and statement 
     17 *    are included in all such copies.  Other copyrights may also apply. 
    918 */ 
    1019#include "angband.h" 
  • trunk/src/types.h

    r117 r137  
    953953        bool run_break_left;    /* Looking for a break (left) */ 
    954954 
     955        bool auto_pickup_okay;      /* Allow automatic pickup */ 
     956 
    955957        s16b command_cmd;               /* Gives identity of current command */ 
    956958        s16b command_arg;               /* Gives argument of current command */