-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.c
175 lines (127 loc) · 4.09 KB
/
update.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <stdio.h>
#include <time.h>
#include "structs.h"
#define bytemask 0xFF
struct old_char_point_data
{
sh_int mana;
sh_int max_mana; /* Not useable may be erased upon player file renewal */
sh_int hit;
sh_int max_hit; /* Max hit for NPC */
sh_int move;
sh_int max_move; /* Max move for NPC */
byte armor; /* Internal -100..100, external -10..10 AC */
int gold; /* Money carried */
int exp; /* The experience of the player */
sbyte hitroll; /* Any bonus or penalty to the hit roll */
sbyte damroll; /* Any bonus or penalty to the damage roll */
};
struct char_file_old_u
{
byte sex;
byte class;
byte level;
time_t birth; /* Time of birth of character */
int played; /* Number of secs played in total */
ubyte weight;
ubyte height;
char title[80];
sh_int hometown;
char description[240];
bool talks[MAX_TOUNGE];
sh_int load_room; /* Which room to place char in */
struct char_ability_data abilities;
struct old_char_point_data points;
struct char_skill_data skills[MAX_SKILLS];
struct affected_type affected[MAX_AFFECT];
/* specials */
byte spells_to_learn;
int alignment;
time_t last_logon; /* Time (in secs) of last logon */
ubyte act; /* ACT Flags */
/* char data */
char name[20];
char pwd[11];
sh_int apply_saving_throw[5];
int conditions[3];
};
void do_it(FILE *src, FILE *trg);
main(int argc, char **argv)
{
FILE *src, *trg;
if (argc != 3) {
fprintf(stderr, "Usage: %s source target\n", argv[0]);
exit (0);
} else if (!(src = fopen(argv[1], "rb")))
fprintf(stderr, "%s: Could not open.\n", argv[1]);
else if (!(trg = fopen(argv[2], "wb")))
fprintf(stderr, "%s: Could not open.\n", argv[2]);
else
do_it(src, trg);
fclose(src);
fclose(trg);
}
void do_it(FILE *src, FILE *trg)
{
struct char_file_u buf;
struct char_file_old_u oldbuf;
int a,b,c,d, n;
srand((int) time(0));
n=1;
for (;;)
{
fread(&oldbuf, sizeof(oldbuf), 1, src);
if (feof(src))
break;
/* do something */
buf.sex = oldbuf.sex;
buf.class = oldbuf.class;
buf.level = oldbuf.level;
buf.birth = oldbuf.birth; /* Time of birth of character */
buf.played = oldbuf.played; /* Number of secs played in total */
buf.weight = oldbuf.weight;
buf.height = oldbuf.height;
strcpy(buf.title, oldbuf.title);
buf.hometown = oldbuf.hometown;
strcpy(buf.description, oldbuf.description);
buf.talks[0] = oldbuf.talks[0];
buf.talks[1] = oldbuf.talks[1];
buf.talks[2] = oldbuf.talks[2];
buf.load_room = oldbuf.load_room;
buf.abilities = oldbuf.abilities;
buf.points.mana = oldbuf.points.mana;
buf.points.max_mana = oldbuf.points.max_mana;
buf.points.hit = oldbuf.points.hit;
buf.points.max_hit = oldbuf.points.max_hit;
buf.points.move = oldbuf.points.move;
buf.points.max_move = oldbuf.points.max_move;
buf.points.armor = 100;
buf.points.gold = oldbuf.points.gold;
buf.points.exp = oldbuf.points.exp;
buf.points.hitroll = 0;
buf.points.damroll = 0;
for(n=0; n < MAX_SKILLS; n++)
buf.skills[n] = oldbuf.skills[n];
for(n=0; n < MAX_AFFECT; n++)
buf.affected[n] = oldbuf.affected[n];
buf.spells_to_learn = oldbuf.spells_to_learn;
buf.alignment = oldbuf.alignment;
buf.last_logon = oldbuf.last_logon;
buf.act = oldbuf.act;
strcpy(buf.name,oldbuf.name);
strcpy(buf.pwd, oldbuf.pwd);
buf.apply_saving_throw[0] = oldbuf.apply_saving_throw[0];
buf.apply_saving_throw[1] = oldbuf.apply_saving_throw[1];
buf.apply_saving_throw[2] = oldbuf.apply_saving_throw[2];
buf.apply_saving_throw[3] = oldbuf.apply_saving_throw[3];
buf.apply_saving_throw[4] = oldbuf.apply_saving_throw[4];
buf.conditions[0] = oldbuf.conditions[0];
buf.conditions[1] = oldbuf.conditions[1];
buf.conditions[2] = oldbuf.conditions[2];
/* do something else */
fwrite(&buf, sizeof(buf), 1, trg);
}
printf("Size of buf is %d\n\rSize of oldbuf is %d\n\r",
sizeof(buf),
sizeof(oldbuf));
}