Source:Hack 1.0/hack.u init.c
Revision as of 22:43, 3 March 2008 by Kernigh bot (talk | contribs) (Hack 1.0/hack.u init.c moved to Source:Hack 1.0/hack.u init.c: Robot: moved page)
Below is the full text to hack.u_init.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/hack.u_init.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
Screenshots and source code from Hack are used under the CWI license.
1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ 2. 3. #include "hack.h" 4. #include <stdio.h> 5. #include <signal.h> 6. #define Strcat (void) strcat 7. #define UNDEF_TYP 0 8. #define UNDEF_SPE (-1) 9. extern struct obj *addinv(); 10. extern char plname[]; 11. 12. char pl_character[PL_CSIZ]; 13. 14. struct trobj { 15. uchar trotyp; 16. schar trspe; 17. char trolet; 18. Bitfield(trquan,6); 19. Bitfield(trknown,1); 20. }; 21. 22. #ifdef WIZARD 23. struct trobj Extra_objs[] = { 24. { 0, 0, 0, 0, 0 }, 25. { 0, 0, 0, 0, 0 } 26. }; 27. #endif WIZARD 28. 29. struct trobj Cave_man[] = { 30. { MACE, 1, WEAPON_SYM, 1, 1 }, 31. { BOW, 1, WEAPON_SYM, 1, 1 }, 32. { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */ 33. { LEATHER_ARMOR, 2, ARMOR_SYM, 1, 1 }, 34. { 0, 0, 0, 0, 0} 35. }; 36. 37. struct trobj Fighter[] = { 38. { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 }, 39. { RING_MAIL, 3, ARMOR_SYM, 1, 1 }, 40. { 0, 0, 0, 0, 0 } 41. }; 42. 43. struct trobj Knight[] = { 44. { LONG_SWORD, 0, WEAPON_SYM, 1, 1 }, 45. { SPEAR, 2, WEAPON_SYM, 1, 1 }, 46. { RING_MAIL, 4, ARMOR_SYM, 1, 1 }, 47. { HELMET, 1, ARMOR_SYM, 1, 1 }, 48. { SHIELD, 1, ARMOR_SYM, 1, 1 }, 49. { PAIR_OF_GLOVES, 1, ARMOR_SYM, 1, 1 }, 50. { 0, 0, 0, 0, 0 } 51. }; 52. 53. struct trobj Speleologist[] = { 54. { STUDDED_LEATHER_ARMOR, 3, ARMOR_SYM, 1, 1 }, 55. { UNDEF_TYP, 0, POTION_SYM, 2, 0 }, 56. { FOOD_RATION, 0, FOOD_SYM, 3, 1 }, 57. { ICE_BOX, 0, TOOL_SYM, 1, 0 }, 58. { 0, 0, 0, 0, 0} 59. }; 60. 61. struct trobj Tourist[] = { 62. { UNDEF_TYP, 0, FOOD_SYM, 10, 1 }, 63. { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 }, 64. { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 }, 65. { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */ 66. { 0, 0, 0, 0, 0 } 67. }; 68. 69. struct trobj Wizard[] = { 70. { ELVEN_CLOAK, 1, ARMOR_SYM, 1, 1 }, 71. { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 }, 72. { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 }, 73. { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 }, 74. { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 }, 75. { 0, 0, 0, 0, 0 } 76. }; 77. 78. #ifdef NEWS 79. int u_in_infl; 80. 81. u_in_intrup(){ 82. u_in_infl++; 83. (void) signal(SIGINT, u_in_intrup); 84. } 85. #endif NEWS 86. 87. u_init(){ 88. register int c,pc,i; 89. #ifdef NEWS 90. /* It is not unlikely that we get an interrupt here 91. intended to kill the news; unfortunately this would 92. also kill (part of) the following question */ 93. int (*prevsig)() = signal(SIGINT, u_in_intrup); 94. #endif NEWS 95. register char *cp; 96. char buf[256]; 97. if(pc = pl_character[0]) goto got_suffix; 98. buf[0] = 0; 99. Strcat(buf, "\nTell me what kind of character you are:\n"); 100. Strcat(buf, "Are you a Tourist, a Speleologist, a Fighter,\n"); 101. Strcat(buf, "\ta Knight, a Cave-man or a Wizard? [TSFKCW] "); 102. intrup: 103. for(cp = buf; *cp; cp++){ 104. #ifdef NEWS 105. if(u_in_infl){ 106. u_in_infl = 0; 107. goto intrup; 108. } 109. #endif NEWS 110. (void) putchar(*cp); 111. } 112. loop: 113. (void) fflush(stdout); 114. pc = 0; 115. while((c = getchar()) != '\n') { 116. if(c == EOF) { 117. #ifdef NEWS 118. if(u_in_infl) goto intrup; /* %% */ 119. #endif NEWS 120. settty("\nEnd of input?\n"); 121. exit(0); 122. } 123. if(!pc) pc = c; 124. } 125. if(!pc || !index("TSFKCWtsfkcw", pc)){ 126. printf("Answer with T,S,F,K,C or W. What are you? "); 127. goto loop; 128. } 129. got_suffix: 130. if('a' <= pc && pc <= 'z') pc += 'A'-'a'; 131. 132. #ifdef NEWS 133. (void) signal(SIGINT,prevsig); 134. #endif NEWS 135. 136. u.usym = '@'; 137. u.ulevel = 1; 138. init_uhunger(); 139. u.uhpmax = u.uhp = 12; 140. u.ustrmax = u.ustr = !rn2(20) ? 14 + rn2(7) : 16; 141. #ifdef QUEST 142. u.uhorizon = 6; 143. #endif QUEST 144. switch(pc) { 145. case 'C': 146. setpl_char("Cave-man"); 147. Cave_man[2].trquan = 12 + rnd(9)*rnd(9); 148. u.uhp = u.uhpmax = 16; 149. u.ustr = u.ustrmax = 18; 150. ini_inv(Cave_man); 151. break; 152. case 'T': 153. setpl_char("Tourist"); 154. Tourist[3].trquan = 20 + rnd(20); 155. u.ugold = u.ugold0 = rnd(1000); 156. u.uhp = u.uhpmax = 10; 157. u.ustr = u.ustrmax = 8; 158. ini_inv(Tourist); 159. break; 160. case 'W': 161. setpl_char("Wizard"); 162. for(i=1; i<=4; i++) if(!rn2(5)) 163. Wizard[i].trquan += rn2(3) - 1; 164. u.uhp = u.uhpmax = 15; 165. u.ustr = u.ustrmax = 16; 166. ini_inv(Wizard); 167. break; 168. case 'S': 169. setpl_char("Speleologist"); 170. Fast = INTRINSIC; 171. Stealth = INTRINSIC; 172. u.uhp = u.uhpmax = 12; 173. u.ustr = u.ustrmax = 10; 174. ini_inv(Speleologist); 175. break; 176. case 'K': 177. setpl_char("Knight"); 178. u.uhp = u.uhpmax = 12; 179. u.ustr = u.ustrmax = 10; 180. ini_inv(Knight); 181. break; 182. case 'F': 183. setpl_char("Fighter"); 184. u.uhp = u.uhpmax = 14; 185. u.ustr = u.ustrmax = 17; 186. ini_inv(Fighter); 187. } 188. find_ac(); 189. /* make sure he can carry all he has - especially for T's */ 190. while(inv_weight() > 0 && u.ustr < 118) 191. u.ustr++, u.ustrmax++; 192. #ifdef WIZARD 193. if(wizard) wiz_inv(); 194. #endif WIZARD 195. } 196. 197. ini_inv(trop) register struct trobj *trop; { 198. register struct obj *obj; 199. extern struct obj *mkobj(); 200. while(trop->trolet) { 201. obj = mkobj(trop->trolet); 202. obj->known = trop->trknown; 203. obj->cursed = 0; 204. if(obj->olet == WEAPON_SYM){ 205. obj->quan = trop->trquan; 206. trop->trquan = 1; 207. } 208. if(trop->trspe != UNDEF_SPE) 209. obj->spe = trop->trspe; 210. if(trop->trotyp != UNDEF_TYP) 211. obj->otyp = trop->trotyp; 212. obj->owt = weight(obj); /* defined after setting otyp+quan */ 213. obj = addinv(obj); 214. if(obj->olet == ARMOR_SYM){ 215. switch(obj->otyp){ 216. case SHIELD: 217. if(!uarms) setworn(obj, W_ARMS); 218. break; 219. case HELMET: 220. if(!uarmh) setworn(obj, W_ARMH); 221. break; 222. case PAIR_OF_GLOVES: 223. if(!uarmg) setworn(obj, W_ARMG); 224. break; 225. case ELVEN_CLOAK: 226. if(!uarm2) 227. setworn(obj, W_ARM); 228. break; 229. default: 230. if(!uarm) setworn(obj, W_ARM); 231. } 232. } 233. if(obj->olet == WEAPON_SYM) 234. if(!uwep) setuwep(obj); 235. if(--trop->trquan) continue; /* make a similar object */ 236. trop++; 237. } 238. } 239. 240. #ifdef WIZARD 241. wiz_inv(){ 242. register struct trobj *trop = &Extra_objs[0]; 243. extern char *getenv(); 244. register char *ep = getenv("INVENT"); 245. register int type; 246. while(ep && *ep) { 247. type = atoi(ep); 248. ep = index(ep, ','); 249. if(ep) while(*ep == ',' || *ep == ' ') ep++; 250. if(type <= 0 || type > NROFOBJECTS) continue; 251. trop->trotyp = type; 252. trop->trolet = objects[type].oc_olet; 253. trop->trspe = 4; 254. trop->trknown = 1; 255. trop->trquan = 1; 256. ini_inv(trop); 257. } 258. /* give him a wand of wishing by default */ 259. trop->trotyp = WAN_WISHING; 260. trop->trolet = WAND_SYM; 261. trop->trspe = 20; 262. trop->trknown = 1; 263. trop->trquan = 1; 264. ini_inv(trop); 265. } 266. #endif WIZARD 267. 268. setpl_char(plc) char *plc; { 269. (void) strncpy(pl_character, plc, PL_CSIZ-1); 270. pl_character[PL_CSIZ-1] = 0; 271. } 272. 273. plnamesuffix() { 274. register char *p; 275. if(p = rindex(plname, '-')) { 276. *p = 0; 277. if(!plname[0]) { 278. askname(); 279. plnamesuffix(); 280. } 281. if(index("TSFKCWtsfkcw", p[1])) { 282. pl_character[0] = p[1]; 283. pl_character[1] = 0; 284. } 285. } 286. }