1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.o_init.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.o_init.c,v 1.6 1999/11/16 10:26:37 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.o_init.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
6 #include "def.objects.h"
9 static void setgemprobs(void);
10 static bool interesting_to_discover(int);
18 while ((ch
= obj_symbols
[i
++]) != 0)
27 int i
, j
, first
, last
, sum
, end
;
32 * init base; if probs given check that they add up to 100, otherwise
33 * compute probs; shuffle descriptions
38 let
= objects
[first
].oc_olet
;
40 while (last
< end
&& objects
[last
].oc_olet
== let
41 && objects
[last
].oc_name
!= NULL
)
44 if ((!i
&& let
!= ILLOBJ_SYM
) || bases
[i
] != 0)
45 error("initialization error");
52 for (j
= first
; j
< last
; j
++)
53 sum
+= objects
[j
].oc_prob
;
55 for (j
= first
; j
< last
; j
++)
56 objects
[j
].oc_prob
= (100 + j
- first
) / (last
- first
);
60 error("init-prob error for %c", let
);
62 if (objects
[first
].oc_descr
!= NULL
&& let
!= TOOL_SYM
) {
63 /* shuffle, also some additional descriptions */
64 while (last
< end
&& objects
[last
].oc_olet
== let
)
68 i
= first
+ rn2(j
+ 1 - first
);
69 tmp
= objects
[j
].oc_descr
;
70 objects
[j
].oc_descr
= objects
[i
].oc_descr
;
71 objects
[i
].oc_descr
= tmp
;
81 int i
= bases
[letindex(let
)];
84 while ((prob
-= objects
[i
].oc_prob
) >= 0)
86 if (objects
[i
].oc_olet
!= let
|| !objects
[i
].oc_name
)
87 panic("probtype(%c) error, i=%d", let
, i
);
96 first
= bases
[letindex(GEM_SYM
)];
98 for (j
= 0; j
< 9 - dlevel
/ 3; j
++)
99 objects
[first
+ j
].oc_prob
= 0;
101 if (first
>= LAST_GEM
|| first
>= SIZE(objects
) ||
102 objects
[first
].oc_olet
!= GEM_SYM
||
103 objects
[first
].oc_name
== NULL
)
104 printf("Not enough gems? - first=%d j=%d LAST_GEM=%d\n",
106 for (j
= first
; j
< LAST_GEM
; j
++)
107 objects
[j
].oc_prob
= (20 + j
- first
) / (LAST_GEM
- first
);
111 oinit(void) /* level dependent initialization */
122 bwrite(fd
, (char *)bases
, sizeof(bases
));
123 bwrite(fd
, (char *)objects
, sizeof(objects
));
125 * as long as we use only one version of Hack/Quest we need not save
126 * oc_name and oc_descr, but we must save oc_uname for all objects
128 for (i
= 0; i
< SIZE(objects
); i
++) {
129 if (objects
[i
].oc_uname
) {
130 len
= strlen(objects
[i
].oc_uname
) + 1;
131 bwrite(fd
, (char *)&len
, sizeof(len
));
132 bwrite(fd
, objects
[i
].oc_uname
, len
);
143 mread(fd
, (char *)bases
, sizeof(bases
));
144 mread(fd
, (char *)objects
, sizeof(objects
));
145 for (i
= 0; i
< SIZE(objects
); i
++)
146 if (objects
[i
].oc_uname
) {
147 mread(fd
, (char *)&len
, sizeof(len
));
148 objects
[i
].oc_uname
= alloc(len
);
149 mread(fd
, objects
[i
].oc_uname
, len
);
154 dodiscovered(void) /* free after Robert Viduya */
159 cornline(0, "Discoveries");
162 for (i
= 0; i
< end
; i
++) {
163 if (interesting_to_discover(i
)) {
165 cornline(1, typename(i
));
169 pline("You haven't discovered anything yet...");
178 interesting_to_discover(int i
)
181 objects
[i
].oc_uname
!= NULL
||
182 (objects
[i
].oc_name_known
&& objects
[i
].oc_descr
!= NULL
)