00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if defined(macintosh)
00023 #include <types.h>
00024 #else
00025 #include <sys/types.h>
00026 #endif
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <time.h>
00031 #include "merc.h"
00032 #include "tables.h"
00033 #include "lookup.h"
00034
00035
00036 struct flag_stat_type {
00037 const struct flag_type *structure;
00038 bool stat;
00039 };
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 const struct flag_stat_type flag_stat_table[] = {
00051
00052 {area_flags, FALSE},
00053 {sex_flags, TRUE},
00054 {exit_flags, FALSE},
00055 {door_resets, TRUE},
00056 {room_flags, FALSE},
00057 {sector_flags, TRUE},
00058 {type_flags, TRUE},
00059 {extra_flags, FALSE},
00060 {wear_flags, FALSE},
00061 {act_flags, FALSE},
00062 {affect_flags, FALSE},
00063 {apply_flags, TRUE},
00064 {wear_loc_flags, TRUE},
00065 {wear_loc_strings, TRUE},
00066 {container_flags, FALSE},
00067
00068
00069
00070 {form_flags, FALSE},
00071 {part_flags, FALSE},
00072 {ac_type, TRUE},
00073 {size_flags, TRUE},
00074 {position_flags, TRUE},
00075 {off_flags, FALSE},
00076 {imm_flags, FALSE},
00077 {res_flags, FALSE},
00078 {vuln_flags, FALSE},
00079 {weapon_class, TRUE},
00080 {weapon_type2, FALSE},
00081 {apply_types, TRUE},
00082 {0, 0}
00083 };
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 bool is_stat (const struct flag_type *flag_table)
00094 {
00095 int flag;
00096
00097 for (flag = 0; flag_stat_table[flag].structure; flag++)
00098 {
00099 if (flag_stat_table[flag].structure == flag_table
00100 && flag_stat_table[flag].stat)
00101 return TRUE;
00102 }
00103 return FALSE;
00104 }
00105
00106
00107
00108
00109
00110
00111 int flag_value (const struct flag_type *flag_table, char *argument)
00112 {
00113 char word[MAX_INPUT_LENGTH];
00114 int bit;
00115 int marked = 0;
00116 bool found = FALSE;
00117
00118 if (is_stat (flag_table))
00119 return flag_lookup (argument, flag_table);
00120
00121
00122
00123
00124 for (;;)
00125 {
00126 argument = one_argument (argument, word);
00127
00128 if (word[0] == '\0')
00129 break;
00130
00131 if ((bit = flag_lookup (word, flag_table)) != NO_FLAG)
00132 {
00133 SET_BIT (marked, bit);
00134 found = TRUE;
00135 }
00136 }
00137
00138 if (found)
00139 return marked;
00140 else
00141 return NO_FLAG;
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151 char *flag_string (const struct flag_type *flag_table, int bits)
00152 {
00153 static char buf[2][512];
00154 static int cnt = 0;
00155 int flag;
00156
00157 if (++cnt > 1)
00158 cnt = 0;
00159
00160 buf[cnt][0] = '\0';
00161
00162 for (flag = 0; flag_table[flag].name != NULL; flag++)
00163 {
00164 if (!is_stat (flag_table) && IS_SET (bits, flag_table[flag].bit))
00165 {
00166 strcat (buf[cnt], " ");
00167 strcat (buf[cnt], flag_table[flag].name);
00168 }
00169 else if (flag_table[flag].bit == bits)
00170 {
00171 strcat (buf[cnt], " ");
00172 strcat (buf[cnt], flag_table[flag].name);
00173 break;
00174 }
00175 }
00176 return (buf[cnt][0] != '\0') ? buf[cnt] + 1 : "none";
00177 }