]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.o_init.c
1 /* $NetBSD: hack.o_init.c,v 1.6 2001/03/25 20:44:02 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.o_init.c,v 1.6 2001/03/25 20:44:02 jsm 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
;
37 * init base; if probs given check that they add up to 100, otherwise
38 * compute probs; shuffle descriptions
43 let
= objects
[first
].oc_olet
;
45 while (last
< end
&& objects
[last
].oc_olet
== let
46 && objects
[last
].oc_name
!= NULL
)
49 if ((!i
&& let
!= ILLOBJ_SYM
) || bases
[i
] != 0)
50 error("initialization error");
57 for (j
= first
; j
< last
; j
++)
58 sum
+= objects
[j
].oc_prob
;
60 for (j
= first
; j
< last
; j
++)
61 objects
[j
].oc_prob
= (100 + j
- first
) / (last
- first
);
65 error("init-prob error for %c", let
);
67 if (objects
[first
].oc_descr
!= NULL
&& let
!= TOOL_SYM
) {
68 /* shuffle, also some additional descriptions */
69 while (last
< end
&& objects
[last
].oc_olet
== let
)
73 i
= first
+ rn2(j
+ 1 - first
);
74 tmp
= objects
[j
].oc_descr
;
75 objects
[j
].oc_descr
= objects
[i
].oc_descr
;
76 objects
[i
].oc_descr
= tmp
;
87 int i
= bases
[letindex(let
)];
89 while ((prob
-= objects
[i
].oc_prob
) >= 0)
91 if (objects
[i
].oc_olet
!= let
|| !objects
[i
].oc_name
)
92 panic("probtype(%c) error, i=%d", let
, i
);
101 first
= bases
[letindex(GEM_SYM
)];
103 for (j
= 0; j
< 9 - dlevel
/ 3; j
++)
104 objects
[first
+ j
].oc_prob
= 0;
106 if (first
>= LAST_GEM
|| first
>= SIZE(objects
) ||
107 objects
[first
].oc_olet
!= GEM_SYM
||
108 objects
[first
].oc_name
== NULL
)
109 printf("Not enough gems? - first=%d j=%d LAST_GEM=%d\n",
111 for (j
= first
; j
< LAST_GEM
; j
++)
112 objects
[j
].oc_prob
= (20 + j
- first
) / (LAST_GEM
- first
);
117 { /* level dependent initialization */
127 bwrite(fd
, (char *) bases
, sizeof bases
);
128 bwrite(fd
, (char *) objects
, sizeof objects
);
130 * as long as we use only one version of Hack/Quest we need not save
131 * oc_name and oc_descr, but we must save oc_uname for all objects
133 for (i
= 0; i
< SIZE(objects
); i
++) {
134 if (objects
[i
].oc_uname
) {
135 len
= strlen(objects
[i
].oc_uname
) + 1;
136 bwrite(fd
, (char *) &len
, sizeof len
);
137 bwrite(fd
, objects
[i
].oc_uname
, len
);
148 mread(fd
, (char *) bases
, sizeof bases
);
149 mread(fd
, (char *) objects
, sizeof objects
);
150 for (i
= 0; i
< SIZE(objects
); i
++)
151 if (objects
[i
].oc_uname
) {
152 mread(fd
, (char *) &len
, sizeof len
);
153 objects
[i
].oc_uname
= (char *) alloc(len
);
154 mread(fd
, objects
[i
].oc_uname
, len
);
160 { /* free after Robert Viduya */
164 cornline(0, "Discoveries");
167 for (i
= 0; i
< end
; i
++) {
168 if (interesting_to_discover(i
)) {
170 cornline(1, typename(i
));
174 pline("You haven't discovered anything yet...");
175 cornline(3, (char *) 0);
177 cornline(2, (char *) 0);
183 interesting_to_discover(i
)
187 objects
[i
].oc_uname
!= NULL
||
188 (objects
[i
].oc_name_known
&& objects
[i
].oc_descr
!= NULL
)