ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/communicator/command_parser/stats.h
Revision: 1.3
Committed: Mon Oct 25 12:06:58 2010 UTC (16 years ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -0 lines
Log Message:
be more strict about the protocol

File Contents

# Content
1 #include "deliantra/data/statistics.h"
2
3 #include "adt/array_map.h"
4
5 using data::statistics;
6
7 static array_map<s16 (statistics::*)> const u16_stats {
8 { CS_STAT_HP, &statistics::s_hp },
9 { CS_STAT_MAXHP, &statistics::s_maxhp },
10 { CS_STAT_SP, &statistics::s_sp },
11 { CS_STAT_MAXSP, &statistics::s_maxsp },
12 { CS_STAT_STR, &statistics::s_str },
13 { CS_STAT_INT, &statistics::s_int },
14 { CS_STAT_WIS, &statistics::s_wis },
15 { CS_STAT_DEX, &statistics::s_dex },
16 { CS_STAT_CON, &statistics::s_con },
17 { CS_STAT_CHA, &statistics::s_cha },
18 { CS_STAT_LEVEL, &statistics::s_level },
19 { CS_STAT_WC, &statistics::s_wc },
20 { CS_STAT_AC, &statistics::s_ac },
21 { CS_STAT_DAM, &statistics::s_dam },
22 { CS_STAT_ARMOUR, &statistics::s_armour },
23 { CS_STAT_FOOD, &statistics::s_food },
24 { CS_STAT_POW, &statistics::s_pow },
25 { CS_STAT_GRACE, &statistics::s_grace },
26 { CS_STAT_MAXGRACE, &statistics::s_maxgrace },
27 { CS_STAT_FLAGS, &statistics::s_flags },
28 { CS_STAT_RES_PHYS, &statistics::s_res_phys },
29 { CS_STAT_RES_MAG, &statistics::s_res_mag },
30 { CS_STAT_RES_FIRE, &statistics::s_res_fire },
31 { CS_STAT_RES_ELEC, &statistics::s_res_elec },
32 { CS_STAT_RES_COLD, &statistics::s_res_cold },
33 { CS_STAT_RES_CONF, &statistics::s_res_conf },
34 { CS_STAT_RES_ACID, &statistics::s_res_acid },
35 { CS_STAT_RES_DRAIN, &statistics::s_res_drain },
36 { CS_STAT_RES_GHOSTHIT, &statistics::s_res_ghosthit },
37 { CS_STAT_RES_POISON, &statistics::s_res_poison },
38 { CS_STAT_RES_SLOW, &statistics::s_res_slow },
39 { CS_STAT_RES_PARA, &statistics::s_res_para },
40 { CS_STAT_TURN_UNDEAD, &statistics::s_turn_undead },
41 { CS_STAT_RES_FEAR, &statistics::s_res_fear },
42 { CS_STAT_RES_DEPLETE, &statistics::s_res_deplete },
43 { CS_STAT_RES_DEATH, &statistics::s_res_death },
44 { CS_STAT_RES_HOLYWORD, &statistics::s_res_holyword },
45 { CS_STAT_RES_BLIND, &statistics::s_res_blind },
46 };
47
48 static array_map<s32 (statistics::*)> const u32_stats {
49 { CS_STAT_EXP, &statistics::s_exp },
50 { CS_STAT_WEIGHT_LIM, &statistics::s_weight_lim },
51 { CS_STAT_SPELL_ATTUNE, &statistics::s_spell_attune },
52 { CS_STAT_SPELL_REPEL, &statistics::s_spell_repel },
53 { CS_STAT_SPELL_DENY, &statistics::s_spell_deny },
54 };
55
56 static array_map<s64 (statistics::*)> const u64_stats {
57 { CS_STAT_EXP64, &statistics::s_exp64 },
58 };
59
60 static array_map<std::string (statistics::*)> const string_stats {
61 { CS_STAT_RANGE, &statistics::s_range },
62 { CS_STAT_TITLE, &statistics::s_title },
63 };
64
65 static array_map<float (statistics::*)> const float_stats {
66 { CS_STAT_SPEED, &statistics::s_speed },
67 { CS_STAT_WEAP_SP, &statistics::s_weap_sp },
68 };
69
70 void
71 command_parser::on_stats (std::istream &args)
72 {
73 while (args.peek () != EOF)
74 {
75 u08 stat = read_u08 (args);
76
77 auto const &logs = LOG;
78 logs ("server") << "stat " << u32 (stat) << ": ";
79
80 if (u16_stats.has (stat))
81 logs << (stats.*u16_stats[stat] = read_u16 (args));
82 else if (u32_stats.has (stat))
83 logs << (stats.*u32_stats[stat] = read_u32 (args));
84 else if (u64_stats.has (stat))
85 logs << (stats.*u64_stats[stat] = read_u64 (args));
86 else if (string_stats.has (stat))
87 logs << (stats.*string_stats[stat] = read_string08 (args));
88 else if (float_stats.has (stat))
89 logs << (stats.*float_stats[stat] = (1 / FLOAT_MULTF) * read_u32 (args));
90 else if (stat >= CS_STAT_SKILLINFO && stat < CS_STAT_SKILLINFO + CS_NUM_SKILLS)
91 {
92 auto level = read_u08 (args);
93 auto value = read_u64 (args);
94 logs << "skillinfo: " << u32 (stat) << ": " << u32 (level) << ", " << value;
95 stats.s_skillinfo[stat - CS_STAT_SKILLINFO] = value;
96 }
97 else
98 {
99 logs << "\nserver: unknown stat " << u32 (stat) << '\n';
100 throw std::runtime_error ("unknown stat");
101 }
102
103 logs << '\n';
104
105 assert (args);
106 }
107 PARSE_END;
108
109 emit stats (stats);
110 }