init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* $NetBSD: init.c,v 1.14 2004/01/27 20:30:29 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1983, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. #if 0
  33. static char sccsid[] = "@(#)init.c 8.4 (Berkeley) 4/30/95";
  34. #else
  35. __RCSID("$NetBSD: init.c,v 1.14 2004/01/27 20:30:29 jsm Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "extern.h"
  39. static int checkout(const char *);
  40. static const char *getutmp(void);
  41. static int wizard(const char *);
  42. void
  43. initialize(filename)
  44. const char *filename;
  45. {
  46. const struct objs *p;
  47. char *savefile;
  48. puts("Version 4.2, fall 1984.");
  49. puts("First Adventure game written by His Lordship, the honorable");
  50. puts("Admiral D.W. Riggle\n");
  51. location = dayfile;
  52. srand(getpid());
  53. username = getutmp();
  54. wordinit();
  55. if (filename == NULL) {
  56. direction = NORTH;
  57. ourtime = 0;
  58. snooze = CYCLE * 1.5;
  59. position = 22;
  60. setbit(wear, PAJAMAS);
  61. fuel = TANKFULL;
  62. torps = TORPEDOES;
  63. for (p = dayobjs; p->room != 0; p++)
  64. setbit(location[p->room].objects, p->obj);
  65. } else {
  66. savefile = save_file_name(filename, strlen(filename));
  67. restore(savefile);
  68. free(savefile);
  69. }
  70. wiz = wizard(username);
  71. signal(SIGINT, diesig);
  72. }
  73. static const char *
  74. getutmp()
  75. {
  76. struct passwd *ptr;
  77. ptr = getpwuid(getuid());
  78. if (ptr == NULL)
  79. return "";
  80. else
  81. return strdup(ptr->pw_name);
  82. }
  83. /* Hereditary wizards. A configuration file might make more sense. */
  84. static const char *const list[] = {
  85. "riggle",
  86. "chris",
  87. "edward",
  88. "comay",
  89. "yee",
  90. "dmr",
  91. "ken",
  92. 0
  93. };
  94. static const char *const badguys[] = {
  95. "wnj",
  96. "root",
  97. "ted",
  98. 0
  99. };
  100. static int
  101. wizard(uname)
  102. const char *uname;
  103. {
  104. int flag;
  105. if ((flag = checkout(uname)) != 0)
  106. printf("You are the Great wizard %s.\n", uname);
  107. return flag;
  108. }
  109. static int
  110. checkout(uname)
  111. const char *uname;
  112. {
  113. const char *const *ptr;
  114. for (ptr = list; *ptr; ptr++)
  115. if (strcmp(*ptr, uname) == 0)
  116. return 1;
  117. for (ptr = badguys; *ptr; ptr++)
  118. if (strcmp(*ptr, uname) == 0) {
  119. printf("You are the Poor anti-wizard %s. Good Luck!\n",
  120. uname);
  121. CUMBER = 3;
  122. WEIGHT = 9; /* that'll get him! */
  123. ourclock = 10;
  124. setbit(location[7].objects, WOODSMAN); /* viper room */
  125. setbit(location[20].objects, WOODSMAN); /* laser " */
  126. setbit(location[13].objects, DARK); /* amulet " */
  127. setbit(location[8].objects, ELF); /* closet */
  128. return 0; /* anything else, Chris? */
  129. }
  130. return 0;
  131. }