]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.o_init.c
1 /* $NetBSD: hack.o_init.c,v 1.5 1997/10/19 16:58:37 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.o_init.c,v 1.5 1997/10/19 16:58:37 christos Exp $");
15 #include "def.objects.h"
16 #include "hack.onames.h" /* for LAST_GEM */
24 while ((ch
= obj_symbols
[i
++]) != 0)
33 int i
, j
, first
, last
, sum
, end
;
36 * init base; if probs given check that they add up to 100, otherwise
37 * compute probs; shuffle descriptions
42 let
= objects
[first
].oc_olet
;
44 while (last
< end
&& objects
[last
].oc_olet
== let
45 && objects
[last
].oc_name
!= NULL
)
48 if ((!i
&& let
!= ILLOBJ_SYM
) || bases
[i
] != 0)
49 error("initialization error");
56 for (j
= first
; j
< last
; j
++)
57 sum
+= objects
[j
].oc_prob
;
59 for (j
= first
; j
< last
; j
++)
60 objects
[j
].oc_prob
= (100 + j
- first
) / (last
- first
);
64 error("init-prob error for %c", let
);
66 if (objects
[first
].oc_descr
!= NULL
&& let
!= TOOL_SYM
) {
67 /* shuffle, also some additional descriptions */
68 while (last
< end
&& objects
[last
].oc_olet
== let
)
72 i
= first
+ rn2(j
+ 1 - first
);
73 tmp
= objects
[j
].oc_descr
;
74 objects
[j
].oc_descr
= objects
[i
].oc_descr
;
75 objects
[i
].oc_descr
= tmp
;
86 int i
= bases
[letindex(let
)];
88 while ((prob
-= objects
[i
].oc_prob
) >= 0)
90 if (objects
[i
].oc_olet
!= let
|| !objects
[i
].oc_name
)
91 panic("probtype(%c) error, i=%d", let
, i
);
100 first
= bases
[letindex(GEM_SYM
)];
102 for (j
= 0; j
< 9 - dlevel
/ 3; j
++)
103 objects
[first
+ j
].oc_prob
= 0;
105 if (first
>= LAST_GEM
|| first
>= SIZE(objects
) ||
106 objects
[first
].oc_olet
!= GEM_SYM
||
107 objects
[first
].oc_name
== NULL
)
108 printf("Not enough gems? - first=%d j=%d LAST_GEM=%d\n",
110 for (j
= first
; j
< LAST_GEM
; j
++)
111 objects
[j
].oc_prob
= (20 + j
- first
) / (LAST_GEM
- first
);
116 { /* level dependent initialization */
126 bwrite(fd
, (char *) bases
, sizeof bases
);
127 bwrite(fd
, (char *) objects
, sizeof objects
);
129 * as long as we use only one version of Hack/Quest we need not save
130 * oc_name and oc_descr, but we must save oc_uname for all objects
132 for (i
= 0; i
< SIZE(objects
); i
++) {
133 if (objects
[i
].oc_uname
) {
134 len
= strlen(objects
[i
].oc_uname
) + 1;
135 bwrite(fd
, (char *) &len
, sizeof len
);
136 bwrite(fd
, objects
[i
].oc_uname
, len
);
147 mread(fd
, (char *) bases
, sizeof bases
);
148 mread(fd
, (char *) objects
, sizeof objects
);
149 for (i
= 0; i
< SIZE(objects
); i
++)
150 if (objects
[i
].oc_uname
) {
151 mread(fd
, (char *) &len
, sizeof len
);
152 objects
[i
].oc_uname
= (char *) alloc(len
);
153 mread(fd
, objects
[i
].oc_uname
, len
);
159 { /* free after Robert Viduya */
163 cornline(0, "Discoveries");
166 for (i
= 0; i
< end
; i
++) {
167 if (interesting_to_discover(i
)) {
169 cornline(1, typename(i
));
173 pline("You haven't discovered anything yet...");
174 cornline(3, (char *) 0);
176 cornline(2, (char *) 0);
182 interesting_to_discover(i
)
186 objects
[i
].oc_uname
!= NULL
||
187 (objects
[i
].oc_name_known
&& objects
[i
].oc_descr
!= NULL
)