Changeset 1405

Show
Ignore:
Timestamp:
05/23/09 02:05:00 (10 months ago)
Author:
takkaria
Message:
  • (#829) Remove now-unnecessary duplication in init1.c
  • Make struct player_race use arrays for flags
  • Move all player-related types into player/types.h
Location:
trunk/src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/externs.h

    r1376 r1405  
    322322/* files.c */ 
    323323extern void html_screenshot(cptr name, int mode); 
    324 extern void player_flags(u32b *f1, u32b *f2, u32b *f3); 
     324extern void player_flags(u32b f[OBJ_FLAG_N]); 
    325325extern void display_player(int mode); 
    326326extern void display_player_stat_info(void); 
  • trunk/src/files.c

    r1346 r1405  
    105105 * Obtain the "flags" for the player as if he was an item 
    106106 */ 
    107 void player_flags(u32b *f1, u32b *f2, u32b *f3) 
    108 { 
    109         /* Clear */ 
    110         (*f1) = (*f2) = (*f3) = 0L; 
    111  
     107void player_flags(u32b f[OBJ_FLAG_N]) 
     108{ 
    112109        /* Add racial flags */ 
    113         (*f1) |= rp_ptr->flags1; 
    114         (*f2) |= rp_ptr->flags2; 
    115         (*f3) |= rp_ptr->flags3; 
     110        memcpy(f, rp_ptr->flags, sizeof(rp_ptr->flags)); 
    116111 
    117112        /* Some classes become immune to fear at a certain plevel */ 
    118         if (cp_ptr->flags & CF_BRAVERY_30) 
    119         { 
    120                 if (p_ptr->lev >= 30) (*f2) |= (TR1_RES_FEAR); 
    121         } 
     113        if ((cp_ptr->flags & CF_BRAVERY_30) && p_ptr->lev >= 30) 
     114                f[1] |= TR1_RES_FEAR; 
    122115} 
    123116 
     
    245238                        else 
    246239                        { 
    247                                 player_flags(&f[0], &f[1], &f[2]); 
     240                                player_flags(f); 
    248241 
    249242                                /* If the race has innate infravision, force the corresponding flag 
     
    251244                                   function will think the infravision is caused by equipment. */ 
    252245                                if (rp_ptr->infra > 0) 
    253                                 { 
    254246                                        f[0] |= (TR0_INFRA); 
    255                                 } 
    256247                        } 
    257248 
     
    470461 
    471462        /* Player flags */ 
    472         player_flags(&f[0], &f[1], &f[2]); 
     463        player_flags(&f); 
    473464 
    474465        /* Check stats */ 
  • trunk/src/init1.c

    r1374 r1405  
    13901390 * Grab one flag in an object_kind from a textual string 
    13911391 */ 
    1392 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what) 
    1393 { 
    1394         if (grab_one_flag(&k_ptr->flags[0], k_info_flags1, what) == 0) 
    1395                 return (0); 
    1396  
    1397         if (grab_one_flag(&k_ptr->flags[1], k_info_flags2, what) == 0) 
    1398                 return (0); 
    1399  
    1400         if (grab_one_flag(&k_ptr->flags[2], k_info_flags3, what) == 0) 
     1392static errr grab_one_object_flag(u32b flags[OBJ_FLAG_N], cptr what) 
     1393{ 
     1394        if (grab_one_flag(&flags[0], k_info_flags1, what) == 0 && 
     1395                        grab_one_flag(&flags[1], k_info_flags2, what) == 0 && 
     1396                        grab_one_flag(&flags[2], k_info_flags3, what) == 0) 
    14011397                return (0); 
    14021398 
     
    16451641 
    16461642                        /* Parse this entry */ 
    1647                         if (0 != grab_one_kind_flag(k_ptr, s)) 
     1643                        if (0 != grab_one_object_flag(k_ptr->flags, s)) 
    16481644                                return (PARSE_ERROR_INVALID_FLAG); 
    16491645 
     
    16871683} 
    16881684 
    1689  
    1690 /* 
    1691  * Grab one flag in an artifact_type from a textual string 
    1692  */ 
    1693 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what) 
    1694 { 
    1695         if (grab_one_flag(&a_ptr->flags[0], k_info_flags1, what) == 0) 
    1696                 return (0); 
    1697  
    1698         if (grab_one_flag(&a_ptr->flags[1], k_info_flags2, what) == 0) 
    1699                 return (0); 
    1700  
    1701         if (grab_one_flag(&a_ptr->flags[2], k_info_flags3, what) == 0) 
    1702                 return (0); 
    1703  
    1704         /* Oops */ 
    1705         msg_format("Unknown artifact flag '%s'.", what); 
    1706  
    1707         /* Error */ 
    1708         return (PARSE_ERROR_INVALID_FLAG); 
    1709 } 
    17101685 
    17111686 
     
    18661841 
    18671842                        /* Parse this entry */ 
    1868                         if (0 != grab_one_artifact_flag(a_ptr, s)) 
     1843                        if (0 != grab_one_object_flag(a_ptr->flags, s)) 
    18691844                                return (PARSE_ERROR_INVALID_FLAG); 
    18701845 
     
    19201895        return (0); 
    19211896} 
    1922  
    1923  
    1924 /* 
    1925  * Grab one flag in a ego-item_type from a textual string 
    1926  */ 
    1927 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what) 
    1928 { 
    1929         if (grab_one_flag(&e_ptr->flags[0], k_info_flags1, what) == 0) 
    1930                 return (0); 
    1931  
    1932         if (grab_one_flag(&e_ptr->flags[1], k_info_flags2, what) == 0) 
    1933                 return (0); 
    1934  
    1935         if (grab_one_flag(&e_ptr->flags[2], k_info_flags3, what) == 0) 
    1936                 return (0); 
    1937  
    1938         /* Oops */ 
    1939         msg_format("Unknown ego-item flag '%s'.", what); 
    1940  
    1941         /* Error */ 
    1942         return (PARSE_ERROR_INVALID_FLAG); 
    1943 } 
    1944  
    19451897 
    19461898 
     
    20982050 
    20992051                        /* Parse this entry */ 
    2100                         if (0 != grab_one_ego_item_flag(e_ptr, s)) 
     2052                        if (0 != grab_one_object_flag(e_ptr->flags, s)) 
    21012053                                return (PARSE_ERROR_INVALID_FLAG); 
    21022054 
     
    24452397} 
    24462398 
    2447  
    2448 /* 
    2449  * Grab one flag in a player_race from a textual string 
    2450  */ 
    2451 static errr grab_one_racial_flag(player_race *pr_ptr, cptr what) 
    2452 { 
    2453         if (grab_one_flag(&pr_ptr->flags1, k_info_flags1, what) == 0) 
    2454                 return (0); 
    2455  
    2456         if (grab_one_flag(&pr_ptr->flags2, k_info_flags2, what) == 0) 
    2457                 return (0); 
    2458  
    2459         if (grab_one_flag(&pr_ptr->flags3, k_info_flags3, what) == 0) 
    2460                 return (0); 
    2461  
    2462         /* Oops */ 
    2463         msg_format("Unknown player flag '%s'.", what); 
    2464  
    2465         /* Error */ 
    2466         return (PARSE_ERROR_INVALID_FLAG); 
    2467 } 
    24682399 
    24692400/* 
     
    26822613 
    26832614                        /* Parse this entry */ 
    2684                         if (0 != grab_one_racial_flag(pr_ptr, s)) 
     2615                        if (0 != grab_one_object_flag(pr_ptr->flags, s)) 
    26852616                                return (PARSE_ERROR_INVALID_FLAG); 
    26862617 
  • trunk/src/player/calcs.c

    r1404 r1405  
    613613 
    614614        /* Extract the player flags */ 
    615         player_flags(&collect_f[0], &collect_f[1], &collect_f[2]); 
     615        player_flags(collect_f); 
    616616 
    617617 
  • trunk/src/player/types.h

    r1370 r1405  
    245245} player_type; 
    246246 
     247 
     248 
     249 
     250/* 
     251 * Player sex info 
     252 */ 
     253typedef struct 
     254{ 
     255        cptr title;                     /* Type of sex */ 
     256        cptr winner;            /* Name of winner */ 
     257} player_sex; 
     258 
     259 
     260/* 
     261 * Player racial info 
     262 */ 
     263typedef struct 
     264{ 
     265        u32b name;                      /* Name (offset) */ 
     266        u32b text;                      /* Text (offset) */ 
     267         
     268        s16b r_adj[A_MAX];      /* Racial stat bonuses */ 
     269         
     270        s16b r_skills[SKILL_MAX];       /* racial skills */ 
     271         
     272        byte r_mhp;                     /* Race hit-dice modifier */ 
     273        byte r_exp;                     /* Race experience factor */ 
     274         
     275        byte b_age;                     /* base age */ 
     276        byte m_age;                     /* mod age */ 
     277         
     278        byte m_b_ht;            /* base height (males) */ 
     279        byte m_m_ht;            /* mod height (males) */ 
     280        byte m_b_wt;            /* base weight (males) */ 
     281        byte m_m_wt;            /* mod weight (males) */ 
     282         
     283        byte f_b_ht;            /* base height (females) */ 
     284        byte f_m_ht;            /* mod height (females) */ 
     285        byte f_b_wt;            /* base weight (females) */ 
     286        byte f_m_wt;            /* mod weight (females) */ 
     287         
     288        byte infra;                     /* Infra-vision range */ 
     289         
     290        byte choice;            /* Legal class choices */ 
     291         
     292        s16b hist;                      /* Starting history index */ 
     293         
     294        u32b flags[OBJ_FLAG_N]; /* Racial flags */ 
     295} player_race; 
     296 
     297 
     298/* 
     299 * Starting equipment entry 
     300 */ 
     301typedef struct 
     302{ 
     303        byte tval;      /* Item's tval */ 
     304        byte sval;      /* Item's sval */ 
     305        byte min;       /* Minimum starting amount */ 
     306        byte max;       /* Maximum starting amount */ 
     307} start_item; 
     308 
     309 
     310/* 
     311 * A structure to hold class-dependent information on spells. 
     312 */ 
     313typedef struct 
     314{ 
     315        byte slevel;            /* Required level (to learn) */ 
     316        byte smana;                     /* Required mana (to cast) */ 
     317        byte sfail;                     /* Minimum chance of failure */ 
     318        byte sexp;                      /* Encoded experience bonus */ 
     319} magic_type; 
     320 
     321 
     322/* 
     323 * Information about the player's "magic" 
     324 * 
     325 * Note that a player with a "spell_book" of "zero" is illiterate. 
     326 */ 
     327typedef struct 
     328{ 
     329        magic_type info[PY_MAX_SPELLS]; /* The available spells */ 
     330} player_magic; 
     331 
     332 
     333/* 
     334 * Player class info 
     335 */ 
     336typedef struct 
     337{ 
     338        u32b name;                      /* Name (offset) */ 
     339         
     340        u32b title[10];         /* Titles - offset */ 
     341         
     342        s16b c_adj[A_MAX];      /* Class stat modifier */ 
     343         
     344        s16b c_skills[SKILL_MAX];       /* class skills */ 
     345        s16b x_skills[SKILL_MAX];       /* extra skills */ 
     346         
     347        s16b c_mhp;                     /* Class hit-dice adjustment */ 
     348        s16b c_exp;                     /* Class experience factor */ 
     349         
     350        u32b flags;                     /* Class Flags */ 
     351         
     352        u16b max_attacks;       /* Maximum possible attacks */ 
     353        u16b min_weight;        /* Minimum weapon weight for calculations */ 
     354        u16b att_multiply;      /* Multiplier for attack calculations */ 
     355         
     356        byte spell_book;        /* Tval of spell books (if any) */ 
     357        u16b spell_stat;        /* Stat for spells (if any) */ 
     358        u16b spell_first;       /* Level of first spell */ 
     359        u16b spell_weight;      /* Weight that hurts spells */ 
     360         
     361        u32b sense_base;        /* Base pseudo-id value */ 
     362        u16b sense_div;         /* Pseudo-id divisor */ 
     363         
     364        start_item start_items[MAX_START_ITEMS];/**< The starting inventory */ 
     365         
     366        player_magic spells; /* Magic spells */ 
     367} player_class; 
     368 
     369 
     370/* 
     371 * Player background information 
     372 */ 
     373typedef struct 
     374{ 
     375        u32b text;                          /* Text (offset) */ 
     376         
     377        byte roll;                          /* Frequency of this entry */ 
     378        byte chart;                         /* Chart index */ 
     379        byte next;                          /* Next chart index */ 
     380        byte bonus;                         /* Social Class Bonus + 50 */ 
     381} hist_type; 
     382 
     383 
     384 
     385/* 
     386 * Some more player information 
     387 * 
     388 * This information is retained across player lives 
     389 */ 
     390typedef struct 
     391{ 
     392        char full_name[32];             /* Full name */ 
     393        char base_name[32];             /* Base name */ 
     394         
     395        bool opt[OPT_MAX];              /* Options */ 
     396         
     397        u32b window_flag[ANGBAND_TERM_MAX];     /* Window flags */ 
     398         
     399        byte hitpoint_warn;             /* Hitpoint warning (0 to 9) */ 
     400         
     401        byte delay_factor;              /* Delay factor (0 to 9) */ 
     402} player_other; 
     403 
     404 
     405 
    247406#endif /* INCLUDED_PLAYER_TYPES_H */ 
  • trunk/src/spells2.c

    r1353 r1405  
    431431 
    432432        /* And flags from the player */ 
    433         player_flags(&t[0], &t[1], &t[2]); 
     433        player_flags(t); 
    434434 
    435435        /* Extract flags */ 
  • trunk/src/types.h

    r1131 r1405  
    4343typedef struct owner_type owner_type; 
    4444typedef struct store_type store_type; 
    45 typedef struct magic_type magic_type; 
    46 typedef struct player_magic player_magic; 
    4745typedef struct spell_type spell_type; 
    48 typedef struct player_sex player_sex; 
    49 typedef struct player_race player_race; 
    50 typedef struct player_class player_class; 
    51 typedef struct hist_type hist_type; 
    52 typedef struct player_other player_other; 
    53 typedef struct start_item start_item; 
    5446typedef struct autoinscription autoinscription; 
    5547typedef struct history_info history_info; 
     
    175167 
    176168 
    177  
    178 /* 
    179  * A structure to hold class-dependent information on spells. 
    180  */ 
    181 struct magic_type 
    182 { 
    183         byte slevel;            /* Required level (to learn) */ 
    184         byte smana;                     /* Required mana (to cast) */ 
    185         byte sfail;                     /* Minimum chance of failure */ 
    186         byte sexp;                      /* Encoded experience bonus */ 
    187 }; 
    188  
    189  
    190 /* 
    191  * Information about the player's "magic" 
    192  * 
    193  * Note that a player with a "spell_book" of "zero" is illiterate. 
    194  */ 
    195 struct player_magic 
    196 { 
    197         magic_type info[PY_MAX_SPELLS]; /* The available spells */ 
    198 }; 
    199  
    200  
    201169/* 
    202170 * And here's the structure for the "fixed" spell information 
     
    213181 
    214182        byte spell_index;       /* Index into player_magic array */ 
    215 }; 
    216  
    217  
    218 /* 
    219  * Player sex info 
    220  */ 
    221 struct player_sex 
    222 { 
    223         cptr title;                     /* Type of sex */ 
    224  
    225         cptr winner;            /* Name of winner */ 
    226 }; 
    227  
    228  
    229 /* 
    230  * Player racial info 
    231  */ 
    232 struct player_race 
    233 { 
    234         u32b name;                      /* Name (offset) */ 
    235         u32b text;                      /* Text (offset) */ 
    236  
    237         s16b r_adj[A_MAX];      /* Racial stat bonuses */ 
    238  
    239         s16b r_skills[SKILL_MAX];       /* racial skills */ 
    240  
    241         byte r_mhp;                     /* Race hit-dice modifier */ 
    242         byte r_exp;                     /* Race experience factor */ 
    243  
    244         byte b_age;                     /* base age */ 
    245         byte m_age;                     /* mod age */ 
    246  
    247         byte m_b_ht;            /* base height (males) */ 
    248         byte m_m_ht;            /* mod height (males) */ 
    249         byte m_b_wt;            /* base weight (males) */ 
    250         byte m_m_wt;            /* mod weight (males) */ 
    251  
    252         byte f_b_ht;            /* base height (females) */ 
    253         byte f_m_ht;            /* mod height (females) */ 
    254         byte f_b_wt;            /* base weight (females) */ 
    255         byte f_m_wt;            /* mod weight (females) */ 
    256  
    257         byte infra;                     /* Infra-vision range */ 
    258  
    259         byte choice;            /* Legal class choices */ 
    260  
    261         s16b hist;                      /* Starting history index */ 
    262  
    263         u32b flags1;            /* Racial Flags, set 1 */ 
    264         u32b flags2;            /* Racial Flags, set 2 */ 
    265         u32b flags3;            /* Racial Flags, set 3 */ 
    266 }; 
    267  
    268  
    269 /* 
    270  * Starting equipment entry 
    271  */ 
    272 struct start_item 
    273 { 
    274         byte tval;      /* Item's tval */ 
    275         byte sval;      /* Item's sval */ 
    276         byte min;       /* Minimum starting amount */ 
    277         byte max;       /* Maximum starting amount */ 
    278 }; 
    279  
    280  
    281 /* 
    282  * Player class info 
    283  */ 
    284 struct player_class 
    285 { 
    286         u32b name;                      /* Name (offset) */ 
    287  
    288         u32b title[10];         /* Titles - offset */ 
    289  
    290         s16b c_adj[A_MAX];      /* Class stat modifier */ 
    291  
    292         s16b c_skills[SKILL_MAX];       /* class skills */ 
    293         s16b x_skills[SKILL_MAX];       /* extra skills */ 
    294  
    295         s16b c_mhp;                     /* Class hit-dice adjustment */ 
    296         s16b c_exp;                     /* Class experience factor */ 
    297  
    298         u32b flags;                     /* Class Flags */ 
    299  
    300         u16b max_attacks;       /* Maximum possible attacks */ 
    301         u16b min_weight;        /* Minimum weapon weight for calculations */ 
    302         u16b att_multiply;      /* Multiplier for attack calculations */ 
    303  
    304         byte spell_book;        /* Tval of spell books (if any) */ 
    305         u16b spell_stat;        /* Stat for spells (if any) */ 
    306         u16b spell_first;       /* Level of first spell */ 
    307         u16b spell_weight;      /* Weight that hurts spells */ 
    308  
    309         u32b sense_base;        /* Base pseudo-id value */ 
    310         u16b sense_div;         /* Pseudo-id divisor */ 
    311  
    312         start_item start_items[MAX_START_ITEMS];/**< The starting inventory */ 
    313  
    314         player_magic spells; /* Magic spells */ 
    315 }; 
    316  
    317  
    318 /* 
    319  * Player background information 
    320  */ 
    321 struct hist_type 
    322 { 
    323         u32b text;                          /* Text (offset) */ 
    324  
    325         byte roll;                          /* Frequency of this entry */ 
    326         byte chart;                         /* Chart index */ 
    327         byte next;                          /* Next chart index */ 
    328         byte bonus;                         /* Social Class Bonus + 50 */ 
    329 }; 
    330  
    331  
    332  
    333 /* 
    334  * Some more player information 
    335  * 
    336  * This information is retained across player lives 
    337  */ 
    338 struct player_other 
    339 { 
    340         char full_name[32];             /* Full name */ 
    341         char base_name[32];             /* Base name */ 
    342  
    343         bool opt[OPT_MAX];              /* Options */ 
    344  
    345         u32b window_flag[ANGBAND_TERM_MAX];     /* Window flags */ 
    346  
    347         byte hitpoint_warn;             /* Hitpoint warning (0 to 9) */ 
    348  
    349         byte delay_factor;              /* Delay factor (0 to 9) */ 
    350183}; 
    351184