├── .gitignore ├── LICENCE ├── README.md ├── bin └── .gitignore ├── cgalib └── .gitignore ├── doc └── ossuary.txt ├── inc ├── bitmap.h ├── cgalib.h ├── display.h ├── errors.h ├── font.h ├── game.h ├── scores.h └── screen.h ├── makefile ├── obj └── .gitignore ├── ossuary └── .gitignore ├── pic └── ossuary.pic └── src ├── bitmap.c ├── display.c ├── errors.c ├── font.c ├── fontconv.c ├── game.c ├── makegfx.c ├── ossuary.c ├── scores.c └── screen.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | .* 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ossuary 2 | 3 | Ossuary is a very simplistic Roguelike for DOS, designed to run on any PC with an 8088 or better processor, and CGA or compatible graphics. DOS binaries with packaged documentation are available on [Itch](https://cyningstan.itch.io/ossuary) and at the game's [home page](http://damian.cyningstan.org.uk/download/176/ossuary-for-dos). 4 | 5 | The gameplay is extremely simplistic and was originally designed for a 16K ZX Spectrum computer. If you want a deep, detailed roguelike experience then this is probably not the game for you. If you are happy with a half-hour dungeon crawl involving just a handful of different monsters and weapons then this might be your cup of tea. 6 | 7 | ## Getting Started 8 | 9 | If you just want to play the game, then I recommend downloading the binary package from one of the sources above. This repo is for those who want to examine the source code, and perhaps to modify it or fork their own version of the game. 10 | 11 | The source files are developed for OpenWatcom C 2.0. Compilation has been tested both under Linux and DOS. It may work under Windows too, but if your system cannot compile the source natively then it should work under DOSBox. 12 | 13 | The game uses a modified version of the CGALIB library, the original of which may or may not be available on GitHub by the time you read this (at the time of writing, it isn't). But since this is a modified version of the library, it is included with this repo. 14 | 15 | ## Building on Linux 16 | 17 | To build for Linux, you need OpenWatcom 2.0 to be set up properly for compilation, with its environment variables and path set as per the compiler's documentation. You will also need DOSBox to be set up and accessible as it is called as part of the build process. 18 | 19 | In case you're new to git or github, the first thing you need to do (after installing git and getting a github account) is to clone the repo: 20 | 21 | ``` 22 | $ git clone https://github.com/cyningstan/ossuary 23 | $ cd ossuary 24 | ``` 25 | 26 | Then, assuming that you have your OpenWatcom set up for compilation under Linux, you can just run OpenWatcom's make utility: 27 | 28 | ``` 29 | $ wmake 30 | ``` 31 | 32 | The program that generates the game's asset file is a DOS program; you will briefly see DOSBox appear when that program is run. After successful building, there will be a second `ossuary` directory within the first one; this inner directory is the DOS distribution and can be zipped for distribution, moved to your DOSBox's C drive or transferred to whatever other environment you want to run the game on. 33 | 34 | ## Building for DOS 35 | 36 | First you need to clone the repo using whatever facility your host operating system offers. For the sake of this guide I'll assume that you're using Linux and you're going to clone ossuary into /home/me/ossuary. That done, launch DOSBox. Choose a free drive letter; I'll assume D, and mount the repo into a DOS drive: 37 | 38 | ``` 39 | Z:\> mount d /home/me/ossuary 40 | Z:\> d: 41 | ``` 42 | 43 | From here, run the wmake utility as per the Linux example: 44 | 45 | ``` 46 | D:\> wmake 47 | ``` 48 | 49 | The program that generates the assets briefly puts them on the screen, so you may see a graphical display pop up for a fraction of a second. Once the compilation is done, the `D:\OSSUARY` directory will contain the compiled, installed game for you to run or to transfer elsewhere. 50 | 51 | ## Licence 52 | 53 | CGALIB is public domain. If you'd like to use it, I'd recommend grabbing the original distribution from [here](http://damian.cyningstan.org.uk/download/163/cgalib-a-graphics-library-for-cga-games) instead of working with the customised version used by Ossuary. I intend to give it its own GitHub repo eventually. 54 | 55 | The rest of the game is released under the GPL. If you'd like to make a port, or use Ossuary's code in your own project, the LICENSE file tells you what you have to do (basically distribute your own modifications under the GPL too). 56 | -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /cgalib/.gitignore: -------------------------------------------------------------------------------- 1 | *.lib 2 | *.exe 3 | -------------------------------------------------------------------------------- /doc/ossuary.txt: -------------------------------------------------------------------------------- 1 | OSSUARY 2 | A Simple Roguelike Dungeon Crawl 3 | Copyright (C) Damian Gareth Walker 2013, 2020. 4 | 5 | Contents: 6 | 7 | The Story 8 | The Game 9 | Running the Game 10 | How to Play 11 | Using the Menu 12 | Your Inventory 13 | Understanding Your Hero 14 | Items and Their Effects 15 | The Enemies 16 | Licence 17 | Acknowledgements 18 | 19 | The Story 20 | 21 | The villagers were quite proud of their ossuary. Centuries of 22 | custom and practice dictated that at the end of their lives, the 23 | people of this village, like all the other villages and towns in 24 | the land, would inter their dead in grand, uderground vaults 25 | built for the purpose. At special times, like birthdays and 26 | holidays, the living would descend into the ossuary to visit and 27 | make offerings to their ancestors. 28 | 29 | But things have been a bit different recently. Every age has its 30 | social ills, and today was no different. Though magic had often 31 | been used in medicine, religion and war, a new breed of 32 | sorcerors made it less welcome. A craze for necromancy took hold 33 | in the towns, and many young sorcerors developed an addiction 34 | for communicating with, and even raising, the dead. Senior 35 | practitioners of the magic arts needed a good reason to disturb 36 | the sleep of the dead, but their younger colleagues were often 37 | caught doing it for the sheer fun of it. 38 | 39 | This had to stop, and in a short time the more irresponsible 40 | students of magic were banished from the towns and the colleges 41 | in disgrace. Did this stop them? Of course not. Off they went 42 | into the country to find other places to practice their dark 43 | arts, and what better place to raise the dead than in the vast 44 | burial chambers built across the land? 45 | 46 | And so, periodically, along with the wolves, the goblins and the 47 | occasional dragon, villagers now have necromancers to put up 48 | with too. While the necromancers are happy to confine their 49 | activities to the underground chambers, making pets out of wild 50 | creatures and friends out of the dead, the intrusion of spirits 51 | and animated corpses adds nothing to the dignity of the funerals 52 | and other ceremonies the villagers are still trying to hold in 53 | their grand, centuries-old cemeteries. They want it stopped. The 54 | villagers want their Ossuary back. 55 | 56 | The Game 57 | 58 | Ossuary is an adventure game for the IBM PC and compatibles. You 59 | play the hero who has agreed to rid the ossuary of its unwanted 60 | visitor, the necromancer. You must fight your way through the 61 | twenty-four levels of enchanted creatures, animated bodies and 62 | summoned spirits with which the necromancer has filled his 63 | adopted domain. And on reaching the final level, you must defeat 64 | the necromancer himself. Your prize is all the gold you can 65 | carry. And being an adventurer, you can carry a lot. 66 | 67 | Every game is different. The layout of the dungeon is generated 68 | each time you play. While things get more difficult the further 69 | down you go, the manner in which this happens varies from one 70 | game to another. In some games you encounter spirits early on, 71 | while in other games it may take longer, but the very animals 72 | themselves become more vicious. Sometimes you will encounter a 73 | great variety of creatures on a single level, while at other 74 | times the enemies seem to come in waves, one kind succeeding 75 | another. 76 | 77 | Your character will also be different each time you play. Attack 78 | strength, defensive skill and intelligence are all randomly set 79 | at the beginning of the game, though every hero whose role you 80 | take on will be of a similar overall ability. In some games you 81 | might have a strong character suited to physical attacks; in 82 | others a physically weaker character might be better suited to 83 | magic; in some games the abilities are finely balanced and you 84 | need to see how your character develops in order to decide how 85 | best to deal with the various enemies. 86 | 87 | In the manner of dungeon hack games everywhere, there are 88 | objects to be found on the way which will help you in your 89 | quest. Some things sustain your health, there are weapons and 90 | shields to be found, magic wands and amulets may come in useful 91 | if you have the ability to use them, and there are incantation 92 | scrolls to keep evil spirits at bay. But with all this, your 93 | chances are still slim: all these things were left by previous, 94 | failed adventurers, who now add to the numbers of the wandering 95 | dead. 96 | 97 | Running the Game 98 | 99 | The minimum specification to run Ossuary is an IBM PC with an 100 | 8088 processor and CGA graphics, running PC-DOS or MS-DOS. The 101 | game will run at an acceptable speed on faster machines, and its 102 | graphics will display correctly on any CGA-compatible card with 103 | an RGB colour monitor. Clarity and legibility are not guaranteed 104 | on monochrome or colour composite monitors, but the game will 105 | run. 106 | 107 | The game can be run from a floppy disk or from a hard disk. The 108 | following instructions assume that you have the game installed 109 | to hard disk C: in the directory OSSUARY. To run the game, type 110 | the following commands: 111 | 112 | c: 113 | cd \ossuary 114 | ossuary 115 | 116 | The first thing you will see is the high score table. This lists 117 | the players who have made it back after ridding the Ossuary of 118 | its necromancer, and shows how much gold they collected. You 119 | will be asked under what name you want to play. Note that if you 120 | omit to type in a name, you will not be entered on the high 121 | score table even if you collect enough gold and beat the 122 | necromancer. Once you have entered your name, you will start 123 | your first game. 124 | 125 | How to Play 126 | 127 | The interface for Ossuary is very simple to pick up. You see the 128 | dungeon from the top down, in the form of a level plan. The four 129 | cursor keys move your hero around the map. You only see part of 130 | the current dungeon level at a time; the view is kept centred on 131 | your hero as you move around. You might notice that enemies move 132 | only when you do. Ossuary is a turn based game, in which careful 133 | thought is more important than fast reactions. 134 | 135 | To attack creatures, simply move so as to push into them. There 136 | is no specific attack command, nor is there ranged combat in the 137 | game. This much exploration and attacking can be done with the 138 | direction keys only, but the menu system and its shortcut keys 139 | give access to more of the game's features. To start playing the 140 | game properly, let's look at the screen in a bit more detail. 141 | 142 | The screen is split into four parts. The least important part is 143 | the bottom: this is purely there for decoration. The part you 144 | will be looking at most is in the middle: this is the map view 145 | on which you move around. The cyan bar underneath the map is the 146 | message bar. It is used to show brief messages, and to show the 147 | menu. 148 | 149 | To the left are your hero's statistics. These are his strengths, 150 | and the additions to his natural abilities which are affected by 151 | the things he is currently holding. At the bottom of this panel 152 | is the amount of gold collected, which functions as a score in 153 | the game. It will be listed on the high score screen if you beat 154 | the necromancer. 155 | 156 | On the right is the inventory, the items your hero has collected 157 | and holds in his hands or in his bag. You'll need to understand 158 | this and the statistics panel to play the game effectively, but 159 | first let's look at the menu. 160 | 161 | Using the Menu 162 | 163 | The SPACE bar activates the menu. The current option will appear 164 | on the menu bar, and pressing SPACE again will select 165 | it. Pressing LEFT and RIGHT will allow you to select the other 166 | options that are available to you. The game will normally try to 167 | select the most appropriate option when you first press SPACE, 168 | so for instance, when standing at an item you can pick up, PICK 169 | UP ITEM is the default option. This means that much of the time 170 | you can take the most appropriate action at any given time just 171 | by pressing SPACE twice. The menu options are: 172 | 173 | SHOW GAME KEYS 174 | WAIT A MOMENT... 175 | VIEW INVENTORY 176 | PICK UP ITEM 177 | DESCEND STAIRS 178 | EAT A NICE APPLE 179 | QUAFF A POTION 180 | START NEW GAME 181 | EXIT THIS GAME 182 | CANCEL MENU 183 | 184 | If no appropriate action suggests itself, the default option 185 | will be VIEW INVENTORY. From this you can see how to pick up 186 | items, and to descend the stairs to the next level. You can, by 187 | the way, go downstairs leaving monsters and objects behind, but 188 | trying to rush headlong down to the last level without fighting 189 | or collecting anything is a recipe for failure. 190 | 191 | All of these options have shortcut keys which can be used to 192 | activate them with or without bringing up the menu first; those 193 | shortcut keys are given as each option is discussed. 194 | 195 | SHOW GAME KEYS brings up a list of in-game shortcut keys. Space 196 | is cramped, so where alternative keys exist for a function they 197 | will not be listed. ESC returns to gameplay when viewing that 198 | list. 199 | 200 | The WAIT A MOMENT... option makes the hero stand still while 201 | allowing the other creatures to move; useful if you want to wait 202 | for an enemy to come to you or move out of the way. The shortcut 203 | key for this is the dot (full-stop, or period, depending on 204 | where you come from). 205 | 206 | VIEW INVENTORY enters the inventory subsystem, which is 207 | explained in detail later. The shortcut key for this is I. 208 | 209 | PICK UP ITEM picks up any item in the square where the hero is 210 | standing, and puts it in the hero's bag. The shortcut key is T 211 | (for "take"). 212 | 213 | DESCEND STAIRS will take the hero down the stairs to the next 214 | level. The shortcut key is S, but players of other roguelike 215 | games will be pleased to know the > key also works. 216 | 217 | EAT A NICE APPLE selects an apple from the hero's hands or bag, 218 | and eats it, restoring four health points. the shortcut key is 219 | E. 220 | 221 | QUAFF A POTION selects a health potion from the hero's hands or 222 | bag, and quaffs it, restoring the hero to full health. The 223 | shortcut key is Q. 224 | 225 | START NEW GAME abandons the current game and starts afresh with 226 | a new hero in a new Ossuary. You are asked for confirmation, 227 | then given an opportunity to choose another name for your hero, 228 | before the new game begins. The shortcut key is N. 229 | 230 | EXIT THIS GAME abandons the game and returns to DOS. The 231 | shortcut keys are X and ESC. As with starting a new game, you 232 | are asked for confirmation in case you pressed the key by 233 | mistake. 234 | 235 | CANCEL MENU lets you exit the menu without choosing an option, 236 | in case you entered it by mistake. Its shortcut key, while 237 | viewing the menu only, is ESC. 238 | 239 | As promised, it is time to look more closely at the VIEW 240 | INVENTORY option. 241 | 242 | Your Inventory 243 | 244 | The panel on the right of the screen shows the items you are 245 | currently carrying with you. The top two items are separate; 246 | these are the things you are holding in your hands, or wielding 247 | as the game puts it. The other items are in your bag, not 248 | currently being used but available for you at any time you need 249 | them. Usually you would wield a weapon and a shield or a 250 | protective amulet. 251 | 252 | When you select the option VIEW INVENTORY from the main menu, a 253 | cursor appears in this panel. The action in the game is 254 | suspended, and your movement controls instead move the cursor 255 | around your inventory. The message bar identifies the currently 256 | selected item. Pressing SPACE when viewing the inventory brings 257 | up another menu: 258 | 259 | WIELD ITEM 260 | PUT ITEM AWAY 261 | CONSUME ITEM 262 | DISCARD ITEM 263 | CLOSE INVENTORY 264 | 265 | The CLOSE INVENTORY option returns you to the game without any 266 | other effect, allowing you to move around again. The shortcut 267 | key is ESC. 268 | 269 | All the other options, when used successfully, cause time to 270 | pass as with the WAIT A MOMENT... option on the main menu. The 271 | relevant shortcut keys are available while moving around the 272 | inventory or while browsing this menu. They are not available 273 | from the main menu or while moving your hero; you need to enter 274 | VIEW INVENTORY first. 275 | 276 | WIELD ITEM will put the currently selected item into your 277 | hand. The cursor needs to be on an item in your bag, and one 278 | hand needs to be empty. Ossuary doesn't care whether your hero 279 | is left- or right-handed, so it doesn't matter which hand your 280 | weapon is in. The shortcut key is W. 281 | 282 | PUT ITEM AWAY will return a wielded item to your bag, and is 283 | only useful when selecting an item in your hand. The shortcut 284 | key is P. 285 | 286 | CONSUME ITEM, useful only for apples and potions, causes you to 287 | eat or drink the currently selected item. You can do this 288 | directly from the bag; you do not need to be wielding the 289 | item. This differs from the EAT/DRINK options available from 290 | outside the inventory; here you choose the apple or potion, and 291 | it allows you to be fussy about the layout of your 292 | inventory. The shortcut key is C, but if you are pointing at an 293 | apple you can use E, and if you are pointing at a potion you can 294 | use Q. 295 | 296 | DISCARD ITEM drops the currently selected item on the 297 | ground. This cannot be done where there is already an item on 298 | the ground where the hero stands, and you cannot drop items down 299 | the stairs! The shortcut key is D. 300 | 301 | Understanding Your Hero 302 | 303 | Your hero is described by the statistics panel on the left of 304 | the screen. The four statistics are Attack Strength, identified 305 | by the fist, Defence Skill shown by the raised hand, 306 | Intelligence shown by the quill, and Health shown by the heart. 307 | 308 | The first three statistics are generated randomly at the start 309 | of the game. Under each is a modifier, preceded by a + 310 | sign. This shows how much that statistic has been augmented by 311 | objects the hero is wielding. Weapons modify the attack 312 | strength, shields modify defence skill, and magical items modify 313 | intelligence. 314 | 315 | The fourth statistic, health, is calculated by adding together 316 | the other three. This calculates a maximum; health is depleted 317 | by enemy attacks, but can be restored to this maximum. The 318 | current health level is above the bar, the maximum is below. 319 | 320 | Items and their Effects 321 | 322 | The following items are available at various points in the game: 323 | 324 | Gold. The purse of gold contains 20 gold pieces. The casket of 325 | gold contains 50 gold pieces. These are added straight to your 326 | gold total when you pick them up; they don't take up any space 327 | in your inventory and have no other use apart from score. 328 | 329 | A nice apple. These refreshing snacks restore four hit points to 330 | your health when you eat them. They will not increase your 331 | health beyond its maximum limit. They are more common than 332 | potions. 333 | 334 | A magic potion. Potions restore your health to its maximum. If 335 | you have only slight injuries, it is better to eat an apple than 336 | to waste a potion which could be used to restore a greater 337 | amount of health. 338 | 339 | Weapons. These add to your attack strength when you wield 340 | them. The dagger adds +2 points, the broadsword adds +4, and the 341 | battle axe adds +6. It is possible to wield two weapons for 342 | added effect, like the sword and the axe for +10, but it is only 343 | advisable if you have a high natural defence skill. 344 | 345 | Shields. When wielded, a shield will add to your hero's natural 346 | defence skill. The wooden shield adds +2, and the iron shield 347 | adds +4. It is possible to wield them both, but is not 348 | recommended as your hero is more effective when carrying a 349 | weapon. 350 | 351 | A magic wand. This has two effects when wielded. Firstly, a +2 352 | modifier is added to intelligence. Secondly, all attacks are 353 | magical, and use the modified intelligence rather than physical 354 | attack strength. 355 | 356 | A magic amulet. This needs to be wielded to be useful. Wielding 357 | it has two effects. Firstly, a +2 modifier is added to 358 | intelligence. Secondly, all defence is magical, and uses the 359 | modified intelligence rather than physical defence skill. The 360 | amulet is often combined with the wand to give a +4 intelligence 361 | modifier, as this combined modifier affects both attack and 362 | defence. 363 | 364 | A banish spell. When wielded in place of a weapon, this spell 365 | can banish a spectre or daemon. Chances of success are a little 366 | under 50%. There is a small chance that the spell will crumble 367 | to dust on failure, so it is advisable to carry a few spells. As 368 | spectres and daemons are immune to physical attacks, the banish 369 | spell is the most effective way to deal with them for heroes 370 | without good magical abilities. 371 | 372 | The Enemies 373 | 374 | Bats. These giant bats have little attack power but their 375 | agility gives them good defence skill. They are also the only 376 | non-humanoid enemies that can pick up and carry objects. Still, 377 | they are the easiest creatures in the game to beat. 378 | 379 | Other creatures. Other enemies from the animal kingdom become 380 | progressively more difficult to beat: the vermin are giant rats, 381 | arachnids are giant spiders with a nasty bite, and serpents have 382 | a scaly hide which gives them great defensive ability. These 383 | creatures cannot carry items, but are often found guarding them. 384 | 385 | Corpses. There are two kinds: cadavers, whose decomposing forms 386 | are still dangerous foes, and skeletons whose bleached bones are 387 | all that remains of these centuries-old warriors. Both of these 388 | enemies can carry items with them. 389 | 390 | Spirits. These are also of two kinds: spectres and 391 | daemons. Neither can be hurt with physical weapons, though 392 | shields might be useful against their attacks. Spectres are 393 | often found guarding valuable items, while daemons are able to 394 | pick things up and carry them. 395 | 396 | The Necromancer. This is the ultimate enemy, as strong as any 397 | daemon, he sits in his lair awaiting your arrival. Only the 398 | stoutest hero will make it to face him, let alone defeat him. 399 | 400 | Licence 401 | 402 | You are welcome to copy Ossuary and share it with your 403 | friends. The source code is also available for inspection, 404 | modification and distribution under the GNU General Public 405 | Licence, a full copy of which is included in the source code 406 | distribution. 407 | 408 | Acknowledgements 409 | 410 | Thanks must go to Phil Cooper, Ricky Walker, and discord users 411 | bananaboy, Epona142, DethroTull and Kimdol for their help in 412 | testing the DOS release of this game. 413 | 414 | DGW, July 2020. 415 | -------------------------------------------------------------------------------- /inc/bitmap.h: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Bitmap Module Header. 4 | * 5 | * Definitions for the bitmap functions. Also includes the bitmap 6 | * structure for internal use only. 7 | * 8 | * Copyright (C) Damian Walker 2020. 9 | * Created 29-Jun-2020. 10 | */ 11 | 12 | #ifndef __BITMAP_H__ 13 | #define __BITMAP_H__ 14 | 15 | /*---------------------------------------------------------------------- 16 | * Internal Structures. 17 | */ 18 | 19 | /** @struct bitmap holds the information for a bitmap */ 20 | #ifdef __CGALIB__ 21 | struct bitmap { 22 | 23 | /** @var width is the width of the bitmap in pixels */ 24 | int width; 25 | 26 | /** @var height is the height of the bitmap in pixels */ 27 | int height; 28 | 29 | /** @var ink is the ink colour used in the bitmap */ 30 | int ink; 31 | 32 | /** @var paper is the paper colour used in the bitmap */ 33 | int paper; 34 | 35 | /** @ar font is the font used for bit_print() operations */ 36 | Font *font; 37 | 38 | /** @var pixels is a pointer to the pixel data */ 39 | char *pixels; 40 | 41 | }; 42 | #endif 43 | 44 | /*---------------------------------------------------------------------- 45 | * Public Level Function Prototypes. 46 | */ 47 | 48 | /** 49 | * Create a bitmap. 50 | * @param w is the width of the bitmap. 51 | * @param h is the height of the bitmap. 52 | * @returns a new Bitmap. 53 | */ 54 | Bitmap *bit_create (int w, int h); 55 | 56 | /** 57 | * Create a bitmap by copying another. 58 | * @param src is the bitmap to copy. 59 | * @returns a new Bitmap. 60 | */ 61 | Bitmap *bit_copy (Bitmap *src); 62 | 63 | /** 64 | * Read a bitmap from an already-open file. 65 | * @param input is the input file handle. 66 | * @returns a new Bitmap. 67 | */ 68 | Bitmap *bit_read (FILE *input); 69 | 70 | /** 71 | * Write a bitmap to an already-open file. 72 | * @param bitmap is the bitmap to write. 73 | * @param output is the file handle to write to. 74 | */ 75 | void bit_write (Bitmap *bitmap, FILE *output); 76 | 77 | /** 78 | * Put one bitmap onto another, with clipping. 79 | * @param dst is the destination bitmap. 80 | * @param src is the source bitmap. 81 | * @param x is the y coordinate on the destination bitmap. 82 | * @param y is the x coordinate on the destination bitmap. 83 | * @param d is the drawing mode to use. 84 | */ 85 | void bit_put (Bitmap *dst, Bitmap *src, int x, int y, DrawMode draw); 86 | 87 | /** 88 | * Get one bitmap from another. 89 | * @param src is the source bitmap. 90 | * @param dst is the destination bitmap. 91 | * @param x is the x coordinate on the source bitmap. 92 | * @param y is the y coordinate on the source bitmap. 93 | */ 94 | void bit_get (Bitmap *src, Bitmap *dst, int x, int y); 95 | 96 | /** 97 | * Draw a box onto a Bitmap, filled in the current ink colour. 98 | * @param bitmap is the destination bitmap. 99 | * @param x is the x coordinate of the top left of the box. 100 | * @param y is the y coordinate of the top left of the box. 101 | * @param width is the width of the box. 102 | * @param height is the height of the box. 103 | * The draw mode is always DRAW_PUT. For anything more sophisticated, 104 | * the scr_put() function should be used. 105 | */ 106 | void bit_box (Bitmap *bitmap, int x, int y, int width, int height); 107 | 108 | /** 109 | * Print some text onto a bitmap in the current ink colour. 110 | * @param bitmap is the destination bitmap. 111 | * @param x is the x coordinate where the text should appear. 112 | * @param y is the y coordinate where the text should appear. 113 | * @param message is the message to print. 114 | * The text is printed in a box of the paper colour. 115 | */ 116 | void bit_print (Bitmap *bitmap, int x, int y, char *message); 117 | 118 | /** 119 | * Set the ink colour for scr_box and scr_print operations. 120 | * @param bitmap is the bitmap to set the colour for. 121 | * @param ink is the colour to use, 0..3. 122 | */ 123 | void bit_ink (Bitmap *bitmap, int ink); 124 | 125 | /** 126 | * Set the paper colour for scr_print operations. 127 | * @param bitmap is the bitmap to set the colour for. 128 | * @param paper is the colour to use, 0..3. 129 | */ 130 | void bit_paper (Bitmap *bitmap, int paper); 131 | 132 | /** 133 | * Set the font for scr_print operations. 134 | * @param bitmap is the bitmap to set the font for. 135 | * @param font is the font to use. 136 | */ 137 | void bit_font (Bitmap *bitmap, Font *font); 138 | 139 | /** 140 | * Destroy a bitmap. 141 | * @param bitmap is the bitmap to destroy. 142 | */ 143 | void bit_destroy (Bitmap *bitmap); 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /inc/cgalib.h: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Main Header File. 4 | * 5 | * Provides a central header file for programs using CGALib. 6 | * Includes the other headers for all functionality. 7 | * 8 | * Copyright (C) Damian Walker 2020. 9 | * Created 29-Jun-2020. 10 | */ 11 | 12 | #ifndef __CGALIB_H__ 13 | #define __CGALIB_H__ 14 | 15 | #include 16 | 17 | /* Structure Type Definitions */ 18 | typedef struct screen Screen; 19 | typedef struct bitmap Bitmap; 20 | typedef struct font Font; 21 | 22 | /* Enum Type Definitions */ 23 | typedef enum { 24 | DRAW_PSET, 25 | DRAW_PRESET, 26 | DRAW_AND, 27 | DRAW_OR, 28 | DRAW_XOR 29 | } DrawMode; 30 | 31 | /* included headers */ 32 | #include "screen.h" 33 | #include "bitmap.h" 34 | #include "font.h" 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /inc/display.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Screen handling header. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | #ifndef __SCREEN_H__ 11 | #define __SCREEN_H__ 12 | 13 | /*---------------------------------------------------------------------- 14 | * Type definitions 15 | */ 16 | 17 | /* Bitmaps */ 18 | typedef struct bitmap Bitmap; 19 | 20 | /*---------------------------------------------------------------------- 21 | * Public Level Routine Prototypes. 22 | */ 23 | 24 | /** 25 | * Initialise the screen. 26 | * @param mono is 1 for monochrome graphics, 0 for colour. 27 | * @param palette is 1 for ugly palette, 0 for custom palette. 28 | */ 29 | int init_screen (int mono, int palette); 30 | 31 | /** 32 | * Load the game graphics. 33 | */ 34 | int load_graphics (void); 35 | 36 | /** 37 | * Display the updates to the text window. 38 | */ 39 | void display_text (void); 40 | 41 | /** 42 | * Display a number in the gold statistic box. 43 | * @param gold is the amount of gold. 44 | */ 45 | void display_gold (int gold); 46 | 47 | /** 48 | * Display one of the three hero stats. 49 | * @param stat_no is the stat number, 0..2. 50 | * @param stat_val is the value of the stat. 51 | * @param stat_mod is the modifier. 52 | */ 53 | void display_stat (int stat_no, int stat_val, int stat_mod); 54 | 55 | /** 56 | * Display the hero's health. 57 | * @param health_val is the current health value. 58 | * @param health_max is the maximum health value. 59 | */ 60 | void display_health (int health_val, int health_max); 61 | 62 | /** 63 | * Display an inventory slot. 64 | * @param slot is the slot number. 65 | * @param item is the item number. 66 | */ 67 | void display_inventory (int slot, int item); 68 | 69 | /** 70 | * Highlight an inventory slot with the cursor. 71 | * @param slot is the slot number. 72 | */ 73 | void highlight_inventory (int slot); 74 | 75 | /** 76 | * Display a message in the bottom text area 77 | * @param message is the message to print 78 | */ 79 | void display_message (char *message); 80 | 81 | /* 82 | * Blank out the previous message. 83 | */ 84 | void blank_message (void); 85 | 86 | /** 87 | * Display some text in the top text area. 88 | * @param message is the message to print 89 | */ 90 | void display_heading (char *message); 91 | 92 | /** 93 | * Alter a tile on the drawn map 94 | * @param x is the X location to alter. 95 | * @param y is the Y location to alter. 96 | * @param value is the map square value. 97 | */ 98 | void update_map_tile (int x, int y, int value); 99 | 100 | /** 101 | * Build and display the visible portion of the game map. 102 | * @param map is the whole map. 103 | * @param hero_x is the hero's X location. 104 | * @param hero_y is the hero's Y locaation. 105 | */ 106 | void display_map (int hero_x, int hero_y); 107 | 108 | /** 109 | * Display a blank square in the map area. 110 | */ 111 | void blank_map (void); 112 | 113 | /** 114 | * Get a keypress, adding 0x8000 for extended codes, and converting 115 | * upper case letters to lower case. 116 | * @returns the keypress 117 | */ 118 | int get_keypress (void); 119 | 120 | /** 121 | * Clean up the display. 122 | */ 123 | void clean_up_display (void); 124 | 125 | /** 126 | * Display a game over message and wait for a key. 127 | * @param line_1 is the first line of the message. 128 | * @param line_2 is the second line of the message. 129 | * The lines are assumed to be exactly 8 characters long. 130 | */ 131 | void display_game_over (char *line_1, char *line_2); 132 | 133 | /** 134 | * Print a debug message at the bottom of the screen. 135 | * @param message is the message. 136 | */ 137 | void debug_message (char *message); 138 | 139 | /** 140 | * Display a row of the high score table. 141 | * @param row is the row number. 142 | * @param name is the name. 143 | * @param gold is the gold. 144 | */ 145 | void display_score (int row, char *name, int gold, int highlight); 146 | 147 | /** 148 | * Display the game keys. 149 | */ 150 | void display_keys (void); 151 | 152 | /** 153 | * Noise for a hit in combat. 154 | */ 155 | void hit_noise (void); 156 | 157 | /** 158 | * Noise for a kill in combat. 159 | */ 160 | void kill_noise (void); 161 | 162 | /** 163 | * Noise for some inventory action. 164 | */ 165 | void inventory_noise (void); 166 | 167 | /** 168 | * Noise for the clink of gold. 169 | */ 170 | void gold_noise (void); 171 | 172 | /** 173 | * Noise for descending the stairs. 174 | */ 175 | void stairs_noise (void); 176 | 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /inc/errors.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Error handling header. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | #ifndef __ERRORS_H__ 11 | #define __ERRORS_H__ 12 | 13 | /*---------------------------------------------------------------------- 14 | * Public Level Function Prototypes. 15 | */ 16 | 17 | /** 18 | * Exit the program on an error condition, showing the error. 19 | * @param exit_code is the code that determines what the error was. 20 | */ 21 | void exit_game (int exit_code); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /inc/font.h: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Font Module Header. 4 | * 5 | * Definitions for the bitmap functions. Also includes the bitmap 6 | * structure for internal use only. 7 | * 8 | * Copyright (C) Damian Walker 2020. 9 | * Created 29-Jun-2020. 10 | */ 11 | 12 | #ifndef __FONT_H__ 13 | #define __FONT_H__ 14 | 15 | /*---------------------------------------------------------------------- 16 | * Internal Structures. 17 | */ 18 | 19 | /** @struct font holds the data for a single font. */ 20 | #ifdef __CGALIB__ 21 | struct font { 22 | 23 | /** @var first is the first character in a font */ 24 | int first; 25 | 26 | /** @var lst is the last character in a font */ 27 | int last; 28 | 29 | /** @var pixels is the pixel data for each character */ 30 | char *pixels; 31 | }; 32 | #endif 33 | 34 | /*---------------------------------------------------------------------- 35 | * Public Level Function Prototypes. 36 | */ 37 | 38 | /** 39 | * Create a new font. 40 | * @param first is the first character in the font. 41 | * @param last is the last character in the font. 42 | * @returns the new font. 43 | */ 44 | Font *fnt_create (int first, int last); 45 | 46 | /** 47 | * Copy a font. 48 | * @param font is the font to copy. 49 | * @returns a new font copied from the old. 50 | */ 51 | Font *fnt_copy (Font *src); 52 | 53 | /** 54 | * Read a font from an already open file. 55 | * @param input is the input file handle. 56 | * @returns the new font. 57 | */ 58 | Font *fnt_read (FILE *input); 59 | 60 | /** 61 | * Write a font to an already open file. 62 | * @param font is the font to write. 63 | * @param output is the output file handle. 64 | */ 65 | void fnt_write (Font *font, FILE *output); 66 | 67 | /** 68 | * Put a bitmap into a font character. 69 | * @param dst is the destination font. 70 | * @param src is the source bitmap. 71 | * @param ch is the character to set. 72 | */ 73 | void fnt_put (Font *dst, Bitmap *src, int ch); 74 | 75 | /** 76 | * Get a bitmap from a font character. 77 | * @param src is the source font. 78 | * @param dst is the destination bitmap. 79 | * @param ch is the character to get. 80 | */ 81 | void fnt_get (Font *src, Bitmap *dst, int ch); 82 | 83 | /** 84 | * Set the font colours permanently. 85 | * @param font is the font to modify. 86 | * @param i is the ink colour. 87 | * @param p is the paper colour. 88 | * This function offers a quicker alternative to colouring text as it is 89 | * printed, and may be used if ALL text is going to be a certain colour. 90 | * It can be used in conjunction with the fnt_copy() function to quickly 91 | * output text in multiple colours (fnt_copy then apply fnt_colours). 92 | * Note that this assumes that the colours are already ink 3, paper 0. 93 | * After changing the font colours, this will no longer be the case 94 | * and further colour changes will have unpredictable results. 95 | */ 96 | void fnt_colours (Font *font, int i, int p); 97 | 98 | /** 99 | * Destroy a font. 100 | * @param font is the font to destroy. 101 | */ 102 | void fnt_destroy (Font *font); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /inc/game.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Game handling header. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | #ifndef __GAME_H__ 11 | #define __GAME_H__ 12 | 13 | /*---------------------------------------------------------------------- 14 | * Defined Constants. 15 | */ 16 | 17 | /* key code constants */ 18 | #define KEY_UP 0x8048 19 | #define KEY_KEYPAD_UP 0x38 20 | #define KEY_DOWN 0x8050 21 | #define KEY_KEYPAD_DOWN 0x32 22 | #define KEY_LEFT 0x804b 23 | #define KEY_KEYPAD_LEFT 0x34 24 | #define KEY_RIGHT 0x804d 25 | #define KEY_KEYPAD_RIGHT 0x36 26 | #define KEY_FIRE 0x0020 27 | 28 | /*---------------------------------------------------------------------- 29 | * Public Level Function Declarations. 30 | */ 31 | 32 | /** 33 | * Initialise some game variables. 34 | */ 35 | void init_game (void); 36 | 37 | /** 38 | * Generate the hero. 39 | */ 40 | void generate_hero (void); 41 | 42 | /** 43 | * Initialise the inventory. 44 | */ 45 | void init_inventory (void); 46 | 47 | /** 48 | * Show the player stats. 49 | */ 50 | void show_stats (void); 51 | 52 | /** 53 | * Show the gold counter. 54 | */ 55 | void show_gold (void); 56 | 57 | /** 58 | * Show the inventory. 59 | */ 60 | void show_inventory (void); 61 | 62 | /** 63 | * Ask the player for their name. 64 | */ 65 | void ask_name (void); 66 | 67 | /** 68 | * Initialise the map for a level 69 | */ 70 | void generate_map (void); 71 | 72 | /** 73 | * Place the hero on the current level 74 | */ 75 | void place_hero (void); 76 | 77 | /** 78 | * Place the level's objective (staircase or necromancer) 79 | */ 80 | void place_objective (void); 81 | 82 | /** 83 | * Place the level's eight enemies 84 | */ 85 | void place_enemies (void); 86 | 87 | /** 88 | * Place the level's items 89 | */ 90 | void place_items (void); 91 | 92 | /** 93 | * Generate the drawn map from a new level. 94 | */ 95 | void generate_drawn_map (void); 96 | 97 | /** 98 | * Show the level number 99 | */ 100 | void show_level (void); 101 | 102 | /** 103 | * Show the map window 104 | */ 105 | void show_map (void); 106 | 107 | /** 108 | * Get and process player action. 109 | * @returns 1 if the player successfully performed an action. 110 | * May return 0 if, for example, the player tried to walk into a wall 111 | * or selected some menu option that does not constitute an action. 112 | */ 113 | int player_action (void); 114 | 115 | /** 116 | * Generate and process enemy action 117 | */ 118 | void enemy_action (void); 119 | 120 | /** 121 | * Generate and process the necromancer's action. 122 | */ 123 | void necro_action (void); 124 | 125 | /** 126 | * See if the level is over. 127 | * @returns 1 if the level is over, 0 if not. 128 | */ 129 | int level_is_over (void); 130 | 131 | /** 132 | * See if the game is over. 133 | * @returns 1 if the game is over, 0 if not. 134 | */ 135 | int game_is_over (void); 136 | 137 | /** 138 | * Return a code to say who won the game, if anyone. 139 | * @returns +1 if the hero won, -1 if the hero lost, 0 otherwise. 140 | */ 141 | int who_won (void); 142 | 143 | /** 144 | * See if user wants to quit. 145 | * @returns 1 if the player wants to quit, 0 if not. 146 | */ 147 | int player_quit (void); 148 | 149 | /** 150 | * Return the player name. 151 | * @returns pointer to player name. 152 | */ 153 | char *get_name (void); 154 | 155 | /** 156 | * Return the player's gold 157 | * @returns the gold 158 | */ 159 | int get_gold (void); 160 | 161 | /** 162 | * Return the level number. 163 | * @returns the current level number. 164 | */ 165 | int get_level (void); 166 | 167 | #endif 168 | -------------------------------------------------------------------------------- /inc/scores.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Score handling header. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 16-Jul-2020. 8 | */ 9 | 10 | #ifndef __SCORES_H__ 11 | #define __SCORES_H__ 12 | 13 | /*---------------------------------------------------------------------- 14 | * Public Level Function Declarations. 15 | */ 16 | 17 | /** 18 | * Load or generate the high score table. 19 | */ 20 | void load_scores (void); 21 | 22 | /** 23 | * Show the high score table. 24 | */ 25 | void show_scores (void); 26 | 27 | /** 28 | * Save the scores at the end of the game (if changed) 29 | */ 30 | void save_scores (void); 31 | 32 | /** 33 | * Consider adding a score to the high score table. 34 | * @param name is the player name. 35 | * @param gold is the amount of gold. 36 | */ 37 | void add_score (char *name, int gold); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /inc/screen.h: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Screen Header File. 4 | * 5 | * Definitions for the hardware screen functions. 6 | * 7 | * Copyright (C) Damian Walker 2020. 8 | * Created 29-Jun-2020. 9 | */ 10 | 11 | #ifndef __SCREEN_H__ 12 | #define __SCREEN_H__ 13 | 14 | /*---------------------------------------------------------------------- 15 | * Internal structures. 16 | */ 17 | 18 | /** @struct screen holds screen information */ 19 | #ifdef __CGALIB__ 20 | struct screen { 21 | 22 | /** @var mode is the video mode */ 23 | int mode; 24 | 25 | /** @var palette is the palette number */ 26 | int palette; 27 | 28 | /** @var colour is the palette background colour */ 29 | int colour; 30 | 31 | /** @var ink is the ink colour */ 32 | int ink; 33 | 34 | /** @var paper is the paper colour */ 35 | int paper; 36 | 37 | /** @var font is the current font */ 38 | Font *font; 39 | }; 40 | #endif 41 | 42 | /*---------------------------------------------------------------------- 43 | * Public Level Function Prototypes. 44 | */ 45 | 46 | /** 47 | * Initialise the screen, and set its initial screen mode. 48 | * @param m is the screen mode: 4, 5 or 6. 49 | * @returns the new screen. 50 | */ 51 | Screen *scr_create (int mode); 52 | 53 | /** 54 | * Set the screen palette. 55 | * @param screen is the screen to affect. 56 | * @param p is the palette number, 0..5. 57 | * @param c is the background colour, 0..15. 58 | */ 59 | void scr_palette (Screen *screen, int palette, int colour); 60 | 61 | /** 62 | * Put a bitmap onto the screen. 63 | * @param dst is the screen to affect. 64 | * @param src is the source bitmap. 65 | * @param x is the x coordinate at which the bitmap is to be placed. 66 | * @param y is the y coordinate at which the bitmap is to be placed. 67 | * @param d is the draw mode. 68 | */ 69 | void scr_put (Screen *dst, Bitmap *src, int x, int y, DrawMode draw); 70 | 71 | /** 72 | * Get a bitmap from the screen. 73 | * @param src is the screen from which the bitmap comes. 74 | * @param dst is the destination bitmap, whose size is already set. 75 | * @param x is the x coordinate where the desired pattern lies. 76 | * @param y is the y coordinate where the desired pattern lies. 77 | */ 78 | void scr_get (Screen *src, Bitmap *dst, int x, int y); 79 | 80 | /** 81 | * Draw a box on the screen, filled in the current ink colour. 82 | * @param screen is the screen to affect. 83 | * @param x is the x coordinate of the top left of the box. 84 | * @param y is the y coordinate of the top left of the box. 85 | * @param w is the width of the box. 86 | * @param h is the height of the box. 87 | * The draw mode is always DRAW_PUT. For anything more sophisticated, 88 | * the scr_put() function should be used. 89 | */ 90 | void scr_box (Screen *screen, int x, int y, int width, int height); 91 | 92 | /** 93 | * Print some text on the screen in the current ink colour. 94 | * @param screen is the screen to affect. 95 | * @param x is the x coordinate where the text should appear. 96 | * @param y is the y coordinate where the text should appear. 97 | * @param message is the message to print. 98 | * The text is printed in a box of the paper colour. 99 | */ 100 | void scr_print (Screen *screen, int x, int y, char *message); 101 | 102 | /** 103 | * Set the ink colour for scr_box and scr_print operations. 104 | * @param screen is the screen to affect. 105 | * @param ink is the colour to use, 0..3. 106 | */ 107 | void scr_ink (Screen *screen, int ink); 108 | 109 | /** 110 | * Set the paper colour for scr_print operations. 111 | * @param screen is the screen to affect. 112 | * @param paper is the colour to use, 0..3. 113 | */ 114 | void scr_paper (Screen *screen, int paper); 115 | 116 | /** 117 | * Set the font for scr_print operations. 118 | * @param screen is the screen to affect. 119 | * @param font is the font to use. 120 | */ 121 | void scr_font (Screen *screen, Font *font); 122 | 123 | /** 124 | * Reset the screen back to text mode which graphic output is finished. 125 | * @param screen is the screen to affect. 126 | */ 127 | void scr_destroy (Screen *screen); 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------- 2 | # Ossuary 3 | # A DOS port of the ZX Spectrum rogue-like. 4 | # Main game source file. 5 | # 6 | # Copyright (C) Damian Gareth Walker 2020. 7 | # Created: 22-Jun-2020. 8 | # 9 | 10 | # Directories 11 | SRCDIR = src 12 | INCDIR = inc 13 | DOCDIR = doc 14 | PICDIR = pic 15 | FONDIR = fon 16 | OBJDIR = obj 17 | BINDIR = bin 18 | LIBCGA = cgalib 19 | TGTDIR = ossuary 20 | 21 | # Tool commands and their options 22 | CC = wcc 23 | LD = wcl 24 | LIB = wlib 25 | COPTS = -q -0 -W4 -ml -I=$(INCDIR) 26 | LOPTS = -q 27 | 28 | # Host specific build tools 29 | !ifdef __LINUX__ 30 | CP = cp 31 | MAKEGFX = dosbox -c "mount y $(%cwd)" & 32 | -c "y:" & 33 | -c "$(BINDIR)\\makegfx $[@ $@" & 34 | -c "exit" 35 | RM = rm 36 | !else 37 | CP = copy 38 | MAKEGFX = $(BINDIR)\\makegfx $[@ $@ 39 | RM = del 40 | !endif 41 | 42 | GAME : $(TGTDIR)/ossuary.exe & 43 | $(TGTDIR)/OSSUARY.GFX & 44 | $(TGTDIR)/ossuary.txt 45 | 46 | # Game executables 47 | $(TGTDIR)/ossuary.exe : $(OBJDIR)/ossuary.obj & 48 | $(OBJDIR)/display.obj & 49 | $(OBJDIR)/game.obj & 50 | $(OBJDIR)/scores.obj & 51 | $(OBJDIR)/errors.obj & 52 | $(LIBCGA)/cga-ml.lib 53 | $(LD) $(LOPTS) -fe=$@ $< 54 | $(BINDIR)/makegfx.exe : $(OBJDIR)/makegfx.obj $(LIBCGA)/cga-ml.lib 55 | $(LD) $(LOPTS) -fe=$@ $< 56 | 57 | # Game data files 58 | $(TGTDIR)/OSSUARY.GFX : $(PICDIR)/ossuary.pic $(BINDIR)/makegfx.exe 59 | $(MAKEGFX) 60 | $(TGTDIR)/ossuary.txt : $(DOCDIR)/ossuary.txt 61 | $(CP) $< $@ 62 | 63 | # Object files (Ossuary) 64 | $(OBJDIR)/ossuary.obj : $(SRCDIR)/ossuary.c 65 | $(CC) $(COPTS) -fo=$@ $< 66 | $(OBJDIR)/game.obj : $(SRCDIR)/game.c 67 | $(CC) $(COPTS) -fo=$@ $< 68 | $(OBJDIR)/display.obj : $(SRCDIR)/display.c 69 | $(CC) $(COPTS) -fo=$@ $< 70 | $(OBJDIR)/scores.obj : $(SRCDIR)/scores.c 71 | $(CC) $(COPTS) -fo=$@ $< 72 | $(OBJDIR)/errors.obj : $(SRCDIR)/errors.c 73 | $(CC) $(COPTS) -fo=$@ $< 74 | $(OBJDIR)/makegfx.obj : $(SRCDIR)/makegfx.c 75 | $(CC) $(COPTS) -fo=$@ $< 76 | 77 | # CGALIB Wide Font Variant 78 | $(LIBCGA)/cga-ml.lib : & 79 | $(OBJDIR)/screen.obj & 80 | $(OBJDIR)/bitmap.obj & 81 | $(OBJDIR)/font.obj 82 | $(LIB) $(LIBOPTS) $@ & 83 | +-$(OBJDIR)/screen.obj & 84 | +-$(OBJDIR)/bitmap.obj & 85 | +-$(OBJDIR)/font.obj 86 | $(OBJDIR)/screen.obj : $(SRCDIR)/screen.c 87 | $(CC) $(COPTS) -fo=$@ $< 88 | $(OBJDIR)/bitmap.obj : $(SRCDIR)/bitmap.c 89 | $(CC) $(COPTS) -fo=$@ $< 90 | $(OBJDIR)/font.obj : $(SRCDIR)/font.c 91 | $(CC) $(COPTS) -fo=$@ $< 92 | 93 | # Clean the repo 94 | CLEAN : 95 | $(RM) $(TGTDIR)/ossuary.exe 96 | $(RM) $(TGTDIR)/OSSUARY.GFX 97 | $(RM) $(TGTDIR)/ossuary.txt 98 | $(RM) $(LIBCGA)/cga-ml.lib 99 | $(RM) $(BINDIR)/makegfx.exe 100 | -------------------------------------------------------------------------------- /obj/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /ossuary/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /pic/ossuary.pic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyningstan/ossuary/3a274a8cec4c3f32ecb20f5e1acdc77f828bf1ed/pic/ossuary.pic -------------------------------------------------------------------------------- /src/bitmap.c: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Bitmap Module. 4 | * 5 | * Definitions for the bitmap functions. Also includes the bitmap 6 | * structure for internal use only. 7 | * 8 | * Copyright (C) Damian Walker 2020. 9 | * Created 30-Jun-2020. 10 | */ 11 | 12 | /* default CGALIB macro for access to internal structures */ 13 | #define __CGALIB__ 14 | 15 | /* included headers */ 16 | #include 17 | #include 18 | #include 19 | #include "cgalib.h" 20 | 21 | /*---------------------------------------------------------------------- 22 | * Public Level Functions. 23 | */ 24 | 25 | /** 26 | * Create a bitmap. 27 | * @param width is the width of the bitmap. 28 | * @param height is the height of the bitmap. 29 | * @returns a new Bitmap. 30 | */ 31 | Bitmap *bit_create (int width, int height) 32 | { 33 | /* local variables */ 34 | Bitmap *bitmap; 35 | 36 | /* reserve memory */ 37 | if (! (bitmap = malloc (sizeof (Bitmap)))) 38 | return NULL; 39 | if (! (bitmap->pixels = malloc (width / 4 * height))) { 40 | free (bitmap); 41 | return NULL; 42 | } 43 | 44 | /* initialise the data */ 45 | bitmap->width = width; 46 | bitmap->height = height; 47 | bitmap->ink = 3; 48 | bitmap->paper = 0; 49 | bitmap->font = NULL; 50 | 51 | /* return the bitmap */ 52 | return bitmap; 53 | } 54 | 55 | /** 56 | * Create a bitmap by copying another. 57 | * @param src is the bitmap to copy. 58 | * @returns a new Bitmap. 59 | */ 60 | Bitmap *bit_copy (Bitmap *src) 61 | { 62 | /* local variables */ 63 | Bitmap *dst; 64 | 65 | /* reserve memory */ 66 | if (! (dst = malloc (sizeof (Bitmap)))) 67 | return NULL; 68 | if (! (dst->pixels = malloc (src->width / 4 * src->height))) { 69 | free (dst); 70 | return NULL; 71 | } 72 | 73 | /* initialise the data */ 74 | dst->width = src->width; 75 | dst->height = src->height; 76 | dst->ink = src->ink; 77 | dst->paper = src->paper; 78 | dst->font = src->font; 79 | memcpy (dst->pixels, src->pixels, src->width / 4 * src->height); 80 | 81 | /* return the bitmap */ 82 | return dst; 83 | 84 | } 85 | 86 | /** 87 | * Read a bitmap from an already-open file. 88 | * @param input is the input file handle. 89 | * @returns a new Bitmap. 90 | */ 91 | Bitmap *bit_read (FILE *input) 92 | { 93 | /* local variables */ 94 | Bitmap *bitmap; /* the bitmap to return */ 95 | int w; /* the width read from a file */ 96 | int h; /* the height read from a file */ 97 | 98 | /* attempt to read the width and height */ 99 | if (! fread (&w, 2, 1, input)) 100 | return NULL; 101 | if (! fread (&h, 2, 1, input)) 102 | return NULL; 103 | 104 | /* reserve memory for bitmap and its pixels */ 105 | if (! (bitmap = malloc (sizeof (Bitmap)))) 106 | return NULL; 107 | if (! (bitmap->pixels = malloc (w / 4 * h))) { 108 | free (bitmap); 109 | return NULL; 110 | } 111 | 112 | /* attempt to read the pixels */ 113 | if (! fread (bitmap->pixels, w / 4 * h, 1, input)) { 114 | free (bitmap->pixels); 115 | free (bitmap); 116 | return NULL; 117 | } 118 | 119 | /* set the rest of the variables in the bitmap */ 120 | bitmap->width = w; 121 | bitmap->height = h; 122 | bitmap->ink = 3; 123 | bitmap->paper = 0; 124 | bitmap->font = NULL; 125 | 126 | /* return the bitmap */ 127 | return bitmap; 128 | } 129 | 130 | /** 131 | * Write a bitmap to an already-open file. 132 | * @param bitmap is the bitmap to write. 133 | * @param output is the file handle to write to. 134 | */ 135 | void bit_write (Bitmap *bitmap, FILE *output) 136 | { 137 | if (! fwrite (&bitmap->width, 2, 1, output)) 138 | return; 139 | if (! fwrite (&bitmap->height, 2, 1, output)) 140 | return; 141 | if (! fwrite (bitmap->pixels, bitmap->width / 4 * bitmap->height, 1, 142 | output)) 143 | return; 144 | } 145 | 146 | /** 147 | * Put one bitmap onto another, with clipping. 148 | * @param dst is the destination bitmap. 149 | * @param src is the source bitmap. 150 | * @param x is the y coordinate on the destination bitmap. 151 | * @param y is the x coordinate on the destination bitmap. 152 | * @param draw is the drawing mode to use. 153 | */ 154 | void bit_put (Bitmap *dst, Bitmap *src, int x, int y, DrawMode draw) 155 | { 156 | /* local variables */ 157 | char *d; /* address to copy data to */ 158 | char *s; /* address to copy data from */ 159 | int r; /* row counter */ 160 | int b; /* byte counter */ 161 | 162 | /* copy the pixels */ 163 | for (r = 0; r < src->height; ++r) 164 | 165 | /* DRAW_PSET can be copied by a quicker method */ 166 | if (draw == DRAW_PSET) { 167 | d = dst->pixels + x / 4 + (y + r) * (dst->width / 4); 168 | s = src->pixels + src->width / 4 * r; 169 | _fmemcpy (d, s, src->width / 4); 170 | } 171 | 172 | /* the other draw operations need doing byte by byte */ 173 | else 174 | for (b = 0; b < src->width / 4; ++b) { 175 | d = dst->pixels + b + x / 4 176 | + (y + r) * (dst->width / 4); 177 | s = b + src->pixels + src->width / 4 * r; 178 | switch (draw) { 179 | case DRAW_PRESET: 180 | *d = ~*s; 181 | break; 182 | case DRAW_AND: 183 | *d &= *s; 184 | break; 185 | case DRAW_OR: 186 | *d |= *s; 187 | break; 188 | case DRAW_XOR: 189 | *d ^= *s; 190 | break; 191 | } 192 | } 193 | } 194 | 195 | /** 196 | * Get one bitmap from another. 197 | * @param src is the source bitmap. 198 | * @param dst is the destination bitmap. 199 | * @param x is the x coordinate on the source bitmap. 200 | * @param y is the y coordinate on the source bitmap. 201 | */ 202 | void bit_get (Bitmap *src, Bitmap *dst, int x, int y) 203 | { 204 | /* local variables */ 205 | char *s; /* address to copy data from */ 206 | char *d; /* address to copy data to */ 207 | int r; /* row counter */ 208 | 209 | /* copy the pixels */ 210 | for (r = 0; r < dst->height; ++r) { 211 | s = src->pixels + x / 4 + (y + r) * (src->width / 4); 212 | d = dst->pixels + dst->width / 4 * r; 213 | _fmemcpy (d, s, dst->width / 4); 214 | } 215 | } 216 | 217 | /** 218 | * Draw a box onto a Bitmap, filled in the current ink colour. 219 | * @param bitmap is the destination bitmap. 220 | * @param x is the x coordinate of the top left of the box. 221 | * @param y is the y coordinate of the top left of the box. 222 | * @param width is the width of the box. 223 | * @param height is the height of the box. 224 | * The draw mode is always DRAW_PUT. For anything more sophisticated, 225 | * the scr_put() function should be used. 226 | */ 227 | void bit_box (Bitmap *bitmap, int x, int y, int width, int height) 228 | { 229 | /* local variables */ 230 | char v; /* value to write to the screen */ 231 | int r; /* row counter */ 232 | char *d; /* address to write to */ 233 | 234 | /* determine the byte value that will fill the box */ 235 | v = bitmap->ink * 0x55; 236 | 237 | /* fill each individual row */ 238 | for (r = 0; r < height; ++r) { 239 | d = bitmap->pixels + x / 4 + (y + r) * (bitmap->width / 4); 240 | _fmemset (d, v, width / 4); 241 | } 242 | } 243 | 244 | /** 245 | * Print some text onto a bitmap in the current ink colour. 246 | * @param bitmap is the destination bitmap. 247 | * @param x is the x coordinate where the text should appear. 248 | * @param y is the y coordinate where the text should appear. 249 | * @param message is the message to print. 250 | * The text is printed in a box of the paper colour. 251 | */ 252 | void bit_print (Bitmap *bitmap, int x, int y, char *message) 253 | { 254 | /* local variables */ 255 | int b; /* character pointer */ 256 | int r; /* row of character */ 257 | int v; /* value of byte in character */ 258 | int *d; /* pointer to destination byte on screen */ 259 | 260 | /* only try to print if a font is selected */ 261 | if (! bitmap->font) return; 262 | 263 | /* print each character */ 264 | for (b = 0; message[b]; ++b) 265 | for (r = 0; r < 8; ++r) { 266 | d = (int *) (bitmap->pixels + 2 * b + x / 4 + 267 | (y + r) * (bitmap->width / 4)); 268 | v = bitmap->font->pixels[2 * r + 16 * (message[b] - 269 | bitmap->font->first)] + 0x100 * bitmap->font->pixels[1 + 270 | 2 * r + 16 * (message[b] - bitmap->font->first)]; 271 | if (bitmap->ink != 3 || bitmap->paper != 0) 272 | v = (v & 0x5555 * bitmap->ink) 273 | | ((0xffff ^ v) & 0x5555 * bitmap->paper); 274 | *d = v; 275 | } 276 | } 277 | 278 | /** 279 | * Set the ink colour for scr_box and scr_print operations. 280 | * @param bitmap is the bitmap to set the colour for. 281 | * @param ink is the colour to use, 0..3. 282 | */ 283 | void bit_ink (Bitmap *bitmap, int ink) 284 | { 285 | bitmap->ink = ink; 286 | } 287 | 288 | /** 289 | * Set the paper colour for scr_print operations. 290 | * @param bitmap is the bitmap to set the colour for. 291 | * @param paper is the colour to use, 0..3. 292 | */ 293 | void bit_paper (Bitmap *bitmap, int paper) 294 | { 295 | bitmap->paper = paper; 296 | } 297 | 298 | /** 299 | * Set the font for scr_print operations. 300 | * @param bitmap is the bitmap to set the font for. 301 | * @param font is the font to use. 302 | */ 303 | void bit_font (Bitmap *bitmap, Font *font) 304 | { 305 | bitmap->font = font; 306 | } 307 | 308 | /** 309 | * Destroy a bitmap. 310 | * @param bitmap is the bitmap to destroy. 311 | */ 312 | void bit_destroy (Bitmap *bitmap) 313 | { 314 | if (bitmap) { 315 | if (bitmap->pixels) 316 | free (bitmap->pixels); 317 | free (bitmap); 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /src/display.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Screen handling module. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | /* compiler includes */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | /* project includes */ 21 | #include "cgalib.h" 22 | #include "display.h" 23 | 24 | /*---------------------------------------------------------------------- 25 | * File level variables. 26 | */ 27 | 28 | /** @var screen is the CGALIB screen structure */ 29 | static Screen *screen; 30 | 31 | /** @var mapimg is the bitmap that holds the drawn map */ 32 | static Bitmap *mapimg = NULL; 33 | 34 | /** @var mapwin is the bitmap that holds the visible map section */ 35 | static Bitmap *mapwin = NULL; 36 | 37 | /** @var txtwin is the bitmap that holds text screens */ 38 | static Bitmap *txtwin = NULL; 39 | 40 | /** @var logo is the Cyningstan logo briefly displayed on the screen */ 41 | static Bitmap *logo; 42 | 43 | /** @var bitmaps is the collection of bitmaps used in the game. */ 44 | static Bitmap *bitmaps[30]; 45 | 46 | /** @var font is the font used in the game */ 47 | static Font *font; 48 | 49 | /** @var item_bitmaps links item numbers to the appropriate bitmap */ 50 | static int item_bitmaps[16] = { 51 | 22, 12, 13, 10, 11, 14, 15, 16, 17, 18, 21, 20, 19, 22, 22, 23 52 | }; 53 | 54 | /** @var last_message is the last message printed. */ 55 | static char last_message[17]; 56 | 57 | /*---------------------------------------------------------------------- 58 | * Public Level Routines. 59 | */ 60 | 61 | /** 62 | * Initialise the screen. 63 | */ 64 | int init_screen (int mono, int palette) 65 | { 66 | /* initialise the screen using CGALIB */ 67 | screen = scr_create (mono ? 6 : 4); 68 | if (! palette) 69 | scr_palette (screen, 2, 14); 70 | scr_ink (screen, 2); 71 | scr_box (screen, 0, 0, 320, 200); 72 | 73 | /* return success */ 74 | return 1; 75 | } 76 | 77 | /** 78 | * Clean up the display. 79 | */ 80 | void clean_up_display (void) 81 | { 82 | scr_destroy (screen); 83 | } 84 | 85 | /** 86 | * Load the game graphics. 87 | */ 88 | int load_graphics (void) 89 | { 90 | /* local variables */ 91 | FILE *input; /* input file handle */ 92 | int count; /* graphics counter */ 93 | char header[8]; /* header buffer */ 94 | 95 | /* open the file and read and check the header */ 96 | if (! (input = fopen ("ossuary.gfx", "rb"))) return 0; 97 | if (! (fread (header, 8, 1, input))) return 0; 98 | if (header[7] != '\0') return 0; 99 | if (strcmp (header, "OSS100D")) return 0; 100 | 101 | /* load and display the logo */ 102 | if (! (logo = bit_read (input))) 103 | return 0; 104 | scr_put (screen, logo, 96, 92, DRAW_PSET); 105 | bit_destroy (logo); 106 | 107 | /* load each of the graphic images */ 108 | for (count = 0; count < 30; ++count) 109 | if (! (bitmaps[count] = bit_read (input))) 110 | return 0; 111 | 112 | /* load the font */ 113 | if (! (font = fnt_read (input))) 114 | return 0; 115 | scr_font (screen, font); 116 | 117 | /* create the map bitmaps */ 118 | if (! (mapimg = bit_create (256, 256))) 119 | return 0; 120 | if (! (mapwin = bit_create (144, 144))) 121 | return 0; 122 | if (! (txtwin = bit_create (144, 144))) 123 | return 0; 124 | 125 | /* initialise the text window */ 126 | bit_ink (txtwin, 2); 127 | bit_box (txtwin, 0, 0, 144, 144); 128 | bit_font (txtwin, font); 129 | 130 | /* put the image on the screen and return success */ 131 | sleep (3); 132 | scr_put (screen, bitmaps[0], 0, 0, DRAW_PSET); 133 | return 1; 134 | } 135 | 136 | /** 137 | * Display the updates to the text window. 138 | */ 139 | void display_text (void) 140 | { 141 | scr_put (screen, txtwin, 88, 12, DRAW_PSET); 142 | } 143 | 144 | /** 145 | * Display a number in the gold statistic box. 146 | * @param gold is the amount of gold. 147 | */ 148 | void display_gold (int gold) 149 | { 150 | char gold_string[5]; 151 | sprintf (gold_string, "%04d", gold); 152 | scr_paper (screen, 2); 153 | scr_ink (screen, 3); 154 | scr_print (screen, 40, 84, gold_string); 155 | } 156 | 157 | /** 158 | * Display one of the three hero stats. 159 | * @param stat_no is the stat number, 0..2. 160 | * @param stat_val is the value of the stat. 161 | * @param stat_mod is the modifier. 162 | */ 163 | void display_stat (int stat_no, int stat_val, int stat_mod) 164 | { 165 | /* local variables */ 166 | char val_string[3]; 167 | char mod_string[3]; 168 | 169 | /* build the strings */ 170 | sprintf (val_string, "%02d", stat_val); 171 | sprintf (mod_string, "+%c", '0' + stat_mod); 172 | 173 | /* print the value */ 174 | scr_paper (screen, 2); 175 | scr_ink (screen, 3); 176 | scr_print (screen, 56, 12 + 16 * stat_no, val_string); 177 | 178 | /* print the modifier */ 179 | scr_ink (screen, 1); 180 | scr_print (screen, 56, 20 + 16 * stat_no, mod_string); 181 | } 182 | 183 | /** 184 | * Display the hero's health. 185 | * @param health_val is the current health value. 186 | * @param health_max is the maximum health value. 187 | */ 188 | void display_health (int health_val, int health_max) 189 | { 190 | /* local variables */ 191 | char val_string[3]; 192 | char max_string[3]; 193 | unsigned long int far *overline; 194 | 195 | /* build the strings */ 196 | sprintf (val_string, "%02d", health_val); 197 | sprintf (max_string, "%02d", health_max); 198 | 199 | /* print the value */ 200 | scr_paper (screen, 2); 201 | scr_ink (screen, health_val < 10 ? 0 : 3); 202 | scr_print (screen, 56, 60, val_string); 203 | 204 | /* print the max value */ 205 | scr_ink (screen, 1); 206 | scr_print (screen, 56, 68, max_string); 207 | 208 | /* superimpose a line over the max value */ 209 | overline = (unsigned long int far *) 0xb8000aae; 210 | *overline = 0x56555595; 211 | 212 | } 213 | 214 | /** 215 | * Display an inventory slot. 216 | * @param slot is the slot number. 217 | * @param item is the item number. 218 | */ 219 | void display_inventory (int slot, int item) 220 | { 221 | /* local variables */ 222 | int x, y; 223 | int b; 224 | 225 | /* ascertain screen position and bitmap number */ 226 | x = 248 + 16 * (slot % 2); 227 | y = 12 + 16 * (int) (slot / 2) + 8 * (slot > 1); 228 | b = item_bitmaps[item]; 229 | 230 | /* put the bitmap on the screen */ 231 | scr_put (screen, bitmaps[b], x, y, DRAW_PSET); 232 | } 233 | 234 | /** 235 | * Highlight an inventory slot with the cursor. 236 | * @param slot is the slot number. 237 | */ 238 | void highlight_inventory (int slot) 239 | { 240 | /* local variables */ 241 | int x, y; 242 | 243 | /* ascertain screen position */ 244 | x = 248 + 16 * (slot % 2); 245 | y = 12 + 16 * (int) (slot / 2) + 8 * (slot > 1); 246 | 247 | /* show the cursor in the right position */ 248 | scr_put (screen, bitmaps[28], x, y, DRAW_AND); 249 | } 250 | 251 | /** 252 | * Display a prompt in the bottom text area 253 | * @param message is the message to print 254 | */ 255 | void display_message (char *message) 256 | { 257 | /* if a message was just printed, delay */ 258 | if (*last_message) { 259 | scr_paper (screen, 1); 260 | scr_ink (screen, 2); 261 | scr_print (screen, 96, 156, last_message); 262 | sleep (1); 263 | } 264 | 265 | /* print the text */ 266 | scr_paper (screen, 1); 267 | scr_ink (screen, 0); 268 | scr_print (screen, 96, 156, message); 269 | 270 | /* remember the message */ 271 | strcpy (last_message, message); 272 | } 273 | 274 | /* 275 | * Blank out the previous message. 276 | */ 277 | void blank_message (void) 278 | { 279 | scr_ink (screen, 1); 280 | scr_box (screen, 96, 156, 128, 8); 281 | *last_message = 0; 282 | } 283 | 284 | /** 285 | * Display some text in the top text area. 286 | * @param message is the message to print 287 | */ 288 | void display_heading (char *message) 289 | { 290 | /* print the text */ 291 | scr_paper (screen, 1); 292 | scr_ink (screen, 0); 293 | scr_print (screen, 128, 4, message); 294 | } 295 | 296 | /** 297 | * Alter a tile on the drawn map 298 | * @param x is the X location to alter. 299 | * @param y is the Y location to alter. 300 | * @param value is the map square value. 301 | */ 302 | void update_map_tile (int x, int y, int value) 303 | { 304 | /* local variables */ 305 | int bm_index; /* which bitmap to show */ 306 | 307 | /* work out the tile to display */ 308 | if ((value & 0xf0) == 0x20) /* hero */ 309 | bm_index = 1; 310 | else if (value < 4) /* wall */ 311 | bm_index = 24 + value; 312 | else if ((value & 0xf0) == 0x10) /* floor, item, stairs */ 313 | bm_index = item_bitmaps[value & 0xf]; 314 | else if (value & 0x80) /* enemy */ 315 | bm_index = (value & 0x70) / 0x10 + 2; 316 | else if (value == 0x30) /* necromancer */ 317 | bm_index = 29; 318 | else /* whoops! */ 319 | bm_index = 22; 320 | 321 | /* copy the bitmap */ 322 | bit_put (mapimg, bitmaps[bm_index], 16 * x, 16 * y, DRAW_PSET); 323 | } 324 | 325 | /** 326 | * Build and display the visible portion of the game map. 327 | * @param map is the whole map. 328 | * @param hero_x is the hero's X location. 329 | * @param hero_y is the hero's Y locaation. 330 | */ 331 | void display_map (int hero_x, int hero_y) 332 | { 333 | /* local variables */ 334 | int top, /* map y coordinate at the top of the window */ 335 | left; /* map x coordinate at the left of the window */ 336 | 337 | /* work out the top left of the map */ 338 | if (hero_x < 4) left = 0; 339 | else if (hero_x < 11) left = hero_x - 4; 340 | else left = 7; 341 | if (hero_y < 4) top = 0; 342 | else if (hero_y < 11) top = hero_y - 4; 343 | else top = 7; 344 | 345 | /* put the map on the screen */ 346 | bit_get (mapimg, mapwin, 16 * left, 16 * top); 347 | scr_put (screen, mapwin, 88, 12, DRAW_PSET); 348 | } 349 | 350 | /** 351 | * Display a blank square in the map area. 352 | */ 353 | void blank_map (void) 354 | { 355 | scr_ink (screen, 2); 356 | scr_box (screen, 88, 12, 144, 144); 357 | } 358 | 359 | /** 360 | * Get a keypress, adding 0x8000 for extended codes, and converting 361 | * upper case letters to lower case. 362 | * @returns the keypress 363 | * Keys are as follows: 364 | * SPC Enter the menu. 365 | * Esc Leave the game. 366 | * I Inventory. 367 | * Q Quaff a potion. 368 | * E Eat an apple. 369 | * P Pick up item. 370 | */ 371 | int get_keypress (void) 372 | { 373 | /* local variables */ 374 | int key; 375 | 376 | /* clear the keyboard buffer */ 377 | while (kbhit ()) getch (); 378 | 379 | /* get the key */ 380 | key = getch (); 381 | if (key == 0) 382 | key = getch () + 0x8000; 383 | if (key >= 'A' && key <= 'Z') 384 | key += 32; 385 | 386 | /* once a key is pressed, we don't need to delay last message */ 387 | *last_message = 0; 388 | 389 | /* return the key */ 390 | return key; 391 | } 392 | 393 | /** 394 | * Display a game over message and wait for a key. 395 | * @param line_1 is the first line of the message. 396 | * @param line_2 is the second line of the message. 397 | * The lines are assumed to be exactly 8 characters long. 398 | */ 399 | void display_game_over (char *line_1, char *line_2) 400 | { 401 | display_message (" ESC TO RESTART "); 402 | scr_ink (screen, 0); 403 | scr_paper (screen, 2); 404 | scr_print (screen, 128, 76, line_1); 405 | scr_print (screen, 128, 84, line_2); 406 | while (getch () != 27); 407 | blank_message (); 408 | } 409 | 410 | /** 411 | * Print a debug message at the bottom of the screen. 412 | * @param message is the message. 413 | */ 414 | void debug_message (char *message) 415 | { 416 | char buffer[41], 417 | *ch; 418 | sprintf (buffer, "%-40s", message); 419 | for (ch = buffer; *ch; ++ch) 420 | *ch = toupper (*ch); 421 | scr_ink (screen, 0); 422 | scr_paper (screen, 2); 423 | scr_print (screen, 0, 192, buffer); 424 | if (! getch ()) getch (); 425 | scr_ink (screen, 2); 426 | scr_box (screen, 0, 192, 320, 8); 427 | } 428 | 429 | /** 430 | * Display a row of the high score table. 431 | * @param row is the row number. 432 | * @param name is the name. 433 | * @param gold is the gold. 434 | */ 435 | void display_score (int row, char *name, int gold, int highlight) 436 | { 437 | /* local variables */ 438 | char text[19]; /* the text of this row */ 439 | 440 | /* prepare the text and print it */ 441 | sprintf (text, " %-10s %04d ", name, gold); 442 | bit_paper (txtwin, 2); 443 | bit_ink (txtwin, highlight ? 0 : 3); 444 | bit_print (txtwin, 0, 8 * row, text); 445 | } 446 | 447 | /** 448 | * Display the game keys. 449 | */ 450 | void display_keys (void) 451 | { 452 | /* display heading */ 453 | display_heading (" KEYS "); 454 | display_message ("ESC BACK TO GAME"); 455 | 456 | /* display subheadings */ 457 | bit_paper (txtwin, 2); 458 | bit_ink (txtwin, 3); 459 | bit_print (txtwin, 0, 0, "WHILE MOVING HERO "); 460 | bit_print (txtwin, 0, 88, "WHILE IN INVENTORY"); 461 | 462 | /* display the keys */ 463 | bit_ink (txtwin, 0); 464 | bit_print (txtwin, 0, 8, ". "); 465 | bit_print (txtwin, 0, 16, "I "); 466 | bit_print (txtwin, 0, 24, "T "); 467 | bit_print (txtwin, 0, 32, "S "); 468 | bit_print (txtwin, 0, 40, "E "); 469 | bit_print (txtwin, 0, 48, "Q "); 470 | bit_print (txtwin, 0, 56, "N "); 471 | bit_print (txtwin, 0, 64, "X "); 472 | bit_print (txtwin, 0, 96, "W "); 473 | bit_print (txtwin, 0, 104, "P "); 474 | bit_print (txtwin, 0, 112, "C "); 475 | bit_print (txtwin, 0, 120, "D "); 476 | 477 | /* display descriptions */ 478 | bit_ink (txtwin, 1); 479 | bit_print (txtwin, 16, 8, "WAIT A MOMENT..."); 480 | bit_print (txtwin, 16, 16, "VIEW INVENTORY "); 481 | bit_print (txtwin, 16, 24, "PICK UP ITEM "); 482 | bit_print (txtwin, 16, 32, "DESCEND STAIRS "); 483 | bit_print (txtwin, 16, 40, "EAT A NICE APPLE"); 484 | bit_print (txtwin, 16, 48, "QUAFF A POTION "); 485 | bit_print (txtwin, 16, 56, "START A NEW GAME"); 486 | bit_print (txtwin, 16, 64, "EXIT TO DOS "); 487 | bit_print (txtwin, 0, 72, " ARROWS MOVE HERO"); 488 | bit_print (txtwin, 0, 80, " SPACE FOR MENU "); 489 | bit_print (txtwin, 16, 96, "WIELD AN ITEM "); 490 | bit_print (txtwin, 16, 104, "PUT AN ITEM AWAY"); 491 | bit_print (txtwin, 16, 112, "CONSUME AN ITEM "); 492 | bit_print (txtwin, 16, 120, "DISCARD AN ITEM "); 493 | bit_print (txtwin, 0, 128, " ARROWS SELECT "); 494 | bit_print (txtwin, 0, 136, " SPACE FOR MENU "); 495 | 496 | /* wait for the ESC key */ 497 | display_text (); 498 | while (getch () != 27); 499 | blank_message (); 500 | } 501 | 502 | /** 503 | * Noise for a hit in combat. 504 | */ 505 | void hit_noise (void) 506 | { 507 | /* local variables */ 508 | struct timeb start, /* start time for noise */ 509 | now; /* current time */ 510 | 511 | /* make the noise */ 512 | ftime (&start); 513 | do { 514 | sound (128 + rand () % 64); 515 | ftime (&now); 516 | } while (now.millitm == start.millitm); 517 | nosound (); 518 | } 519 | 520 | /** 521 | * Noise for a kill in combat. 522 | */ 523 | void kill_noise (void) 524 | { 525 | /* local variables */ 526 | struct timeb start, /* start time for noise */ 527 | now; /* current time */ 528 | int pitch; 529 | 530 | /* make the noise */ 531 | pitch = 128 + rand () % 64; 532 | ftime (&start); 533 | do { 534 | sound (pitch); 535 | pitch -= (rand () % pitch) / 32; 536 | ftime (&now); 537 | } while (now.millitm == start.millitm); 538 | nosound (); 539 | } 540 | 541 | /** 542 | * Noise for some inventory action. 543 | */ 544 | void inventory_noise (void) 545 | { 546 | sound (256 + rand () % 128); 547 | delay (1); 548 | nosound (); 549 | } 550 | 551 | /** 552 | * Noise for the clink of gold. 553 | */ 554 | void gold_noise (void) 555 | { 556 | /* local variables */ 557 | struct timeb start, /* start time for noise */ 558 | now; /* current time */ 559 | 560 | /* make the noise */ 561 | ftime (&start); 562 | do { 563 | sound (768 + rand () % 256); 564 | ftime (&now); 565 | } while (now.millitm == start.millitm); 566 | nosound (); 567 | } 568 | 569 | /** 570 | * Noise for descending the stairs. 571 | */ 572 | void stairs_noise (void) 573 | { 574 | /* local variables */ 575 | int pitch, /* descending pitch value */ 576 | count; /* count the number of steps */ 577 | 578 | /* make the noise */ 579 | pitch = 128 + rand () % 64; 580 | for (count = 0; count < 4; ++count) { 581 | sound (pitch); 582 | delay (1); 583 | nosound (); 584 | delay (250); 585 | pitch -= (rand () % pitch) / 4; 586 | } 587 | } 588 | -------------------------------------------------------------------------------- /src/errors.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Error handling module. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /*---------------------------------------------------------------------- 15 | * Public Level Functions. 16 | */ 17 | 18 | /** 19 | * Exit the program on an error condition, showing the error. 20 | * @param exit_code is the code that determines what the error was. 21 | */ 22 | void exit_game (int exit_code) 23 | { 24 | /* @var message is a pointer to the output message */ 25 | char *message; 26 | 27 | /* determine what message to print */ 28 | switch (exit_code) { 29 | case 0: 30 | message = "Goodbye!"; 31 | break; 32 | case 1: 33 | message = "Cannot initialise screen!"; 34 | break; 35 | case 2: 36 | message = "Cannot load font!"; 37 | break; 38 | case 3: 39 | message = "Cannot load graphics!"; 40 | break; 41 | case 4: 42 | message = "Invalid option!"; 43 | break; 44 | case 5: 45 | message = "This beta has expired! Contact Cyningstan."; 46 | break; 47 | default: 48 | message = "Unknown error!"; 49 | } 50 | 51 | /* make sure we're in text mode and print the message */ 52 | _setvideomode (_DEFAULTMODE); 53 | puts (message); 54 | exit (exit_code); 55 | } 56 | -------------------------------------------------------------------------------- /src/font.c: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Font Module. 4 | * 5 | * Copyright (C) Damian Walker 2020. 6 | * Created 29-Jun-2020. 7 | */ 8 | 9 | /* define CGALIB macro for access to internal structures */ 10 | #define __CGALIB__ 11 | 12 | /* included headers */ 13 | #include 14 | #include 15 | #include 16 | #include "cgalib.h" 17 | 18 | /*---------------------------------------------------------------------- 19 | * Public Level Functions. 20 | */ 21 | 22 | /** 23 | * Create a new font. 24 | * @param first is the first character in the font. 25 | * @param last is the last character in the font. 26 | * @returns the new font. 27 | */ 28 | Font *fnt_create (int first, int last) 29 | { 30 | /* local variables */ 31 | Font *font; /* the font to return */ 32 | 33 | /* attempt to allocate memory */ 34 | if (! (font = malloc (sizeof (Font)))) 35 | return NULL; 36 | if (! (font->pixels = malloc (16 * (last - first + 1)))) { 37 | free (font); 38 | return NULL; 39 | } 40 | 41 | /* set the font information */ 42 | font->first = first; 43 | font->last = last; 44 | 45 | /* return the font */ 46 | return font; 47 | } 48 | 49 | /** 50 | * Copy a font. 51 | * @param font is the font to copy. 52 | * @returns a new font copied from the old. 53 | */ 54 | Font *fnt_copy (Font *src) 55 | { 56 | /* local variables */ 57 | Font *dst; /* destination font */ 58 | 59 | /* attempt to reserve memory */ 60 | if (! (dst = malloc (sizeof (Font)))) 61 | return NULL; 62 | if (! (dst->pixels = malloc (16 * (src->last - src->first + 1)))) { 63 | free (dst); 64 | return NULL; 65 | } 66 | 67 | /* set the font information */ 68 | dst->first = src->first; 69 | dst->last = src->last; 70 | memcpy (dst->pixels, src->pixels, 16 * (src->last - src->first + 1)); 71 | 72 | /* return the font */ 73 | return dst; 74 | } 75 | 76 | /** 77 | * Read a font from an already open file. 78 | * @param input is the input file handle. 79 | * @returns the new font. 80 | */ 81 | Font *fnt_read (FILE *input) 82 | { 83 | /* local variables */ 84 | Font *font; /* the font to return */ 85 | char f; /* first character code read from file */ 86 | char l; /* last character code read from file */ 87 | 88 | /* read first and last character codes */ 89 | if (! fread (&f, 1, 1, input)) 90 | return NULL; 91 | if (! fread (&l, 1, 1, input)) 92 | return NULL; 93 | 94 | /* attempt to allocate memory */ 95 | if (! (font = malloc (sizeof (Font)))) 96 | return NULL; 97 | if (! (font->pixels = malloc (16 * (l - f + 1)))) { 98 | free (font); 99 | return NULL; 100 | } 101 | 102 | /* attempt to read the pixel data */ 103 | if (! fread (font->pixels, 16 * (l - f + 1), 1, input)) { 104 | free (font->pixels); 105 | free (font); 106 | return NULL; 107 | } 108 | 109 | /* set the other font information */ 110 | font->first = f; 111 | font->last = l; 112 | 113 | /* return the font */ 114 | return font; 115 | } 116 | 117 | /** 118 | * Write a font to an already open file. 119 | * @param font is the font to write. 120 | * @param output is the output file handle. 121 | */ 122 | void fnt_write (Font *font, FILE *output) 123 | { 124 | if (! fwrite (&font->first, 1, 1, output)) 125 | return; 126 | if (! fwrite (&font->last, 1, 1, output)) 127 | return; 128 | if (! fwrite (font->pixels, 16 * (font->last - font->first + 1), 1, 129 | output)) 130 | return; 131 | } 132 | 133 | /** 134 | * Put a bitmap into a font character. 135 | * @param dst is the destination font. 136 | * @param src is the source bitmap. 137 | * @param ch is the character to set. 138 | */ 139 | void fnt_put (Font *dst, Bitmap *src, int ch) 140 | { 141 | memcpy (dst->pixels + 16 * (ch - dst->first), src->pixels, 16); 142 | } 143 | 144 | /** 145 | * Get a bitmap from a font character. 146 | * @param src is the source font. 147 | * @param dst is the destination bitmap. 148 | * @param ch is the character to get. 149 | */ 150 | void fnt_get (Font *src, Bitmap *dst, int ch) 151 | { 152 | memcpy (dst->pixels, src->pixels + 16 * (ch - src->first), 16); 153 | } 154 | 155 | /** 156 | * Set the font colours permanently. 157 | * @param font is the font to modify. 158 | * @param ink is the ink colour. 159 | * @param paper is the paper colour. 160 | * This function offers a quicker alternative to colouring text as it is 161 | * printed, and may be used if ALL text is going to be a certain colour. 162 | * It can be used in conjunction with the fnt_copy() function to quickly 163 | * output text in multiple colours (fnt_copy then apply fnt_colours). 164 | * Note that this assumes that the colours are already ink 3, paper 0. 165 | * After changing the font colours, this will no longer be the case 166 | * and further colour changes will have unpredictable results. 167 | */ 168 | void fnt_colours (Font *font, int ink, int paper) 169 | { 170 | /* local variables */ 171 | int ch; /* character count */ 172 | int r; /* byte count */ 173 | int p; /* paper mask */ 174 | int i; /* ink mask */ 175 | int b; /* background of recoloured character */ 176 | int f; /* foreground of recoloured character */ 177 | 178 | /* work out the ink and paper masks */ 179 | i = ink * 0x55; 180 | p = paper * 0x55; 181 | 182 | /* loop through all the characters */ 183 | for (ch = 0; ch < font->last - font->first; ++ch) 184 | for (r = 0; r < 15; ++r) { 185 | f = font->pixels[16 * ch + r] & i; 186 | b = 0xff ^ font->pixels[16 * ch + r] & p; 187 | font->pixels[16 * ch + r] = i | p; 188 | } 189 | } 190 | 191 | /** 192 | * Destroy a font. 193 | * @param font is the font to destroy. 194 | */ 195 | void fnt_destroy (Font *font) 196 | { 197 | if (font) { 198 | if (font->pixels) 199 | free (font->pixels); 200 | free (font); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/fontconv.c: -------------------------------------------------------------------------------- 1 | /* temporary font conversion utility */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "conio.h" 8 | #include "cgalib.h" 9 | 10 | /** 11 | * Main Program 12 | */ 13 | void main (void) 14 | { 15 | Screen *screen; 16 | Bitmap *bitmap; 17 | Font *font; 18 | FILE *fp; 19 | int ch, r, c; 20 | 21 | /* initialise the screen */ 22 | _setvideomode (4); 23 | screen = scr_create (4); 24 | 25 | /* show the font */ 26 | if (! _registerfonts ("ossuary.fon")) { 27 | printf ("Cannot load font.\n"); 28 | exit (0); 29 | } 30 | _setfont ("n1"); 31 | _moveto (0, 0); 32 | _outgtext (" !\"#$%&'()*+,-./"); 33 | _moveto (0, 8); 34 | _outgtext ("0123456789:;<=>?"); 35 | _moveto (0, 16); 36 | _outgtext ("@ABCDEFGHIJKLMNO"); 37 | _moveto (0, 24); 38 | _outgtext ("PQRSTUVWXYZ[\\]^_"); 39 | 40 | getch (); 41 | 42 | /* extract all the characters into a font */ 43 | if (! (font = fnt_create (32, 95))) { 44 | printf ("Cannot create font.\n"); 45 | exit (1); 46 | } 47 | if (! (bitmap = bit_create (8, 8))) { 48 | printf ("Cannot create bitmap.\n"); 49 | exit (1); 50 | } 51 | if (! (fp = fopen ("ossuary.fnt", "wb"))) { 52 | printf ("Cannot create font file ossuary.fnt.\n"); 53 | exit (1); 54 | } 55 | if (! fwrite ("CGA100F", 8, 1, fp)) { 56 | printf ("Cannot write header to font file.\n"); 57 | exit (1); 58 | } 59 | for (ch = 32; ch <= 95; ++ch) { 60 | r = (ch - 32) / 16; 61 | c = (ch - 32) % 16; 62 | scr_get (screen, bitmap, 8 * c, 8 * r); 63 | fnt_put (font, bitmap, ch); 64 | } 65 | fnt_write (font, fp); 66 | fclose (fp); 67 | 68 | /* clean up at the end */ 69 | bit_destroy (bitmap); 70 | fnt_destroy (font); 71 | scr_destroy (screen); 72 | } 73 | -------------------------------------------------------------------------------- /src/game.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Game handling module. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | /* compiler headers */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | /* project headers */ 19 | #include "game.h" 20 | #include "display.h" 21 | 22 | /*---------------------------------------------------------------------- 23 | * Constant definitions. 24 | */ 25 | 26 | /* 3x3 cell map bitmasks */ 27 | #define CELL_EAST 0x01 28 | #define CELL_SOUTH 0x02 29 | #define CELL_WEST 0x04 30 | #define CELL_NORTH 0x08 31 | #define CELL_CHAMBER 0x80 32 | 33 | /* bits in the quick inventory */ 34 | #define QI_WAND 0x01 35 | #define QI_AMULET 0x02 36 | #define QI_WOODEN_SHIELD 0x04 37 | #define QI_IRON_SHIELD 0x08 38 | #define QI_DAGGER 0x10 39 | #define QI_SWORD 0x20 40 | #define QI_AXE 0x40 41 | #define QI_POTION 0x80 42 | 43 | /* composite bit patterns for easy searches in the quick inventory */ 44 | #define QI_ANY_SHIELD 0x0c 45 | #define QI_BIG_WEAPON 0x60 46 | #define QI_ANY_WEAPON 0x70 47 | 48 | /*---------------------------------------------------------------------- 49 | * Type definitions 50 | */ 51 | 52 | /** @enum Behaviour is a list of enemy behaviours */ 53 | typedef enum { 54 | BEHAVIOUR_GUARD, 55 | BEHAVIOUR_WANDER, 56 | BEHAVIOUR_CHASE 57 | } Behaviour; 58 | 59 | /** @enum EnemyType is a list of enemy types */ 60 | typedef enum { 61 | ENEMY_BAT, 62 | ENEMY_VERMIN, 63 | ENEMY_ARACHNID, 64 | ENEMY_SERPENT, 65 | ENEMY_CADAVER, 66 | ENEMY_SKELETON, 67 | ENEMY_SPECTRE, 68 | ENEMY_DAEMON 69 | } EnemyType; 70 | 71 | /** @enum ItemType is a list of item types */ 72 | typedef enum { 73 | ITEM_NONE, 74 | ITEM_PURSE, 75 | ITEM_CASKET, 76 | ITEM_APPLE, 77 | ITEM_POTION, 78 | ITEM_DAGGER, 79 | ITEM_SWORD, 80 | ITEM_AXE, 81 | ITEM_WOODEN_SHIELD, 82 | ITEM_IRON_SHIELD, 83 | ITEM_SCROLL, 84 | ITEM_AMULET, 85 | ITEM_WAND 86 | } ItemType; 87 | 88 | /** @enum Direction is a list of directions of movement */ 89 | typedef enum { 90 | DIR_NONE, 91 | DIR_UP, 92 | DIR_DOWN, 93 | DIR_LEFT, 94 | DIR_RIGHT 95 | } Direction; 96 | 97 | /** @enum MenuOptions is a list of main menu options */ 98 | typedef enum { 99 | MENU_HELP, 100 | MENU_WAIT, 101 | MENU_INVENTORY, 102 | MENU_PICK_UP, 103 | MENU_DESCEND, 104 | MENU_EAT, 105 | MENU_QUAFF, 106 | MENU_NEW_GAME, 107 | MENU_EXIT, 108 | MENU_CANCEL, 109 | MENU_INV_HELP, 110 | MENU_INV_WIELD, 111 | MENU_INV_PUT_AWAY, 112 | MENU_INV_CONSUME, 113 | MENU_INV_DISCARD, 114 | MENU_INV_CLOSE 115 | } MenuOptions; 116 | 117 | /** @struct enemy is an enemy record */ 118 | typedef struct enemy Enemy; 119 | struct enemy { 120 | 121 | /** @var x is the x location of the enemy */ 122 | int x; 123 | 124 | /** @var y is the y location of the enemy */ 125 | int y; 126 | 127 | /** @var type is the type of enemy */ 128 | int type; 129 | 130 | /** @var health is the enemy's health */ 131 | int health; 132 | 133 | /** @var aggression is the aggression level of the enemy */ 134 | int aggression; 135 | 136 | /** @var behaviour indicates what the enemy is doing */ 137 | Behaviour behaviour; 138 | 139 | /** @var dest_x is the X coordinate the monster is heading for */ 140 | int dest_x; 141 | 142 | /** @var dest_y is the Y coordinate the monster is heading for */ 143 | int dest_y; 144 | }; 145 | 146 | /** @struct enemy_stats are the stats of each enemy type */ 147 | typedef struct enemy_stats EnemyStats; 148 | struct enemy_stats { 149 | 150 | /** @var strength is the enemy strength */ 151 | int strength; 152 | 153 | /** @var agility is the enemy agility */ 154 | int agility; 155 | }; 156 | 157 | /*---------------------------------------------------------------------- 158 | * File level variables. 159 | */ 160 | 161 | /** @var name is the player's name */ 162 | static char name[11]; 163 | 164 | /** @var level is the current dungeon level. */ 165 | static int level; 166 | 167 | /** @var gold is the gold that the hero has collected. */ 168 | static int gold; 169 | 170 | /** @var enemy_min is the weakest enemy for the current level. */ 171 | static int enemy_min; 172 | 173 | /** @var enemy_max is the strongest enemy for the current level. */ 174 | static int enemy_max; 175 | 176 | /** @var enemy_anger is the average enemy aggression level. */ 177 | static int enemy_anger; 178 | 179 | /** @var experience is the number of XP points the player has. */ 180 | static int experience = 0; 181 | 182 | /** @var necro_health is the necromancer's hit points. */ 183 | static int necro_health; 184 | 185 | /** @var necro_x is the necromancer's X position */ 186 | static int necro_x; 187 | 188 | /** @var necro_y is the necromancer's Y position */ 189 | static int necro_y; 190 | 191 | /** @var hero_strength is the primary attack stat. */ 192 | static int hero_strength; 193 | 194 | /** @var hero_agility is the primary defence stat. */ 195 | static int hero_agility; 196 | 197 | /** @var hero_intelligence is the magical attack/defence stat. */ 198 | static int hero_intelligence; 199 | 200 | /** @var hero_x is the hero's X position on the map */ 201 | static int hero_x; 202 | 203 | /** @var hero_y is the hero's Y position on the map */ 204 | static int hero_y; 205 | 206 | /** @var hero_health is the hero's hit points. */ 207 | static int hero_health; 208 | 209 | /** @var inventory is the player's inventory */ 210 | static int inventory[12]; 211 | 212 | /** @var inventory_slot is the last inventory slot accessed. */ 213 | static int inventory_slot; 214 | 215 | /** @var strength_mod is the attack modifier */ 216 | static int strength_modifier; 217 | 218 | /** @var agility_mod is the defence modifier */ 219 | static int agility_modifier; 220 | 221 | /** @var intelligence_mod is the intelligence modifier */ 222 | static int intelligence_modifier; 223 | 224 | /** @var map is the map */ 225 | static char map[16][16]; 226 | 227 | /** @var enemies is the array of enemies */ 228 | static Enemy enemies[8]; 229 | 230 | /** @var level_over signifies that the level is over */ 231 | static int level_over; 232 | 233 | /** @var game_over signifies that the user wants to restart */ 234 | static int game_over; 235 | 236 | /** @var game_quit signifies that the user has quit */ 237 | static int game_quit; 238 | 239 | /** @var enemy_stats is an array of stats per enemy type */ 240 | static EnemyStats enemy_stats[8] = { 241 | {2, 6}, 242 | {6, 4}, 243 | {6, 6}, 244 | {8, 6}, 245 | {8, 8}, 246 | {8, 10}, 247 | {10, 10}, 248 | {10, 12} 249 | }; 250 | 251 | /** @var item_message are shown when standing by each item */ 252 | static char item_message[16][17] = { 253 | " FOUND A BUG! ", 254 | "A PURSE OF GOLD ", 255 | "A CASKET OF GOLD", 256 | " A NICE APPLE ", 257 | "A HEALING POTION", 258 | " A SMALL DAGGER ", 259 | " A BROADSWORD ", 260 | " A BATTLE AXE ", 261 | "A WOODEN SHIELD ", 262 | " AN IRON SHIELD ", 263 | " A BANISH SPELL ", 264 | " A MAGIC AMULET ", 265 | " A MAGIC WAND ", 266 | " FOUND A BUG! ", 267 | " FOUND A BUG! ", 268 | "THE STAIRS DOWN " 269 | }; 270 | 271 | /** @var enemy_names are the names of the enemy types */ 272 | static char enemy_names[8][9] = { 273 | "BAT", 274 | "VERMIN", 275 | "ARACHNID", 276 | "SERPENT", 277 | "CADAVER", 278 | "SKELETON", 279 | "SPECTRE", 280 | "DAEMON" 281 | }; 282 | 283 | /** @var menu_option_text is the text to print for main menu options */ 284 | static char menu_option_text[16][17] = { 285 | " SHOW GAME KEYS ", 286 | "WAIT A MOMENT...", 287 | " VIEW INVENTORY ", 288 | " PICK UP ITEM ", 289 | " DESCEND STAIRS ", 290 | "EAT A NICE APPLE", 291 | " QUAFF A POTION ", 292 | " START NEW GAME ", 293 | " EXIT THIS GAME ", 294 | " CANCEL MENU ", 295 | " SHOW GAME KEYS ", 296 | " WIELD ITEM ", 297 | " PUT ITEM AWAY ", 298 | " CONSUME ITEM ", 299 | " DISCARD ITEM ", 300 | "CLOSE INVENTORY " 301 | }; 302 | 303 | /*---------------------------------------------------------------------- 304 | * Service Routines. 305 | */ 306 | 307 | /** 308 | * Roll a number of six-sided dice. 309 | * @param count is the number of dice to roll. 310 | * @returns the total of the dice. 311 | */ 312 | static int dice (int count) 313 | { 314 | int total = 0; 315 | while (count--) 316 | total += 1 + rand() % 6; 317 | return total; 318 | } 319 | 320 | /*---------------------------------------------------------------------- 321 | * Level 4 Routines. 322 | */ 323 | 324 | /** 325 | * Make one of the enemies attack the hero. 326 | * @param enemy_no is the enemy who's attacking the hero. 327 | * @returns 1 if the hero is killed, 0 if not. 328 | */ 329 | static int attack_hero (int enemy_no) 330 | { 331 | /* local variables */ 332 | int attack, /* enemy's attack value */ 333 | defence, /* hero's defence value */ 334 | damage, /* damage caused */ 335 | update; /* 1 if the screen needs updating */ 336 | char message[17]; /* battle round message */ 337 | Enemy *enemy; /* enemy the hero is attacking */ 338 | 339 | /* determine which enemy and make it more aggressive */ 340 | enemy = &enemies[enemy_no]; 341 | 342 | /* determine the enemy's attack value */ 343 | attack = enemy_stats[enemy->type].strength; 344 | 345 | /* determine hero's defence value */ 346 | if (inventory[0] == ITEM_AMULET || inventory[1] == ITEM_AMULET) 347 | defence = hero_intelligence + intelligence_modifier; 348 | else 349 | defence = hero_agility + agility_modifier; 350 | 351 | /* otherwise conduct an ordinary attack */ 352 | damage = (1 + attack + dice (2)) - (defence + dice (2)); 353 | if (damage < 0) 354 | damage = 0; 355 | 356 | /* register the damage */ 357 | hero_health -= damage; 358 | if (hero_health < 0) 359 | hero_health = 0; 360 | update = 0; 361 | 362 | /* process a miss */ 363 | if (! damage) { 364 | sprintf (message, "%-8s MISSES ", enemy_names[enemy->type]); 365 | display_message (message); 366 | } 367 | 368 | /* process a non-fatal hit */ 369 | else if (hero_health) { 370 | sprintf (message, "%-8s HIT YOU", enemy_names[enemy->type]); 371 | display_message (message); 372 | display_health (hero_health, hero_strength + hero_agility 373 | + hero_intelligence); 374 | hit_noise (); 375 | } 376 | 377 | /* process a fatal hit */ 378 | else { 379 | sprintf (message, "%-8s HIT YOU", enemy_names[enemy->type]); 380 | display_message (message); 381 | display_health (hero_health, hero_strength + hero_agility 382 | + hero_intelligence); 383 | kill_noise (); 384 | map[hero_x][hero_y] = (map[hero_x][hero_y] & 0xf) | 0x10; 385 | update_map_tile (hero_x, hero_y, map[hero_x][hero_y]); 386 | update = 1; 387 | game_over = 1; 388 | } 389 | 390 | /* return 1 if screen update required */ 391 | return update; 392 | } 393 | 394 | /** 395 | * Kill an enemy. 396 | * Remove it from the map. 397 | * Process any experience level advancements. 398 | * @param enemy is a pointer to the enemy killed. 399 | * @param xp_award is the xp awarded. 400 | */ 401 | static void kill_enemy (Enemy *enemy, int xp_award) 402 | { 403 | /* local variables */ 404 | int stat_no; /* random player stat to increase */ 405 | 406 | /* remove the enemy from the map */ 407 | map[enemy->x][enemy->y] = (map[enemy->x][enemy->y] & 0xf) | 0x10; 408 | update_map_tile (enemy->x, enemy->y, map[enemy->x][enemy->y]); 409 | if (! xp_award) return; 410 | 411 | /* process advancement */ 412 | experience += xp_award; 413 | while (experience >= 24) { 414 | stat_no = rand () % 3; 415 | if (stat_no == 0 && hero_strength < 12) { 416 | ++hero_strength; 417 | display_stat (0, hero_strength, strength_modifier); 418 | experience = 0; 419 | } else if (stat_no == 1 && hero_agility < 12) { 420 | ++hero_agility; 421 | display_stat (1, hero_agility, agility_modifier); 422 | experience = 0; 423 | } else if (stat_no == 2 && hero_intelligence < 12) { 424 | ++hero_intelligence; 425 | display_stat (2, hero_intelligence, 426 | intelligence_modifier); 427 | experience -= 24; 428 | } 429 | } 430 | if (experience == 0) { 431 | ++hero_health; 432 | display_health (hero_health, hero_strength + hero_agility 433 | + hero_intelligence); 434 | } 435 | } 436 | 437 | /*---------------------------------------------------------------------- 438 | * Level 3 Routines. 439 | */ 440 | 441 | /** 442 | * Attempt to use a banish spell. 443 | * @param enemy_x is the X coordinate of the enemy. 444 | * @param enemy_y is the Y coordinate of the enemy. 445 | * @returns 1 if the screen needs updating. 446 | */ 447 | static int banish_spell (int enemy_x, int enemy_y) 448 | { 449 | /* local variables */ 450 | int roll, /* the roll of two dice */ 451 | update = 0, /* 1 if the screen map needs updating */ 452 | scroll_slot, /* which inventory slot the scroll is in */ 453 | e; /* enemy counter */ 454 | 455 | /* the effect is decided by a roll of 2D6 */ 456 | roll = dice (2); 457 | 458 | /* on 8+, banish the monster */ 459 | if (roll >= 8) { 460 | for (e = 0; e < 8; ++e) 461 | if (enemies[e].x == enemy_x && enemies[e].y == enemy_y) { 462 | enemies[e].health = 0; 463 | kill_enemy (&enemies[e], 0); 464 | } 465 | display_message ("BANISH SUCCEEDED"); 466 | update = 1; 467 | kill_noise (); 468 | } 469 | 470 | /* otherwise on 4+, the spell simply fails */ 471 | else if (roll >= 4) 472 | display_message (" BANISH FAILED "); 473 | 474 | /* finally on a roll of 3-, the spell disappears! */ 475 | else { 476 | scroll_slot = (inventory[1] == ITEM_SCROLL); 477 | inventory[scroll_slot] = 0; 478 | display_inventory (scroll_slot, 0); 479 | display_message ("SCROLL HAS GONE!"); 480 | } 481 | 482 | /* tell the calling process whether the map needs updating */ 483 | return update; 484 | } 485 | 486 | /** 487 | * Recalculate and display modifiers. 488 | */ 489 | static void recalc_modifiers (void) 490 | { 491 | /* local variables */ 492 | int c; /* inventory counter */ 493 | 494 | /* initialise modifiers */ 495 | strength_modifier = agility_modifier = intelligence_modifier = 0; 496 | 497 | /* look at wielded items */ 498 | for (c = 0; c < 2; ++c) 499 | switch (inventory[c]) { 500 | case ITEM_DAGGER: strength_modifier += 2; break; 501 | case ITEM_SWORD: strength_modifier += 4; break; 502 | case ITEM_AXE: strength_modifier += 6; break; 503 | case ITEM_WOODEN_SHIELD: agility_modifier += 2; break; 504 | case ITEM_IRON_SHIELD: agility_modifier += 4; break; 505 | case ITEM_WAND: intelligence_modifier += 2; break; 506 | case ITEM_AMULET: intelligence_modifier += 2; break; 507 | } 508 | 509 | /* display the stats and modifiers */ 510 | display_stat (0, hero_strength, strength_modifier); 511 | display_stat (1, hero_agility, agility_modifier); 512 | display_stat (2, hero_intelligence, intelligence_modifier); 513 | } 514 | 515 | /** 516 | * Attempt to move an enemy. 517 | * @param enemy_no is the enemy number. 518 | * @param x is the X coordinate to move to. 519 | * @param y is the Y coorddinate to move to. 520 | * @returns 1 if successful, 0 if blocked. 521 | */ 522 | static int move_enemy (int enemy_no, int x, int y) 523 | { 524 | /* local variables */ 525 | int moved = 0, /* set to 1 if moved */ 526 | cx, /* enemy's current X position */ 527 | cy, /* enemy's current Y position */ 528 | item; /* item the enemy is carrying or guarding */ 529 | 530 | /* the hero is here - attack! */ 531 | if ((map[x][y] & 0xf0) == 0x20) { 532 | attack_hero (enemy_no); 533 | moved = 1; 534 | } 535 | 536 | /* the square is empty - move there */ 537 | else if ((map[x][y] & 0xf0) == 0x10) { 538 | 539 | /* record enemy's current position in convenience variables */ 540 | cx = enemies[enemy_no].x; 541 | cy = enemies[enemy_no].y; 542 | item = map[cx][cy] & 0xf; 543 | 544 | /* first move the enemy on the map */ 545 | map[x][y] = map[x][y] 546 | & 0x0f 547 | | 0x80 548 | | (enemies[enemy_no].type << 4); 549 | map[cx][cy] = map[cx][cy] & 0x0f | 0x10; 550 | 551 | /* then bring any item with it, if appropriate */ 552 | if ((map[x][y] & 0xf) == 0 553 | && item > 0 554 | && item < 0xf 555 | && (enemies[enemy_no].type == ENEMY_BAT 556 | || (enemies[enemy_no].type >= ENEMY_CADAVER 557 | && enemies[enemy_no].type != ENEMY_SPECTRE))) { 558 | map[x][y] |= item; 559 | map[cx][cy] &= 0xf0; 560 | } 561 | 562 | /* update the map and enemy data */ 563 | update_map_tile (x, y, map[x][y]); 564 | update_map_tile (cx, cy, map[cx][cy]); 565 | enemies[enemy_no].x = x; 566 | enemies[enemy_no].y = y; 567 | moved = 1; 568 | } 569 | 570 | /* tell the calling function if the move was successful */ 571 | return moved; 572 | } 573 | 574 | /*---------------------------------------------------------------------- 575 | * Level 2 Routines. 576 | */ 577 | 578 | /** 579 | * Attack an enemy on a particular square 580 | * @param enemy_x is the X coordinate to attack. 581 | * @param enemy_y is the Y coordinate to attack. 582 | * @returns 1 if the enemy is killed, 0 if not. 583 | */ 584 | static int attack_enemy (int enemy_x, int enemy_y) 585 | { 586 | /* local variables */ 587 | int c, /* enemy counter */ 588 | attack, /* hero's attack value */ 589 | defence, /* enemy's defence value */ 590 | damage, /* damage caused */ 591 | update; /* 1 if the screen needs updating */ 592 | char message[17]; /* battle round message */ 593 | Enemy *enemy; /* enemy the hero is attacking */ 594 | 595 | /* determine which enemy and make it more aggressive */ 596 | enemy = NULL; 597 | for (c = 0; c < 8; ++c) 598 | if (enemies[c].x == enemy_x 599 | && enemies[c].y == enemy_y 600 | && enemies[c].health > 0) 601 | enemy = &enemies[c]; 602 | enemy->aggression += (enemy->aggression < 0xff); 603 | 604 | /* determine hero's attack value */ 605 | if (inventory[0] == ITEM_WAND || inventory[1] == ITEM_WAND) 606 | attack = hero_intelligence + intelligence_modifier; 607 | else if (enemy->type <= ENEMY_SKELETON) 608 | attack = hero_strength + strength_modifier; 609 | else 610 | attack = 0; 611 | 612 | /* use banish spell where appropriate */ 613 | if (enemy->type >= ENEMY_SPECTRE 614 | && (inventory[0] == ITEM_SCROLL 615 | || inventory[1] == ITEM_SCROLL)) { 616 | return banish_spell (enemy_x, enemy_y); 617 | } 618 | 619 | /* otherwise conduct an ordinary attack */ 620 | else if (attack > 0) { 621 | defence = enemy_stats[enemy->type].agility; 622 | damage = (1 + attack + dice (2)) - (defence + dice (2)); 623 | if (damage < 0) 624 | damage = 0; 625 | } 626 | 627 | /* if the enemy can't be attacked, register a miss */ 628 | else 629 | damage = 0; 630 | 631 | /* register the damage */ 632 | enemy->health -= damage; 633 | if (enemy->health < 0) 634 | enemy->health = 0; 635 | update = 0; 636 | 637 | /* process a miss */ 638 | if (! damage) { 639 | sprintf (message, " MISSED %-8s", enemy_names[enemy->type]); 640 | display_message (message); 641 | } 642 | 643 | /* process a non-fatal hit */ 644 | else if (enemy->health) { 645 | sprintf (message, "YOU HIT %-8s", enemy_names[enemy->type]); 646 | display_message (message); 647 | hit_noise (); 648 | } 649 | 650 | /* process a fatal hit */ 651 | else { 652 | kill_enemy (enemy, 1); 653 | sprintf (message, " KILLED %-8s", enemy_names[enemy->type]); 654 | display_message (message); 655 | update = 1; 656 | kill_noise (); 657 | } 658 | 659 | /* return 1 if screen update required */ 660 | return update; 661 | } 662 | 663 | /** 664 | * Attack the necromancer. 665 | * @returns 1 if the enemy is killed, 0 if not. 666 | */ 667 | static int attack_necromancer (void) 668 | { 669 | /* local variables */ 670 | int attack, /* hero's attack value */ 671 | defence, /* enemy's defence value */ 672 | damage, /* damage caused */ 673 | update; /* 1 if the screen needs updating */ 674 | 675 | /* determine hero's attack value */ 676 | if (inventory[0] == ITEM_WAND || inventory[1] == ITEM_WAND) 677 | attack = hero_intelligence + intelligence_modifier; 678 | else 679 | attack = hero_strength + strength_modifier; 680 | 681 | /* conduct the attack */ 682 | defence = 12; 683 | damage = (1 + attack + dice (2)) - (defence + dice (2)); 684 | if (damage < 0) 685 | damage = 0; 686 | 687 | /* register the damage */ 688 | necro_health -= damage; 689 | if (necro_health < 0) 690 | necro_health = 0; 691 | update = 0; 692 | 693 | /* process a miss */ 694 | if (! damage) 695 | display_message (" MISSED SORCEROR"); 696 | 697 | /* process a non-fatal hit */ 698 | else if (necro_health) { 699 | display_message ("YOU HIT SORCEROR"); 700 | hit_noise (); 701 | } 702 | 703 | /* process a fatal hit */ 704 | else { 705 | update_map_tile (necro_x, necro_y, 0x10); 706 | display_map (hero_x, hero_y); 707 | display_message ("SORCEROR IS GONE"); 708 | kill_noise (); 709 | update = 1; 710 | } 711 | 712 | /* return 1 if screen update required */ 713 | return update; 714 | } 715 | 716 | /** 717 | * Show the inventory menu and get an option. 718 | * @return the option chosen. 719 | */ 720 | static int inventory_menu (void) 721 | { 722 | /* local variables */ 723 | int option, /* option currently selected */ 724 | finished, /* finished selecting option */ 725 | key; /* key press */ 726 | 727 | /* decide on the default option */ 728 | if (inventory[inventory_slot] == 0) 729 | option = MENU_INV_CLOSE; 730 | else if (inventory[inventory_slot] == ITEM_APPLE 731 | || inventory[inventory_slot] == ITEM_POTION) 732 | option = MENU_INV_CONSUME; 733 | else if (inventory_slot < 2) 734 | option = MENU_INV_PUT_AWAY; 735 | else 736 | option = MENU_INV_WIELD; 737 | 738 | /* main menu loop */ 739 | finished = 0; 740 | while (! finished) { 741 | 742 | /* display the current option and await a keypress */ 743 | display_message (menu_option_text[option]); 744 | key = get_keypress (); 745 | 746 | /* see if the user has finished */ 747 | if (key == 13 || key == 32 || key == 27) 748 | finished = 1; 749 | 750 | /* cycle through the menu options */ 751 | else if (key == KEY_UP || key == KEY_KEYPAD_UP 752 | || key == KEY_LEFT || key == KEY_KEYPAD_LEFT) 753 | --option; 754 | else if (key == KEY_DOWN || key == KEY_KEYPAD_DOWN 755 | || key == KEY_RIGHT || key == KEY_KEYPAD_RIGHT) 756 | ++option; 757 | 758 | /* choose a menu option based on a shortcut */ 759 | else if (key == '?' || key == 'h') { 760 | option = MENU_INV_HELP; 761 | finished = 1; 762 | } else if (key == 'w') { 763 | option = MENU_INV_WIELD; 764 | finished = 1; 765 | } else if (key == 'p') { 766 | option = MENU_INV_PUT_AWAY; 767 | finished = 1; 768 | } else if (key == 'c') { 769 | option = MENU_INV_CONSUME; 770 | finished = 1; 771 | } else if (key == 'e' && inventory[inventory_slot] == ITEM_APPLE) { 772 | option = MENU_INV_CONSUME; 773 | finished = 1; 774 | } else if (key == 'q' 775 | && inventory[inventory_slot] == ITEM_POTION) { 776 | option = MENU_INV_CONSUME; 777 | finished = 1; 778 | } else if (key == 'd') { 779 | option = MENU_INV_DISCARD; 780 | finished = 1; 781 | } 782 | 783 | /* make sure we're pointing at a valid menu option */ 784 | if (option < MENU_INV_HELP) 785 | option = MENU_INV_CLOSE; 786 | else if (option > MENU_INV_CLOSE) 787 | option = MENU_INV_HELP; 788 | } 789 | blank_message (); 790 | 791 | /* return the option chosen */ 792 | return (key == 27) ? MENU_INV_CLOSE : option; 793 | } 794 | 795 | /** 796 | * Show a list of keys 797 | */ 798 | static void show_keys (void) 799 | { 800 | display_keys (); 801 | show_level (); 802 | display_map (hero_x, hero_y); 803 | } 804 | 805 | /** 806 | * Wield the item highlighted by the inventory cursor. 807 | * @returns 1 on success. 808 | */ 809 | static int wield_item (void) 810 | { 811 | /* local variables */ 812 | int empty_slot, /* empty slot identified in hand */ 813 | success; /* 1 if an item was wielded */ 814 | 815 | /* validation */ 816 | success = 0; 817 | if (inventory_slot < 2) 818 | display_message ("ALREADY WIELDED!"); 819 | else if (inventory[0] && inventory[1]) 820 | display_message (" HANDS ARE FULL "); 821 | else if (inventory[inventory_slot] == 0) 822 | display_message ("NOTHING TO WIELD"); 823 | 824 | /* wield the item */ 825 | else { 826 | display_message ("ITEM NOW WIELDED"); 827 | empty_slot = (inventory[0] != 0); 828 | inventory[empty_slot] = inventory[inventory_slot]; 829 | inventory[inventory_slot] = 0; 830 | display_inventory (empty_slot, inventory[empty_slot]); 831 | display_inventory (inventory_slot, inventory[inventory_slot]); 832 | inventory_slot = empty_slot; 833 | recalc_modifiers (); 834 | success = 1; 835 | } 836 | 837 | /* return a success code */ 838 | return success; 839 | } 840 | 841 | /** 842 | * Put the highlighted wielded item in the bag. 843 | * @returns 1 on success. 844 | */ 845 | static int put_item_away (void) 846 | { 847 | /* local variables */ 848 | int empty_slot, /* empty slot identified in hand */ 849 | success, /* 1 if an item was wielded */ 850 | c; /* inventory slot counter */ 851 | 852 | /* validation */ 853 | success = 0; 854 | if (inventory_slot > 1) 855 | display_message ("ITEM NOT IN HAND"); 856 | else if (inventory[inventory_slot] == 0) 857 | display_message ("ITEM NOT IN HAND"); 858 | 859 | /* wield the item */ 860 | else { 861 | empty_slot = -1; 862 | for (c = 2; c < 12; ++c) 863 | if (inventory[c] == 0) 864 | empty_slot = c; 865 | if (empty_slot == -1) 866 | display_message ("YOUR BAG IS FULL"); 867 | else { 868 | display_message ("ITEM IS PUT AWAY"); 869 | inventory[empty_slot] = inventory[inventory_slot]; 870 | inventory[inventory_slot] = 0; 871 | display_inventory (empty_slot, inventory[empty_slot]); 872 | display_inventory (inventory_slot, inventory[inventory_slot]); 873 | inventory_slot = empty_slot; 874 | recalc_modifiers (); 875 | success = 1; 876 | } 877 | } 878 | 879 | /* return a success code */ 880 | return success; 881 | } 882 | 883 | /** 884 | * Consume the highlighted item. 885 | * @returns 1 on success. 886 | */ 887 | static int consume_item (void) 888 | { 889 | /* local variables */ 890 | int success, /* 1 if item successfully consumed */ 891 | max_health; /* convenience variable */ 892 | 893 | /* initialise */ 894 | success = 0; 895 | max_health = hero_strength + hero_agility + hero_intelligence; 896 | 897 | /* don't waste food if already healthy */ 898 | if (hero_health == max_health) 899 | display_message ("ALREADY HEALTHY "); 900 | 901 | /* eat the delicious apple */ 902 | else if (inventory[inventory_slot] == 3) { 903 | hero_health += 4; 904 | if (hero_health > max_health) 905 | hero_health = max_health; 906 | display_message (" ATE THE APPLE "); 907 | display_health (hero_health, max_health); 908 | inventory[inventory_slot] = 0; 909 | display_inventory (inventory_slot, 0); 910 | success = 1; 911 | } 912 | 913 | /* drink (potion) and be merry */ 914 | else if (inventory[inventory_slot] == 4) { 915 | hero_health = max_health; 916 | display_message (" QUAFFED POTION "); 917 | display_health (hero_health, max_health); 918 | inventory[inventory_slot] = 0; 919 | display_inventory (inventory_slot, 0); 920 | success = 1; 921 | } 922 | 923 | /* reject inedible items */ 924 | else 925 | display_message (" NO EDIBLE ITEM "); 926 | 927 | /* return a success code */ 928 | return success; 929 | } 930 | 931 | /** 932 | * Discard the item highlighted by the inventory cursor. 933 | * @returns 1 on success. 934 | */ 935 | static int discard_item () 936 | { 937 | /* local variables */ 938 | int success; /* 1 if item successfully dropped */ 939 | 940 | /* make sure there's somewhere to drop the item */ 941 | success = 0; 942 | if (! inventory[inventory_slot]) 943 | display_message ("NOTHING TO DROP "); 944 | else if ((map[hero_x][hero_y] & 0xf) != 0) 945 | display_message ("CANNOT DROP HERE"); 946 | 947 | /* discard the item */ 948 | else { 949 | display_message (" ITEM DISCARDED "); 950 | map[hero_x][hero_y] |= inventory[inventory_slot]; 951 | inventory[inventory_slot] = 0; 952 | display_inventory (inventory_slot, 0); 953 | if (inventory_slot < 2) 954 | recalc_modifiers (); 955 | success = 1; 956 | } 957 | 958 | /* return success */ 959 | return success; 960 | } 961 | 962 | /** 963 | * Pathfind for an enemy. 964 | * @param enemy_no is the enemy number. 965 | * @param x is the X coordinate to pathfind to. 966 | * @param y is the Y coordinate to pathfind to. 967 | * @param chasing is 1 if the enemy is chasing the hero. 968 | */ 969 | static void enemy_pathfind (int enemy_no, int x, int y, int chasing) 970 | { 971 | /* local variables */ 972 | int xd, /* X direction */ 973 | yd, /* Y direction */ 974 | block_x, /* X coordinate of adjacent block */ 975 | block_y, /* Y coordinate of adjacent block */ 976 | order, /* randomised order to consider directions */ 977 | axis; /* axis under consideration */ 978 | 979 | /* ascertain directions to head for and order of axes */ 980 | xd = (x > enemies[enemy_no].x) - (x < enemies[enemy_no].x); 981 | yd = (y > enemies[enemy_no].y) - (y < enemies[enemy_no].y); 982 | order = rand () % 2; 983 | 984 | /* attempt to move in each direction */ 985 | for (axis = 0; axis <= 1; ++axis) { 986 | 987 | /* look at an adjacent block */ 988 | block_x = enemies[enemy_no].x; 989 | block_y = enemies[enemy_no].y; 990 | if (axis ^ order) 991 | block_y += yd; 992 | else 993 | block_x += xd; 994 | 995 | /* attempt to move the enemy in this direction */ 996 | if ((block_x != enemies[enemy_no].x 997 | || block_y != enemies[enemy_no].y) 998 | && move_enemy (enemy_no, block_x, block_y)) 999 | return; 1000 | } 1001 | 1002 | /* we didn't manage to move... what to do? */ 1003 | if (! chasing) { 1004 | enemies[enemy_no].dest_x = rand () % 16; 1005 | enemies[enemy_no].dest_y = rand () % 16; 1006 | } 1007 | } 1008 | 1009 | /*---------------------------------------------------------------------- 1010 | * Level 1 Routines. 1011 | */ 1012 | 1013 | /** 1014 | * Scramble the cell numbers. 1015 | * This provides an easy way to link up all the cells randomly. 1016 | * @param cell_order is a scrambled index to the cells. 1017 | */ 1018 | static void scramble_cells (int *cell_order) 1019 | { 1020 | /* local variables */ 1021 | int cell_count, /* cell counter */ 1022 | cell_swap; /* cell to swap with */ 1023 | 1024 | /* loop through the cell index swapping at random */ 1025 | for (cell_count = 0; cell_count < 9; ++cell_count) { 1026 | do { 1027 | cell_swap = rand () % 9; 1028 | } while (cell_swap == cell_count); 1029 | cell_order[cell_swap] ^= cell_order[cell_count]; 1030 | cell_order[cell_count] ^= cell_order[cell_swap]; 1031 | cell_order[cell_swap] ^= cell_order[cell_count]; 1032 | } 1033 | } 1034 | 1035 | /** 1036 | * Generate a network of paths between the 3x cells. 1037 | * Since there's a randomised cell index, beating a path from 0->1, 1038 | * 1->2 .. 7->8 in the cardinal directions generates a nice 3x3 dungeon. 1039 | * @param cell_order is a scrambled index to the cells. 1040 | * @param cell_map is the 3x3 cell map. 1041 | */ 1042 | static void generate_paths (int *cell_order, int *cell_map) 1043 | { 1044 | /* local variables */ 1045 | int cell_count, /* cell counter */ 1046 | curr_cell, /* cell to dig a path from */ 1047 | dest_cell; /* cell to dig a path towards */ 1048 | 1049 | /* block off any paths from the previous level */ 1050 | for (cell_count = 0; cell_count < 9; ++cell_count) 1051 | cell_map[cell_count] = 0; 1052 | 1053 | /* create the 8 paths between the 9 randomised cells */ 1054 | for (cell_count = 0; cell_count < 8; ++cell_count) { 1055 | 1056 | /* ascertain the two cells we're connecting */ 1057 | curr_cell = cell_order[cell_count]; 1058 | dest_cell = cell_order[cell_count + 1]; 1059 | 1060 | /* dig a vertical path */ 1061 | while (curr_cell / 3 != dest_cell / 3) { 1062 | if (curr_cell < dest_cell) { 1063 | cell_map[curr_cell] |= CELL_SOUTH; 1064 | cell_map[curr_cell + 3] |= CELL_NORTH; 1065 | curr_cell += 3; 1066 | } else { 1067 | cell_map[curr_cell] |= CELL_NORTH; 1068 | cell_map[curr_cell - 3] |= CELL_SOUTH; 1069 | curr_cell -= 3; 1070 | } 1071 | } 1072 | 1073 | /* dig a horizontal path */ 1074 | while (curr_cell != dest_cell) { 1075 | if (curr_cell < dest_cell) { 1076 | cell_map[curr_cell] |= CELL_EAST; 1077 | cell_map[++curr_cell] |= CELL_WEST; 1078 | } else { 1079 | cell_map[curr_cell] |= CELL_WEST; 1080 | cell_map[--curr_cell] |= CELL_EAST; 1081 | } 1082 | } 1083 | } 1084 | } 1085 | 1086 | /** 1087 | * Generate the chambers. 1088 | * There's a 50% chance that each of the cells on the 3x3 grid will be 1089 | * a chamber, otherwise it will remain a corridor. Dead ends are also 1090 | * turned into chambers, so the proportion of chambers to corridors will 1091 | * be more than 50:50. 1092 | * @params cell_map is the cell map to modify. 1093 | */ 1094 | static void generate_chambers (int *cell_map) 1095 | { 1096 | /* local variables */ 1097 | int cell_count; /* counter for looping through cells */ 1098 | 1099 | /* loop through the cells */ 1100 | for (cell_count = 0; cell_count < 9; ++cell_count) { 1101 | 1102 | /* dead ends are always chambers */ 1103 | if (cell_map[cell_count] == CELL_EAST || 1104 | cell_map[cell_count] == CELL_SOUTH || 1105 | cell_map[cell_count] == CELL_WEST || 1106 | cell_map[cell_count] == CELL_NORTH) 1107 | cell_map[cell_count] |= CELL_CHAMBER; 1108 | 1109 | /* the rest are a 50/50 chance */ 1110 | else if (rand () % 2) 1111 | cell_map[cell_count] |= CELL_CHAMBER; 1112 | } 1113 | } 1114 | 1115 | /** 1116 | * fill the 16x16 map with wall. 1117 | */ 1118 | static void fill_map () 1119 | { 1120 | memset (map, 0, 256); 1121 | } 1122 | 1123 | /** 1124 | * Dig out the room and corridor cells on the 16x16 map. 1125 | * @params cell_map is the 3x3 map of cells. 1126 | */ 1127 | static void open_cells (int *cell_map) 1128 | { 1129 | /* local variables */ 1130 | int cell_count; /* counter for looping through cells */ 1131 | int x, y; /* map square pointer */ 1132 | int offset; /* offset count for digging corridors */ 1133 | 1134 | /* loop through the cells */ 1135 | for (cell_count = 0; cell_count < 9; ++cell_count) { 1136 | 1137 | /* calculate x and y coordinates of the top left corner wall */ 1138 | x = 5 * (cell_count % 3); 1139 | y = 5 * (cell_count / 3); 1140 | 1141 | /* open out a chamber */ 1142 | if (cell_map[cell_count] & CELL_CHAMBER) { 1143 | 1144 | /* open up chamber exits */ 1145 | if (cell_map[cell_count] & CELL_SOUTH) 1146 | map[x + 2][y + 5] = 0x10; 1147 | if (cell_map[cell_count] & CELL_EAST) 1148 | map[x + 5][y + 2] = 0x10; 1149 | 1150 | /* dig out chamber */ 1151 | for (x = 1 + 5 * (cell_count % 3); 1152 | x < 5 + 5 * (cell_count % 3); 1153 | ++x) 1154 | for (y = 1 + 5 * (cell_count / 3); 1155 | y < 5 + 5 * (cell_count / 3); 1156 | ++y) 1157 | map[x][y] = 0x10; 1158 | } 1159 | 1160 | /* open up a corridor */ 1161 | else { 1162 | for (offset = 0; offset <= 5; ++offset) { 1163 | if (offset <= 2 && (cell_map[cell_count] & CELL_NORTH)) 1164 | map[x + 2][y + offset] = 0x10; 1165 | if (offset >= 2 && (cell_map[cell_count] & CELL_SOUTH)) 1166 | map[x + 2][y + offset] = 0x10; 1167 | if (offset <= 2 && (cell_map[cell_count] & CELL_WEST)) 1168 | map[x + offset][y + 2] = 0x10; 1169 | if (offset >= 2 && (cell_map[cell_count] & CELL_EAST)) 1170 | map[x + offset][y + 2] = 0x10; 1171 | } 1172 | } 1173 | } 1174 | } 1175 | 1176 | /** 1177 | * Decorate some exposed walls with gargoyles, niches and torches. 1178 | */ 1179 | static void decorate_walls () 1180 | { 1181 | /* local variables */ 1182 | int x, y; /* coordinate counters */ 1183 | 1184 | /* loop through all map squares looking for exposed walls */ 1185 | for (x = 0; x < 15; ++x) 1186 | for (y = 0; y < 15; ++y) 1187 | if (map[x][y] == 0 1188 | && (x > 0 && map[x - 1][y] == 0x10 1189 | || x < 15 && map[x + 1][y] == 0x10 1190 | || y > 0 && map[x][y - 1] == 0x10 1191 | || y < 15 && map[x][y + 1] == 0x10) 1192 | && rand () % 2) 1193 | map[x][y] = rand () & 3; 1194 | } 1195 | 1196 | /** 1197 | * Build a quick list of key items in the player's inventory. 1198 | * @returns a bit-field collection of flags for various items. 1199 | */ 1200 | static int get_quick_inventory (void) 1201 | { 1202 | /* local variables */ 1203 | int quick_inventory, /* the inventory to return */ 1204 | i_count; /* a counter to loop through items */ 1205 | 1206 | /* see what the player has */ 1207 | quick_inventory = 0; 1208 | for (i_count = 0; i_count < 12; ++i_count) 1209 | switch (inventory[i_count]) { 1210 | case 12: quick_inventory |= QI_WAND; break; 1211 | case 11: quick_inventory |= QI_AMULET; break; 1212 | case 9: quick_inventory |= QI_IRON_SHIELD; break; 1213 | case 8: quick_inventory |= QI_WOODEN_SHIELD; break; 1214 | case 7: quick_inventory |= QI_AXE; break; 1215 | case 6: quick_inventory |= QI_SWORD; break; 1216 | case 5: quick_inventory |= QI_DAGGER; break; 1217 | case 4: quick_inventory |= QI_POTION; break; 1218 | } 1219 | 1220 | /* return the quick inventory */ 1221 | return quick_inventory; 1222 | } 1223 | 1224 | /** 1225 | * Build up a list of items to place on the current level. 1226 | * @param items_list is the array of items to build. 1227 | * @param quick_inventory is a bit-encoded list of what the player has. 1228 | * The quick_inventory parameter is also abused to mark off items as we 1229 | * add them to item_list. 1230 | */ 1231 | static void build_items_list (int *items_list, int quick_inventory) 1232 | { 1233 | /* local variables */ 1234 | int i_count, /* count of items */ 1235 | added_potions, /* number of potions added */ 1236 | added_scroll, /* 1 if a scroll already added */ 1237 | apples_to_add; /* random number of apples for the level */ 1238 | 1239 | /* initialise counters */ 1240 | added_potions = added_scroll = 0; 1241 | apples_to_add = rand () % 4; 1242 | 1243 | /* build the six non-gold items on the level*/ 1244 | for (i_count = 0; i_count < 6; ++i_count) 1245 | 1246 | /* consider adding a wand */ 1247 | if (! (quick_inventory & QI_WAND)) { 1248 | items_list[i_count] = ITEM_WAND; 1249 | quick_inventory |= QI_WAND; 1250 | } 1251 | 1252 | /* consider adding an amulet */ 1253 | else if (enemy_max >= ENEMY_CADAVER 1254 | && ! (quick_inventory & QI_AMULET)) { 1255 | items_list[i_count] = ITEM_AMULET; 1256 | quick_inventory |= QI_AMULET; 1257 | } 1258 | 1259 | /* consider adding a scroll */ 1260 | else if (enemy_max >= ENEMY_SKELETON && ! added_scroll) { 1261 | items_list[i_count] = ITEM_SCROLL; 1262 | ++added_scroll; 1263 | } 1264 | 1265 | /* consider adding an iron shield */ 1266 | else if (enemy_max >= ENEMY_CADAVER 1267 | && (! (quick_inventory & QI_IRON_SHIELD))) { 1268 | items_list[i_count] = ITEM_IRON_SHIELD; 1269 | quick_inventory |= QI_IRON_SHIELD; 1270 | } 1271 | 1272 | /* consider adding a wooden shield */ 1273 | else if (enemy_max >= ENEMY_ARACHNID 1274 | && ! (quick_inventory & QI_ANY_SHIELD)) { 1275 | items_list[i_count] = ITEM_WOODEN_SHIELD; 1276 | quick_inventory |= QI_WOODEN_SHIELD; 1277 | } 1278 | 1279 | /* consider adding an axe */ 1280 | else if (enemy_max >= ENEMY_SKELETON 1281 | && ! (quick_inventory & QI_AXE)) { 1282 | items_list[i_count] = ITEM_AXE; 1283 | quick_inventory |= QI_AXE; 1284 | } 1285 | 1286 | /* consider adding a sword */ 1287 | else if (enemy_max >= ENEMY_SERPENT 1288 | && ! (quick_inventory & QI_BIG_WEAPON)) { 1289 | items_list[i_count] = ITEM_SWORD; 1290 | quick_inventory |= QI_SWORD; 1291 | } 1292 | 1293 | /* consider adding a dagger */ 1294 | else if (! (quick_inventory & QI_ANY_WEAPON)) { 1295 | items_list[i_count] = ITEM_DAGGER; 1296 | quick_inventory |= QI_DAGGER; 1297 | } 1298 | 1299 | /* add the first potion */ 1300 | else if (! added_potions) { 1301 | items_list[i_count] = ITEM_POTION; 1302 | ++added_potions; 1303 | } 1304 | 1305 | /* consider adding a second potion */ 1306 | else if (enemy_max == ENEMY_DAEMON && added_potions < 2) { 1307 | items_list[i_count] = ITEM_POTION; 1308 | ++added_potions; 1309 | } 1310 | 1311 | /* add the appropriate number of apples */ 1312 | else if (apples_to_add-- > 0) 1313 | items_list[i_count] = ITEM_APPLE; 1314 | 1315 | /* fill the rest of the slots with gold */ 1316 | else 1317 | items_list[i_count] 1318 | = 1 + (rand () % 24) >= level 1319 | ? ITEM_PURSE 1320 | : ITEM_CASKET; 1321 | } 1322 | 1323 | /** 1324 | * Place onto the map the items chosen. 1325 | * @param items_list is the list of items chosen by build_items_list(). 1326 | */ 1327 | static void place_listed_items (int *items_list) 1328 | { 1329 | /* local variables */ 1330 | int i_count, /* a counter of the items */ 1331 | x, y; /* temporary holders for location */ 1332 | 1333 | /* loop through the items */ 1334 | for (i_count = 0; i_count < 6; ++i_count) { 1335 | 1336 | /* the first four items are guarded */ 1337 | if (i_count < 4) { 1338 | x = enemies[i_count].x; 1339 | y = enemies[i_count].y; 1340 | if ((enemies[i_count].type >= ENEMY_VERMIN 1341 | && enemies[i_count].type <= ENEMY_SERPENT) 1342 | || enemies[i_count].type == ENEMY_SPECTRE) 1343 | enemies[i_count].behaviour = BEHAVIOUR_GUARD; 1344 | } 1345 | 1346 | /* the last two items are out in the open */ 1347 | else 1348 | do { 1349 | x = rand () % 16; 1350 | y = rand () % 16; 1351 | } while (map[x][y] != 0x10); 1352 | 1353 | /* place the item at the chosen map location */ 1354 | map[x][y] |= items_list[i_count]; 1355 | } 1356 | } 1357 | 1358 | /** 1359 | * Ascertain player direction from a keypress. 1360 | * @param key is the value of the key pressed 1361 | * @returns an integer corresponding to the direction keys. 1362 | */ 1363 | static int get_direction (int key) 1364 | { 1365 | /* local variables */ 1366 | int direction = DIR_NONE; 1367 | 1368 | /* set the direction if exactly one direction key is pressed */ 1369 | if (key == KEY_UP || key == KEY_KEYPAD_UP) 1370 | direction = DIR_UP; 1371 | else if (key == KEY_DOWN || key == KEY_KEYPAD_DOWN) 1372 | direction = DIR_DOWN; 1373 | else if (key == KEY_LEFT || key == KEY_KEYPAD_LEFT) 1374 | direction = DIR_LEFT; 1375 | else if (key == KEY_RIGHT || key == KEY_KEYPAD_RIGHT) 1376 | direction = DIR_RIGHT; 1377 | 1378 | /* return the direction, using DIR_NONE to signify none */ 1379 | return direction; 1380 | } 1381 | 1382 | /** 1383 | * Move the hero in a given direction. 1384 | * @param direction is the direction to move in. 1385 | * @returns 1 if the hero successfully moves. 1386 | */ 1387 | static int move_hero (int direction) 1388 | { 1389 | /* local variables */ 1390 | int xd, yd; /* X and Y direction offsets */ 1391 | int dest; /* contents of destination square */ 1392 | 1393 | /* determine X and Y direction offsets and see what's there */ 1394 | switch (direction) { 1395 | case DIR_UP: xd = 0; yd = -1; break; 1396 | case DIR_DOWN: xd = 0; yd = 1; break; 1397 | case DIR_LEFT: xd = -1; yd = 0; break; 1398 | case DIR_RIGHT: xd = 1; yd = 0; break; 1399 | } 1400 | dest = map[hero_x + xd][hero_y + yd]; 1401 | 1402 | /* if it's a wall, we can't go there */ 1403 | if (dest < 4) 1404 | return 0; 1405 | 1406 | /* if destination square is clear, move there */ 1407 | else if ((dest & 0xf0) == 0x10) { 1408 | 1409 | /* move the hero */ 1410 | map[hero_x + xd][hero_y + yd] ^= 0x30; 1411 | map[hero_x][hero_y] ^= 0x30; 1412 | update_map_tile (hero_x + xd, hero_y + yd, 1413 | map[hero_x + xd][hero_y + yd]); 1414 | update_map_tile (hero_x, hero_y, map[hero_x][hero_y]); 1415 | hero_x += xd; 1416 | hero_y += yd; 1417 | display_map (hero_x, hero_y); 1418 | 1419 | /* update the message */ 1420 | if (map[hero_x][hero_y] & 0xf) 1421 | display_message (item_message[map[hero_x][hero_y] & 0xf]); 1422 | else 1423 | blank_message (); 1424 | } 1425 | 1426 | /* if the destination square is an enemy, attack it */ 1427 | else if (dest & 0x80) 1428 | attack_enemy (hero_x + xd, hero_y + yd); 1429 | 1430 | /* if the destination square is the necromancer, attack him */ 1431 | else if (dest == 0x30) 1432 | attack_necromancer (); 1433 | 1434 | /* we performed an action! */ 1435 | return 1; 1436 | } 1437 | 1438 | /** 1439 | * Bring up the main menu and perform the selected option. 1440 | * @returns 1 if the level should be finished. 1441 | */ 1442 | static int main_menu (void) 1443 | { 1444 | /* local variables */ 1445 | int option, /* option currently selected */ 1446 | finished, /* finished selecting option */ 1447 | key; /* key press */ 1448 | 1449 | /* decide on the default option */ 1450 | if ((map[hero_x][hero_y] & 0xf) == 0) 1451 | option = MENU_INVENTORY; 1452 | else if ((map[hero_x][hero_y] & 0xf) == 0xf) 1453 | option = MENU_DESCEND; 1454 | else 1455 | option = MENU_PICK_UP; 1456 | 1457 | /* main menu loop */ 1458 | finished = 0; 1459 | while (! finished) { 1460 | 1461 | /* display the current option and await a keypress */ 1462 | display_message (menu_option_text[option]); 1463 | key = get_keypress (); 1464 | 1465 | /* see if the user has finished */ 1466 | if (key == 32 || key == 27) 1467 | finished = 1; 1468 | 1469 | /* cycle through the menu options */ 1470 | else if (key == KEY_UP || key == KEY_KEYPAD_UP 1471 | || key == KEY_LEFT || key == KEY_KEYPAD_LEFT) 1472 | --option; 1473 | else if (key == KEY_DOWN || key == KEY_KEYPAD_DOWN 1474 | || key == KEY_RIGHT || key == KEY_KEYPAD_RIGHT) 1475 | ++option; 1476 | 1477 | /* choose a menu option based on a shortcut */ 1478 | else if (key == '?' || key == 'h') { 1479 | option = MENU_HELP; 1480 | finished = 1; 1481 | } else if (key == '.') { 1482 | option = MENU_WAIT; 1483 | finished = 1; 1484 | } else if (key == 'i') { 1485 | option = MENU_INVENTORY; 1486 | finished = 1; 1487 | } else if (key == 't') { 1488 | option = MENU_PICK_UP; 1489 | finished = 1; 1490 | } else if (key == 'e') { 1491 | option = MENU_EAT; 1492 | finished = 1; 1493 | } else if (key == 'q') { 1494 | option = MENU_QUAFF; 1495 | finished = 1; 1496 | } else if (key == 's' || key == '>') { 1497 | option = MENU_DESCEND; 1498 | finished = 1; 1499 | } else if (key == 'x') { 1500 | option = MENU_EXIT; 1501 | finished = 1; 1502 | } 1503 | 1504 | 1505 | /* make sure we're pointing at a valid menu option */ 1506 | if (option < MENU_HELP) 1507 | option = MENU_CANCEL; 1508 | else if (option > MENU_CANCEL) 1509 | option = MENU_HELP; 1510 | } 1511 | blank_message (); 1512 | 1513 | /* return the option chosen */ 1514 | return (key == 27) ? MENU_CANCEL : option; 1515 | } 1516 | 1517 | /** 1518 | * Pick up an item. 1519 | * Returns 1 if hero managed to pick something up. 1520 | */ 1521 | static int pick_up_item (void) 1522 | { 1523 | /* local variables */ 1524 | int item, /* what are we trying to pick up? */ 1525 | i; /* inventory slot counter */ 1526 | 1527 | /* make sure there is something to pick up */ 1528 | item = map[hero_x][hero_y] & 0xf; 1529 | if (item == 0 || item == 0xf) { 1530 | display_message ("NOTHING TO TAKE!"); 1531 | return 0; 1532 | } 1533 | 1534 | /* if this is gold, just add it to the total */ 1535 | if (item <= 2) { 1536 | gold += (item == 1) ? 20 : 50; 1537 | display_gold (gold); 1538 | gold_noise (); 1539 | } 1540 | 1541 | /* otherwise put it in the inventory */ 1542 | else { 1543 | 1544 | /* find a free inventory slot */ 1545 | for (i = 0; i < 12; ++i) 1546 | if (inventory[i] == 0) 1547 | inventory_slot = i; 1548 | if (inventory[inventory_slot]) { 1549 | display_message ("YOUR BAG IS FULL"); 1550 | return 0; 1551 | } 1552 | 1553 | /* put the item there */ 1554 | inventory[inventory_slot] = item; 1555 | display_inventory (inventory_slot, item); 1556 | if (inventory_slot < 2) 1557 | recalc_modifiers (); 1558 | inventory_noise (); 1559 | } 1560 | 1561 | /* remove item from map and show message */ 1562 | map[hero_x][hero_y] &= 0xf0; 1563 | display_message (" PICKED UP ITEM "); 1564 | return 1; 1565 | } 1566 | 1567 | /** 1568 | * Find an apple in the inventory and eat it. 1569 | * @returns 1 if hero managed to eat. 1570 | */ 1571 | static int eat_something (void) 1572 | { 1573 | /* local variables */ 1574 | int i, /* item counter */ 1575 | success; /* 1 if item eaten */ 1576 | 1577 | /* search for an apple */ 1578 | for (i = 11; i >= 0; --i) 1579 | if (inventory[i] == ITEM_APPLE) 1580 | inventory_slot = i; 1581 | 1582 | /* did we find an apple? */ 1583 | if (inventory[inventory_slot] == ITEM_APPLE) { 1584 | success = consume_item (); 1585 | if (success) 1586 | inventory_noise (); 1587 | return success; 1588 | } 1589 | 1590 | /* complain that we didn't find an apple */ 1591 | display_message (" NOTHING TO EAT "); 1592 | return 0; 1593 | } 1594 | 1595 | /** 1596 | * Find a potion in the inventory and drink it. 1597 | * @returns 1 if the hero managed to drink. 1598 | */ 1599 | static int quaff_something (void) 1600 | { 1601 | /* local variables */ 1602 | int i, /* item counter */ 1603 | success; /* 1 if potion quaffed */ 1604 | 1605 | /* search for a ption */ 1606 | for (i = 11; i >= 0; --i) 1607 | if (inventory[i] == ITEM_POTION) 1608 | inventory_slot = i; 1609 | 1610 | /* did we find a potion? */ 1611 | if (inventory[inventory_slot] == ITEM_POTION) { 1612 | success = consume_item (); 1613 | if (success) 1614 | inventory_noise (); 1615 | return success; 1616 | } 1617 | 1618 | /* complain that we didn't find a potion */ 1619 | display_message ("NOTHING TO QUAFF"); 1620 | return 0; 1621 | } 1622 | 1623 | /** 1624 | * Descend the stairs. 1625 | * @returns 1 if successful. 1626 | */ 1627 | static int descend_stairs (void) 1628 | { 1629 | /* local variables */ 1630 | int success = 0; /* 1 when hero descends */ 1631 | int difficulty; /* difficulty to increase */ 1632 | 1633 | /* are we at the stairs? */ 1634 | if (map[hero_x][hero_y] == 0x2f) { 1635 | 1636 | /* increase level and mark this level done */ 1637 | ++level; 1638 | level_over = 1; 1639 | 1640 | /* increase some difficulty */ 1641 | if (level < 24) 1642 | do { 1643 | difficulty = 1 + rand () % 3; 1644 | if (difficulty == 1 && enemy_min < enemy_max) 1645 | ++enemy_min; 1646 | else if (difficulty == 2 && enemy_max < ENEMY_DAEMON) 1647 | ++enemy_max; 1648 | else if (difficulty == 3 && enemy_anger < 8) 1649 | ++enemy_anger; 1650 | else 1651 | difficulty = 0; 1652 | } while (! difficulty); 1653 | 1654 | /* set message and mark success */ 1655 | display_message ("DESCENDING STEPS"); 1656 | update_map_tile (hero_x, hero_y, 0x1f); 1657 | display_map (hero_x, hero_y); 1658 | stairs_noise (); 1659 | success = 1; 1660 | } 1661 | 1662 | /* we're not at the stairs, give an error message */ 1663 | else 1664 | display_message (" NO STAIRS HERE "); 1665 | 1666 | /* return a success code */ 1667 | return success; 1668 | } 1669 | 1670 | /** 1671 | * Perform the "wait a minute" action. 1672 | * @returns 1 - this action never failes. 1673 | */ 1674 | static int wait_action (void) 1675 | { 1676 | display_message (" TIME PASSES... "); 1677 | return 1; 1678 | } 1679 | 1680 | /** 1681 | * Do some inventory action. 1682 | * @returns 1 if an action was successfully performed. 1683 | */ 1684 | static int inventory_action (void) 1685 | { 1686 | /* local variables */ 1687 | int key, /* key pressed */ 1688 | option, /* option returned */ 1689 | action; /* 1 if an action was successfully performed */ 1690 | 1691 | /* main inventory loop */ 1692 | action = 0; 1693 | option = MENU_CANCEL; 1694 | while (option == MENU_CANCEL) { 1695 | 1696 | /* highlight inventory and get a keypress */ 1697 | highlight_inventory (inventory_slot); 1698 | if (inventory[inventory_slot]) 1699 | display_message (item_message[inventory[inventory_slot]]); 1700 | else 1701 | blank_message (); 1702 | key = get_keypress (); 1703 | display_inventory (inventory_slot, inventory[inventory_slot]); 1704 | if (inventory[inventory_slot]) 1705 | blank_message (); 1706 | 1707 | /* move around the inventory */ 1708 | if ((key == KEY_UP || key == KEY_KEYPAD_UP) 1709 | && inventory_slot > 1) 1710 | inventory_slot -= 2; 1711 | else if ((key == KEY_DOWN || key == KEY_KEYPAD_DOWN) 1712 | && inventory_slot < 10) 1713 | inventory_slot += 2; 1714 | else if ((key == KEY_LEFT || key == KEY_KEYPAD_LEFT) 1715 | && (inventory_slot % 2)) 1716 | --inventory_slot; 1717 | else if ((key == KEY_RIGHT || key == KEY_KEYPAD_RIGHT) 1718 | && ! (inventory_slot % 2)) 1719 | ++inventory_slot; 1720 | 1721 | /* process menu key and shortcuts */ 1722 | else if (key == 32 || key == 13) 1723 | option = inventory_menu (); 1724 | else if (key == '?' || key == 'h') 1725 | option = MENU_INV_HELP; 1726 | else if (key == 'w') 1727 | option = MENU_INV_WIELD; 1728 | else if (key == 'p') 1729 | option = MENU_INV_PUT_AWAY; 1730 | else if (key == 'c') 1731 | option = MENU_INV_CONSUME; 1732 | else if (key == 'e' && inventory[inventory_slot] == ITEM_APPLE) 1733 | option = MENU_INV_CONSUME; 1734 | else if (key == 'q' && inventory[inventory_slot] == ITEM_POTION) 1735 | option = MENU_INV_CONSUME; 1736 | else if (key == 'd') 1737 | option = MENU_INV_DISCARD; 1738 | else if (key == 27) 1739 | option = MENU_INV_CLOSE; 1740 | } 1741 | 1742 | /* process the option chosen */ 1743 | switch (option) { 1744 | case MENU_INV_CLOSE: break; 1745 | case MENU_INV_HELP: show_keys (); break; 1746 | case MENU_INV_WIELD: action = wield_item (); break; 1747 | case MENU_INV_PUT_AWAY: action = put_item_away (); break; 1748 | case MENU_INV_CONSUME: action = consume_item (); break; 1749 | case MENU_INV_DISCARD: action = discard_item (); break; 1750 | } 1751 | 1752 | /* return true if an action was performed */ 1753 | if (action) 1754 | inventory_noise (); 1755 | return action; 1756 | } 1757 | 1758 | /** 1759 | * Confirm that the player wishes to restart the game. 1760 | */ 1761 | static void confirm_new_game (void) 1762 | { 1763 | int key; /* key press Y or N */ 1764 | display_message ("START NEW GAME? "); 1765 | do { 1766 | key = get_keypress (); 1767 | } while (key != 'y' && key != 'n'); 1768 | blank_message (); 1769 | game_over = (key == 'y'); 1770 | } 1771 | 1772 | /** 1773 | * Confirm that the player wishes to exit the game. 1774 | */ 1775 | static void confirm_exit (void) 1776 | { 1777 | int key; /* key press Y or N */ 1778 | display_message ("REALLY EXIT? Y/N"); 1779 | do { 1780 | key = get_keypress (); 1781 | } while (key != 'y' && key != 'n'); 1782 | blank_message (); 1783 | game_quit = (key == 'y'); 1784 | } 1785 | 1786 | /** 1787 | * Work out and perform an action for an individual enemy. 1788 | * @param enemy_no is the enemy number. 1789 | */ 1790 | static void individual_enemy_action (int enemy_no) 1791 | { 1792 | /* local variables */ 1793 | int distance; /* distance between enemy and hero */ 1794 | 1795 | /* work out if we should be chasing */ 1796 | distance = abs (enemies[enemy_no].x - hero_x) 1797 | + abs (enemies[enemy_no].y - hero_y); 1798 | 1799 | /* chase the player if close enough */ 1800 | if (distance <= enemies[enemy_no].aggression) 1801 | enemy_pathfind (enemy_no, hero_x, hero_y, 1); 1802 | 1803 | /* if wandering, continue wandering */ 1804 | else if (enemies[enemy_no].behaviour == BEHAVIOUR_WANDER) 1805 | enemy_pathfind (enemy_no, enemies[enemy_no].dest_x, 1806 | enemies[enemy_no].dest_y, 0); 1807 | } 1808 | 1809 | /*---------------------------------------------------------------------- 1810 | * Public Level Functions. 1811 | */ 1812 | 1813 | /** 1814 | * Initialise some game variables. 1815 | */ 1816 | void init_game (void) 1817 | { 1818 | level = 1; 1819 | gold = 0; 1820 | enemy_min = ENEMY_BAT; 1821 | enemy_max = ENEMY_BAT; 1822 | enemy_anger = 0; 1823 | experience = 0; 1824 | necro_health = 24; 1825 | game_over = 0; 1826 | game_quit = 0; 1827 | } 1828 | 1829 | /** 1830 | * Generate the hero. 1831 | */ 1832 | void generate_hero (void) 1833 | { 1834 | /* local variables */ 1835 | int stat_increases = 15; 1836 | int *stat_ptr; 1837 | 1838 | /* start with minimum stats */ 1839 | hero_strength = 2; 1840 | hero_agility = 2; 1841 | hero_intelligence = 2; 1842 | 1843 | /* increase stats to a sensible level */ 1844 | while (stat_increases) { 1845 | switch (rand () % 3) { 1846 | case 0: stat_ptr = &hero_strength; break; 1847 | case 1: stat_ptr = &hero_agility; break; 1848 | case 2: stat_ptr = &hero_intelligence; break; 1849 | } 1850 | if (*stat_ptr == 12) continue; 1851 | ++*stat_ptr; 1852 | --stat_increases; 1853 | } 1854 | 1855 | /* set the modifiers */ 1856 | strength_modifier = 0; 1857 | agility_modifier = 0; 1858 | intelligence_modifier = 0; 1859 | 1860 | /* set health to 21 */ 1861 | hero_health = 21; 1862 | } 1863 | 1864 | /** 1865 | * Initialise the inventory. 1866 | */ 1867 | void init_inventory (void) 1868 | { 1869 | /* local variables */ 1870 | static int start_items[12] = { 1871 | 0, 0, 1872 | 0, 0, 0, 0, 0, 0, 0, 4, 3, 3 1873 | }; 1874 | int count; 1875 | 1876 | /* copy the starting items into the inventory */ 1877 | for (count = 0; count < 12; ++count) 1878 | inventory[count] = start_items[count]; 1879 | inventory_slot = 0; 1880 | } 1881 | 1882 | /** 1883 | * Show the player stats. 1884 | */ 1885 | void show_stats (void) 1886 | { 1887 | display_stat (0, hero_strength, strength_modifier); 1888 | display_stat (1, hero_agility, agility_modifier); 1889 | display_stat (2, hero_intelligence, intelligence_modifier); 1890 | display_health (hero_health, 1891 | hero_strength + hero_agility + hero_intelligence); 1892 | } 1893 | 1894 | /** 1895 | * Show the gold counter. 1896 | */ 1897 | void show_gold (void) 1898 | { 1899 | display_gold (gold); 1900 | } 1901 | 1902 | /** 1903 | * Show the inventory. 1904 | */ 1905 | void show_inventory (void) 1906 | { 1907 | int i; 1908 | for (i = 0; i < 12; ++i) 1909 | display_inventory (i, inventory[i]); 1910 | } 1911 | 1912 | /** 1913 | * Ask the player for their name. 1914 | */ 1915 | void ask_name (void) 1916 | { 1917 | /* local variables */ 1918 | char prompt[17]; 1919 | int ch; 1920 | 1921 | /* editing loop */ 1922 | do { 1923 | 1924 | /* prompt */ 1925 | sprintf (prompt, "NAME? %-10s", name); 1926 | display_message (prompt); 1927 | 1928 | /* get a key. Discard special keys */ 1929 | ch = toupper (get_keypress ()); 1930 | 1931 | /* if it's a printable character, add it to the name */ 1932 | if (ch >= ' ' && ch <= '_' && ch != ':' && strlen (name) < 10) { 1933 | name[strlen (name) + 1] = '\0'; 1934 | name[strlen (name)] = ch; 1935 | } 1936 | 1937 | /* if it's backspace, delete the last character */ 1938 | else if (ch == 8 && *name != '\0') 1939 | name[strlen (name) - 1] = '\0'; 1940 | 1941 | } while (ch != 13); 1942 | 1943 | /* greet the player */ 1944 | display_message (" PLEASE WAIT... "); 1945 | } 1946 | 1947 | /** 1948 | * Initialise the map for a level 1949 | */ 1950 | void generate_map (void) 1951 | { 1952 | /* local variables */ 1953 | static int cell_order[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; 1954 | int cell_map[9]; 1955 | 1956 | /* build up the 3x3 cell network */ 1957 | scramble_cells (cell_order); 1958 | generate_paths (cell_order, cell_map); 1959 | generate_chambers (cell_map); 1960 | 1961 | /* turn the cell network into a 16x16 map */ 1962 | fill_map (); 1963 | open_cells (cell_map); 1964 | decorate_walls (); 1965 | } 1966 | 1967 | /** 1968 | * Place the hero on the current level 1969 | */ 1970 | void place_hero (void) 1971 | { 1972 | do { 1973 | hero_x = rand () % 16; 1974 | hero_y = rand () % 16; 1975 | } while (map[hero_x][hero_y] != 0x10); 1976 | map[hero_x][hero_y] = 0x20; 1977 | level_over = 0; 1978 | } 1979 | 1980 | /** 1981 | * Place the level's objective (staircase or necromancer) 1982 | */ 1983 | void place_objective (void) 1984 | { 1985 | /* local variables */ 1986 | int x, y; /* location choice */ 1987 | 1988 | /* choose a suitable location */ 1989 | do { 1990 | x = rand () % 16; 1991 | y = rand () % 16; 1992 | } while (map[x][y] != 0x10 1993 | || abs (x - hero_x) + abs (y - hero_y) < 10); 1994 | 1995 | /* if we're on level 24, place the necromancer */ 1996 | if (level == 24) { 1997 | necro_x = x; 1998 | necro_y = y; 1999 | map[x][y] = 0x30; 2000 | } 2001 | 2002 | /* otherwise place the stairs down */ 2003 | else 2004 | map[x][y] = 0x1f; 2005 | } 2006 | 2007 | /** 2008 | * Place the level's eight enemies 2009 | */ 2010 | void place_enemies (void) 2011 | { 2012 | int e_count; /* enemy count */ 2013 | int x, y; /* temporary variables to look at map */ 2014 | 2015 | /* loop through eight enemies */ 2016 | for (e_count = 0; e_count < 8; ++e_count) { 2017 | 2018 | /* find a suitable place for this enemy */ 2019 | do { 2020 | x = rand () % 16; 2021 | y = rand () % 16; 2022 | } while (map[x][y] != 0x10 2023 | || abs (x - hero_x) + abs (y - hero_y) < 7); 2024 | 2025 | /* set the enemy details */ 2026 | enemies[e_count].x = x; 2027 | enemies[e_count].y = y; 2028 | enemies[e_count].type = enemy_min 2029 | + rand () % (enemy_max - enemy_min + 1); 2030 | enemies[e_count].health 2031 | = enemy_stats[enemies[e_count].type].strength 2032 | + enemy_stats[enemies[e_count].type].agility; 2033 | enemies[e_count].behaviour = rand () % 2; 2034 | if (enemies[e_count].behaviour == BEHAVIOUR_WANDER) { 2035 | enemies[e_count].dest_x = rand () % 16; 2036 | enemies[e_count].dest_y = rand () % 16; 2037 | } 2038 | enemies[e_count].aggression = enemy_anger + rand () % 3; 2039 | 2040 | /* put the enemy on the map */ 2041 | map[x][y] = 0x80 | ((enemies[e_count].type) * 0x10); 2042 | } 2043 | } 2044 | 2045 | /** 2046 | * Place the level's items 2047 | */ 2048 | void place_items (void) 2049 | { 2050 | int quick_inventory, /* a bit-encoded list of what the player has */ 2051 | items_list[6]; /* a list of items to place on this level */ 2052 | quick_inventory = get_quick_inventory (); 2053 | build_items_list (items_list, quick_inventory); 2054 | place_listed_items (items_list); 2055 | } 2056 | 2057 | /** 2058 | * Generate the drawn map from a new level. 2059 | */ 2060 | void generate_drawn_map (void) 2061 | { 2062 | int x, y; 2063 | for (x = 0; x < 16; ++x) 2064 | for (y = 0; y < 16; ++y) 2065 | update_map_tile (x, y, map[x][y]); 2066 | } 2067 | 2068 | /** 2069 | * Show the level number 2070 | */ 2071 | void show_level (void) 2072 | { 2073 | char level_text[9]; 2074 | sprintf (level_text, "LEVEL %02d", level); 2075 | display_heading (level_text); 2076 | } 2077 | 2078 | /** 2079 | * Show the map window 2080 | */ 2081 | void show_map (void) 2082 | { 2083 | display_map (hero_x, hero_y); 2084 | } 2085 | 2086 | /** 2087 | * Get and process player action 2088 | * @returns 1 if an action was successfully performed. 2089 | */ 2090 | int player_action (void) 2091 | { 2092 | /* local variables */ 2093 | int direction, 2094 | key, 2095 | option, 2096 | action = 0; /* changed to 1 if hero does something */ 2097 | 2098 | /* continue this loop till the player does something */ 2099 | do { 2100 | 2101 | /* see what the player wants to do */ 2102 | option = MENU_CANCEL; 2103 | key = get_keypress (); 2104 | 2105 | /* if this is a movement key, then move */ 2106 | direction = get_direction (key); 2107 | if (direction != DIR_NONE) 2108 | action = move_hero (direction); 2109 | 2110 | /* if this is a menu key, call up the menu */ 2111 | else if (key == 13 || key == 32) 2112 | option = main_menu (); 2113 | 2114 | /* respond to the various shortcut keys */ 2115 | else if (key == '?' || key == 'h') 2116 | option = MENU_HELP; 2117 | else if (key == '.') 2118 | option = MENU_WAIT; 2119 | else if (key == 'i') 2120 | option = MENU_INVENTORY; 2121 | else if (key == 't') 2122 | option = MENU_PICK_UP; 2123 | else if (key == 'e') 2124 | option = MENU_EAT; 2125 | else if (key == 'q') 2126 | option = MENU_QUAFF; 2127 | else if (key == 's' || key == '>') 2128 | option = MENU_DESCEND; 2129 | else if (key == 'n') 2130 | option = MENU_NEW_GAME; 2131 | else if (key == 'x' || key == 27) 2132 | option = MENU_EXIT; 2133 | 2134 | /* process a menu option */ 2135 | switch (option) { 2136 | case MENU_CANCEL: break; 2137 | case MENU_HELP: show_keys (); break; 2138 | case MENU_WAIT: action = wait_action (); break; 2139 | case MENU_INVENTORY: action = inventory_action (); break; 2140 | case MENU_PICK_UP: action = pick_up_item (); break; 2141 | case MENU_EAT: action = eat_something (); break; 2142 | case MENU_QUAFF: action = quaff_something (); break; 2143 | case MENU_DESCEND: action = descend_stairs (); break; 2144 | case MENU_NEW_GAME: confirm_new_game (); break; 2145 | case MENU_EXIT: confirm_exit (); break; 2146 | } 2147 | } while (! (action || level_over || game_over || game_quit)); 2148 | 2149 | /* return 1 if the screen needs updating after this action */ 2150 | return action; 2151 | } 2152 | 2153 | /** 2154 | * Generate and process enemy action 2155 | */ 2156 | void enemy_action (void) 2157 | { 2158 | /* local variables */ 2159 | int e; /* enemy counter */ 2160 | 2161 | /* loop through all the enemies */ 2162 | for (e = 0; e < 8; ++e) 2163 | if (enemies[e].health > 0) 2164 | individual_enemy_action (e); 2165 | } 2166 | 2167 | /** 2168 | * Generate and process the necromancer's action. 2169 | */ 2170 | void necro_action (void) 2171 | { 2172 | /* local variables */ 2173 | int attack, /* enemy's attack value */ 2174 | defence, /* hero's defence value */ 2175 | damage, /* damage caused */ 2176 | update; /* 1 if the screen needs updating */ 2177 | 2178 | /* if the player is not adjacent, do nothing */ 2179 | if (level < 24) 2180 | return; 2181 | if (abs (hero_x - necro_x) + abs (hero_y - necro_y) > 1) 2182 | return; 2183 | 2184 | /* determine attack and defence */ 2185 | attack = 20; 2186 | if (inventory[0] == ITEM_AMULET || inventory[1] == ITEM_AMULET) 2187 | defence = hero_intelligence + intelligence_modifier; 2188 | else 2189 | defence = hero_agility + agility_modifier; 2190 | 2191 | /* conduct the attack */ 2192 | damage = (1 + attack + dice (2)) - (defence + dice (2)); 2193 | if (damage < 0) 2194 | damage = 0; 2195 | 2196 | /* register the damage */ 2197 | hero_health -= damage; 2198 | if (hero_health < 0) 2199 | hero_health = 0; 2200 | update = 0; 2201 | 2202 | /* process a miss */ 2203 | if (! damage) 2204 | display_message ("SORCEROR MISSES "); 2205 | 2206 | /* process a non-fatal hit */ 2207 | else if (hero_health) { 2208 | display_message ("SORCEROR HIT YOU"); 2209 | display_health (hero_health, hero_strength + hero_agility 2210 | + hero_intelligence); 2211 | hit_noise (); 2212 | } 2213 | 2214 | /* process a fatal hit */ 2215 | else { 2216 | display_message ("SORCEROR HIT YOU"); 2217 | display_health (hero_health, hero_strength + hero_agility 2218 | + hero_intelligence); 2219 | map[hero_x][hero_y] = (map[hero_x][hero_y] & 0xf) | 0x10; 2220 | update_map_tile (hero_x, hero_y, map[hero_x][hero_y]); 2221 | game_over = 1; 2222 | } 2223 | } 2224 | 2225 | /** 2226 | * See if the level is over. 2227 | * @returns 1 if the level is over, 0 if not. 2228 | */ 2229 | int level_is_over (void) 2230 | { 2231 | return level_over 2232 | || game_quit 2233 | || game_over 2234 | || (hero_health == 0) 2235 | || (necro_health == 0); 2236 | } 2237 | 2238 | /** 2239 | * See if the game is over. 2240 | * @returns 1 if the game is over, 0 if not. 2241 | */ 2242 | int game_is_over (void) 2243 | { 2244 | return game_quit 2245 | || game_over 2246 | || (hero_health == 0) 2247 | || (necro_health == 0); 2248 | } 2249 | 2250 | /** 2251 | * Return a code to say who won the game, if anyone. 2252 | * @returns +1 if the hero won, -1 if the hero lost, 0 otherwise. 2253 | */ 2254 | int who_won (void) 2255 | { 2256 | return 2257 | (necro_health == 0) 2258 | - (hero_health == 0); 2259 | } 2260 | 2261 | /** 2262 | * See if user wants to quit. 2263 | * @returns 1 if the player wants to quit, 0 if not. 2264 | */ 2265 | int player_quit (void) 2266 | { 2267 | return game_quit; 2268 | } 2269 | 2270 | /** 2271 | * Return the player name. 2272 | * @returns pointer to player name. 2273 | */ 2274 | char *get_name (void) 2275 | { 2276 | return name; 2277 | } 2278 | 2279 | /** 2280 | * Return the player's gold 2281 | * @returns the gold 2282 | */ 2283 | int get_gold (void) 2284 | { 2285 | return gold; 2286 | } 2287 | 2288 | /** 2289 | * Return the level number. 2290 | * @returns the current level number. 2291 | */ 2292 | int get_level (void) 2293 | { 2294 | return level; 2295 | } 2296 | -------------------------------------------------------------------------------- /src/makegfx.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Graphics file generation. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | /* included headers */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "cgalib.h" 16 | 17 | /*---------------------------------------------------------------------- 18 | * File Level Variables. 19 | */ 20 | 21 | /** @var logo is the Cyningstan logo bitmap */ 22 | static Bitmap *logo; 23 | 24 | /** @var bitmap is the collection of bitmaps for the graphics file. */ 25 | static Bitmap *bitmap [30]; 26 | 27 | /** @var font is the font */ 28 | static Font *font; 29 | 30 | /** @var infile is the input file name */ 31 | static char *infile; 32 | 33 | /** @var outfile is the output file name */ 34 | static char *outfile; 35 | 36 | /** @var pic is the pixel data from the pic file */ 37 | static char *pic; 38 | 39 | /*---------------------------------------------------------------------- 40 | * Level 1 Routines. 41 | */ 42 | 43 | /** 44 | * Look for an input and an output file on the command line. 45 | * @param argc is the number of command line arguments. 46 | * @param argv is the command line arguments. 47 | */ 48 | static void parse_args (int argc, char **argv) 49 | { 50 | /* check for the correct number of arguments */ 51 | if (argc != 3) { 52 | printf ("Usage: %s INFILE OUTFILE\n", argv [0]); 53 | exit (0); 54 | } 55 | 56 | /* extract the filenames */ 57 | infile = argv [1]; 58 | outfile = argv [2]; 59 | } 60 | 61 | /** 62 | * Load the input file, which will be in PIC format. 63 | */ 64 | static void load_image (void) 65 | { 66 | FILE *input; 67 | char buffer[7]; 68 | if (! (input = fopen (infile, "rb"))) exit (1); 69 | if (! (fread (buffer, 7, 1, input))) exit (2); 70 | if (! (pic = malloc (16192))) exit (3); 71 | if (! (fread (pic, 16192, 1, input))) exit (4); 72 | fclose (input); 73 | } 74 | 75 | /** 76 | * Extract the graphics from the input file. 77 | */ 78 | static void extract_graphics (void) 79 | { 80 | int row, col, x, y, bit_no; 81 | Screen *screen; 82 | Bitmap *charbit; 83 | 84 | /* show screen */ 85 | screen = scr_create (5); 86 | scr_palette (screen, 2, 14); 87 | _fmemcpy ((void far *) 0xb8000000, pic, 16192); 88 | 89 | /* extract the tiles */ 90 | bit_no = 1; 91 | for (row = 0; row < 5; ++row) 92 | for (col = (row == 3 || row == 4) ? 8 : 0; col < 9; ++col) { 93 | x = 88 + 16 * col; 94 | y = 12 + 16 * row; 95 | if (! (bitmap[bit_no] = bit_create (16, 16))) { 96 | scr_destroy (screen); 97 | printf ("Cannot reserve memory for bitmap.\n"); 98 | exit (1); 99 | } 100 | scr_get (screen, bitmap[bit_no], x, y); 101 | ++bit_no; 102 | } 103 | 104 | /* extract the font */ 105 | if (! (font = fnt_create (32, 95))) { 106 | scr_destroy (screen); 107 | printf ("Out of memory creating font.\n"); 108 | exit (1); 109 | } 110 | if (! (charbit = bit_create (8, 8))) { 111 | scr_destroy (screen); 112 | printf ("Out of memory creating bitmap for character.\n"); 113 | exit (1); 114 | } 115 | for (row = 0; row < 4; ++row) 116 | for (col = 0; col < 16; ++col) { 117 | scr_get (screen, charbit, 88 + 8 * col, 60 + 8 * row); 118 | fnt_put (font, charbit, 32 + col + 16 * row); 119 | } 120 | bit_destroy (charbit); 121 | 122 | /* extract the logo */ 123 | if (! (logo = bit_create (128, 16))) { 124 | scr_destroy (screen); 125 | printf ("Cannot reserve memory for logo.\n"); 126 | exit (1); 127 | } 128 | scr_get (screen, logo, 88, 92); 129 | 130 | /* extract the background screen */ 131 | scr_ink (screen, 2); 132 | scr_box (screen, 88, 12, 144, 144); 133 | if (! (bitmap[0] = bit_create (320, 200))) { 134 | scr_destroy (screen); 135 | exit (6); 136 | } 137 | scr_get (screen, bitmap[0], 0, 0); 138 | 139 | /* return to text mode */ 140 | scr_destroy (screen); 141 | } 142 | 143 | /** 144 | * Save the graphics to the output file 145 | */ 146 | static void save_graphics (void) 147 | { 148 | FILE *output; 149 | int c; 150 | if (! (output = fopen (outfile, "wb"))) exit (7); 151 | fwrite ("OSS100D", 8, 1, output); 152 | bit_write (logo, output); 153 | for (c = 0; c < 30; ++c) 154 | bit_write (bitmap[c], output); 155 | fnt_write (font, output); 156 | fclose (output); 157 | } 158 | 159 | /*---------------------------------------------------------------------- 160 | * Level 0 Routines. 161 | */ 162 | 163 | /** 164 | * Main Program. 165 | * @param argc is the number of command line arguments. 166 | * @param argv is the command line arguments. 167 | */ 168 | void main (int argc, char **argv) 169 | { 170 | parse_args (argc, argv); 171 | load_image (); 172 | extract_graphics (); 173 | save_graphics (); 174 | } 175 | -------------------------------------------------------------------------------- /src/ossuary.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Main game source file. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 22-Jun-2020. 8 | */ 9 | 10 | /* included compiler headers */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /* included project headers */ 20 | #include "display.h" 21 | #include "game.h" 22 | #include "scores.h" 23 | #include "errors.h" 24 | 25 | /*---------------------------------------------------------------------- 26 | * File-level variables. 27 | */ 28 | 29 | /** @var mono is 1 if monochrome graphics were requested. */ 30 | static int mono; 31 | 32 | /** @var palette is 1 if standard palette was requested */ 33 | static int palette; 34 | 35 | /*---------------------------------------------------------------------- 36 | * Level 2 Routines 37 | */ 38 | 39 | /** 40 | * Check that the beta test version is not expired. 41 | * @param expiry is the expiry date, YYYYMMDD format. 42 | * @returns 1 if the beta is not expired. 43 | */ 44 | static int beta_time_check (char *expiry) 45 | { 46 | time_t time_of_day; 47 | struct tm *full_time; 48 | char time_text[9]; 49 | time_of_day = time (NULL); 50 | full_time = gmtime (&time_of_day); 51 | sprintf (time_text, "%04d%02d%02d", 1900 + full_time->tm_year, 52 | 1 + full_time->tm_mon, full_time->tm_mday); 53 | return (strcmp (time_text, expiry) < 0); 54 | } 55 | 56 | /** 57 | * Initialise options on according to the command line. 58 | */ 59 | static int init_options (int argc, char **argv) 60 | { 61 | /* local variables */ 62 | int a; /* argument counter */ 63 | 64 | /* check the arguments */ 65 | for (a = 1; a < argc; ++a) 66 | if (! strcmp (argv[a], "-m")) 67 | mono = 1; 68 | else if (! strcmp (argv[a], "-p")) 69 | palette = 1; 70 | else 71 | return 0; 72 | 73 | /* all successful */ 74 | return 1; 75 | } 76 | 77 | /*---------------------------------------------------------------------- 78 | * Level 1 Routines 79 | */ 80 | 81 | /** 82 | * Initialise the program. 83 | * @returns 1 if successful, 0 if not. 84 | */ 85 | static int initialise (int argc, char **argv) 86 | { 87 | if (! (beta_time_check ("99999999"))) exit_game (5); 88 | if (! (init_options (argc, argv))) exit_game (4); 89 | if (! (init_screen (mono, palette))) exit_game (1); 90 | if (! (load_graphics ())) exit_game (3); 91 | load_scores (); 92 | srand (time (NULL)); 93 | return 1; 94 | } 95 | 96 | /** 97 | * Create a new game. 98 | */ 99 | static void new_game (void) 100 | { 101 | init_game (); 102 | generate_hero (); 103 | init_inventory (); 104 | show_stats (); 105 | show_gold (); 106 | show_inventory (); 107 | show_scores (); 108 | ask_name (); 109 | } 110 | 111 | /** 112 | * Create a new level. 113 | */ 114 | static void new_level (void) 115 | { 116 | generate_map (); 117 | place_hero (); 118 | place_objective (); 119 | place_enemies (); 120 | place_items (); 121 | generate_drawn_map (); 122 | show_level (); 123 | show_map (); 124 | blank_message (); 125 | if (get_level () == 1) 126 | display_message ("PRESS ? FOR KEYS"); 127 | } 128 | 129 | /** 130 | * Play through a single level. 131 | * @returns 1 if the game is over, 0 if not. 132 | */ 133 | static int play_level (void) 134 | { 135 | /* Continue moving player and enemies until the level is over */ 136 | do { 137 | player_action (); 138 | if (! level_is_over ()) { 139 | enemy_action (); 140 | necro_action (); 141 | } 142 | show_map (); 143 | } while (! level_is_over ()); 144 | 145 | /* reset the keyboard and return */ 146 | return game_is_over (); 147 | } 148 | 149 | /** 150 | * Do the End Game things: high score table and play again query. 151 | * returns 1 if the player wants to finish, 0 if not. 152 | */ 153 | static int end_game (void) 154 | { 155 | switch (who_won ()) { 156 | case -1: 157 | display_game_over ("YOU HAVE", " DIED "); 158 | break; 159 | case +1: 160 | display_game_over ("YOU HAVE", " WON! "); 161 | add_score (get_name (), get_gold ()); 162 | break; 163 | } 164 | return player_quit (); 165 | } 166 | 167 | /** 168 | * Clean up when the program is finished. 169 | */ 170 | static void clean_up (void) 171 | { 172 | save_scores (); 173 | clean_up_display (); 174 | } 175 | 176 | /*---------------------------------------------------------------------- 177 | * Level 0 Routines 178 | */ 179 | 180 | /** 181 | * Main Program. 182 | * @param argc is the number of command line arguments. 183 | * @param argv is the command line arguments. 184 | */ 185 | void main (int argc, char **argv) 186 | { 187 | /* local variables */ 188 | int game_finished, /* 1 if user quits, wins or loses the game */ 189 | program_finished; /* 1 if user quits the program */ 190 | 191 | /* main program control */ 192 | initialise (argc, argv); 193 | do { 194 | new_game (); 195 | do { 196 | new_level (); 197 | game_finished = play_level (); 198 | } while (! game_finished); 199 | program_finished = end_game (); 200 | } while (! program_finished); 201 | clean_up (); 202 | } 203 | -------------------------------------------------------------------------------- /src/scores.c: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------- 2 | * Ossuary: 3 | * A DOS port of the ZX Spectrum rogue-like. 4 | * Score handling module. 5 | * 6 | * Copyright (C) Damian Gareth Walker 2013, 2020. 7 | * Created: 16-Jul-2020. 8 | */ 9 | 10 | /* includes */ 11 | #include 12 | #include 13 | #include 14 | #include "display.h" 15 | #include "scores.h" 16 | 17 | /*---------------------------------------------------------------------- 18 | * Data Definitions. 19 | */ 20 | 21 | /** @struct score is a single high score. */ 22 | typedef struct score Score; 23 | struct score { 24 | char name[11]; /* player name */ 25 | int gold; /* gold collected */ 26 | }; 27 | 28 | /*---------------------------------------------------------------------- 29 | * File Level Variables. 30 | */ 31 | 32 | /** @var scores is the high score table. */ 33 | static Score scores[18]; 34 | 35 | /** @var last_score is the row of the last score inserted */ 36 | static int last_score = -1; 37 | 38 | /** @var scores_changed is 1 if the scores have changed */ 39 | static int scores_changed = 0; 40 | 41 | /*---------------------------------------------------------------------- 42 | * Level 1 Private Functions. 43 | */ 44 | 45 | /** 46 | * Load scores from the high score file. 47 | * Returns 0 on success. 48 | */ 49 | static int read_scores (void) 50 | { 51 | /* local variables */ 52 | FILE *input; /* input file handle */ 53 | char name[11], /* name read from input file */ 54 | header[8], /* header read from input file */ 55 | len; /* name length read from input file */ 56 | int gold, /* gold read from input file */ 57 | c; /* score counter */ 58 | 59 | /* attempt to open file */ 60 | if (! (input = fopen ("ossuary.sco", "rb"))) 61 | return 0; 62 | 63 | /* attempt to read header */ 64 | if (! fread (header, 8, 1, input)) { 65 | fclose (input); 66 | return 0; 67 | } 68 | 69 | /* verify header */ 70 | if (strcmp (header, "OSS100S")) { 71 | fclose (input); 72 | return 0; 73 | } 74 | 75 | /* read the scores */ 76 | for (c = 0; c < 18; ++c) { 77 | if (! fread (&len, 1, 1, input)) { 78 | fclose (input); 79 | return 0; 80 | } 81 | if (! fread (name, len, 1, input)) { 82 | fclose (input); 83 | return 0; 84 | } 85 | name[(int) len] = '\0'; 86 | if (! fread (&gold, 2, 1, input)) { 87 | fclose (input); 88 | return 0; 89 | } 90 | strcpy (scores[c].name, name); 91 | scores[c].gold = gold; 92 | } 93 | 94 | /* successful! */ 95 | fclose (input); 96 | return 1; 97 | } 98 | 99 | /** 100 | * Generate new high score table. 101 | */ 102 | static void create_scores (void) 103 | { 104 | /* local variables */ 105 | int c; /* score counter */ 106 | 107 | /* fill score table with Cyningstan */ 108 | for (c = 0; c < 18; ++c) { 109 | strcpy (scores[c].name, "CYNINGSTAN"); 110 | scores[c].gold = 0; 111 | } 112 | 113 | /* these scores want saving */ 114 | scores_changed = 1; 115 | } 116 | 117 | /*---------------------------------------------------------------------- 118 | * Public Level Functions. 119 | */ 120 | 121 | /** 122 | * Load or generate the high score table. 123 | */ 124 | void load_scores (void) 125 | { 126 | if (! read_scores ()) 127 | create_scores (); 128 | } 129 | 130 | /** 131 | * Show the high score table. 132 | */ 133 | void show_scores (void) 134 | { 135 | /* local variables */ 136 | int c; /* score counter */ 137 | 138 | /* show the display */ 139 | display_heading (" SCORES "); 140 | for (c = 0; c < 18; ++c) 141 | display_score (c, scores[c].name, scores[c].gold, 142 | c == last_score); 143 | display_text (); 144 | } 145 | 146 | /** 147 | * Save the scores at the end of the game (if changed) 148 | */ 149 | void save_scores (void) 150 | { 151 | /* local variables */ 152 | FILE *output; /* output file handle */ 153 | char len; /* name length to write to file */ 154 | int c; /* score counter */ 155 | 156 | /* if the scores haven't changed, don't save them */ 157 | if (! scores_changed) 158 | return; 159 | 160 | /* create the file and write the header */ 161 | if (! (output = fopen ("OSSUARY.SCO", "wb"))) 162 | return; 163 | fwrite ("OSS100S", 8, 1, output); 164 | 165 | /* loop through the scores */ 166 | for (c = 0; c < 18; ++c) { 167 | len = strlen (scores[c].name); 168 | fwrite (&len, 1, 1, output); 169 | fwrite (scores[c].name, len, 1, output); 170 | fwrite (&scores[c].gold, 2, 1, output); 171 | } 172 | 173 | /* close the file */ 174 | fclose (output); 175 | } 176 | 177 | /** 178 | * Consider adding a score to the high score table. 179 | * @param name is the player name. 180 | * @param gold is the amount of gold. 181 | */ 182 | void add_score (char *name, int gold) 183 | { 184 | /* local variables */ 185 | int c; /* score counter */ 186 | 187 | /* don't insert a score if they have no name */ 188 | if (! *name) 189 | return; 190 | 191 | /* look for a slot to insert the score */ 192 | for (c = 0; c < 18; ++c) 193 | if (gold > scores[c].gold) 194 | break; 195 | 196 | /* return now if score was not high enough */ 197 | if (c == 18) 198 | return; 199 | 200 | /* shuffle lower scores down the table */ 201 | last_score = c; 202 | for (c = 17; c > last_score; --c) 203 | scores[c] = scores[c - 1]; 204 | 205 | /* insert this score */ 206 | strcpy (scores[last_score].name, name); 207 | scores[last_score].gold = gold; 208 | scores_changed = 1; 209 | } 210 | -------------------------------------------------------------------------------- /src/screen.c: -------------------------------------------------------------------------------- 1 | /*====================================================================== 2 | * CGALib - Watcom C Version. 3 | * Screen Handling Module. 4 | * 5 | * Copyright (C) Damian Walker 2020. 6 | * Created 29-Jun-2020. 7 | */ 8 | 9 | /* define CGALIB for access to internal structures */ 10 | #define __CGALIB__ 11 | 12 | /* headers required for references to data types */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "cgalib.h" 18 | 19 | /*---------------------------------------------------------------------- 20 | * Level 1 Functions. 21 | */ 22 | 23 | /** 24 | * Set the display mode. 25 | * @params mode is the mode to select. 26 | */ 27 | static void set_mode (Screen *screen) 28 | { 29 | /* local variables */ 30 | union REGS regs; 31 | 32 | /* use the BIOS to set the mode. */ 33 | regs.h.ah = 0; 34 | regs.h.al = screen->mode; 35 | int86 (0x10, ®s, ®s); 36 | } 37 | 38 | /** 39 | * Sets the desired screen colours using the CGA palette register. 40 | * This works only on actual CGA cards. These palette registers are 41 | * ignored by EGA and VGA cards, which have independent control of the 42 | * two or four screen colours. 43 | */ 44 | static void palette_cga (Screen *screen) 45 | { 46 | /* registers */ 47 | char mode_control; 48 | char colour_control; 49 | 50 | /* don't do any of this if we're in monochrome mode */ 51 | if (screen->mode == 6) return; 52 | 53 | /* set the mode according to the palette chosen */ 54 | screen->mode = ((screen->palette % 3) == 2) ? 5 : 4; 55 | 56 | /* initialise the registers */ 57 | mode_control = 0; 58 | colour_control = 0; 59 | 60 | /* set the mode control register */ 61 | mode_control |= 0x8; /* show display */ 62 | mode_control |= (screen->mode == 5) ? 0x4 : 0; /* greyscale? */ 63 | mode_control |= 0x2; /* graphics mode */ 64 | 65 | /* set the colour control register */ 66 | colour_control |= (screen->palette % 3) ? 0x20 : 0; /* palette */ 67 | colour_control |= (screen->palette / 3) ? 0x10 : 0; /* intensity */ 68 | colour_control |= screen->colour; /* colour choice */ 69 | 70 | /* set the CGA registers */ 71 | outp (0x3d8, mode_control); 72 | outp (0x3d9, colour_control); 73 | } 74 | 75 | /** 76 | * Sets the screen colours using the EGA palette registers. 77 | * Because EGA and VGA cards ignore the CGA palette registers, we need 78 | * to address these cards directly if we want to see the same colour 79 | * palette on these cards as we do on a CGA display. This function just 80 | * simulates the available CGA palettes, it does not support the actual 81 | * flexibility of a 4-colour EGA/VGA palette. 82 | */ 83 | static void palette_ega (Screen *screen) 84 | { 85 | union REGS regs; 86 | static int background[16] = { /* background colours */ 87 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 88 | 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f 89 | }; 90 | static int foreground[6][3] = { /* table of 320x200 mode colours */ 91 | {0x02, 0x04, 0x06}, /* mode 4 palette 0 bright 0 */ 92 | {0x03, 0x05, 0x07}, /* mode 4 palette 1 bright 0 */ 93 | {0x03, 0x04, 0x07}, /* mode 5 palette 2 bright 0 */ 94 | {0x3a, 0x3c, 0x3e}, /* mode 4 palette 0 bright 1 */ 95 | {0x3b, 0x3d, 0x3f}, /* mode 4 palette 1 bright 1 */ 96 | {0x3b, 0x3c, 0x3f}, /* mode 5 palette 2 bright 1 */ 97 | }; 98 | int fgcount; /* count of foreground colours */ 99 | 100 | /* background colour */ 101 | regs.w.ax = 0x1000; 102 | regs.w.bx = 0x100 * background[screen->colour]; 103 | int86 (0x10, ®s, ®s); 104 | 105 | /* foreground colours */ 106 | for (fgcount = 0; fgcount <= 2; ++fgcount) { 107 | regs.w.ax = 0x1000; 108 | regs.w.bx = 0x100 * foreground[screen->palette][fgcount] 109 | + fgcount + 1; 110 | int86 (0x10, ®s, ®s); 111 | } 112 | } 113 | 114 | /*---------------------------------------------------------------------- 115 | * Public Level Functions. 116 | */ 117 | 118 | /** 119 | * Initialise the screen, and set its initial screen mode. 120 | * @param mode is the screen mode: 4, 5 or 6. 121 | * @returns the new screen. 122 | */ 123 | Screen *scr_create (int mode) 124 | { 125 | /* local variables */ 126 | Screen *screen; 127 | 128 | /* initialise the screen parameters */ 129 | if (! (screen = malloc (sizeof (Screen)))) 130 | return NULL; 131 | screen->mode = mode; 132 | screen->palette = (mode == 5) ? 5 : 4; 133 | screen->colour = 0; 134 | screen->ink = 3; 135 | screen->paper = 0; 136 | screen->font = NULL; 137 | 138 | /* Set the screen mode and palette */ 139 | set_mode (screen); 140 | palette_cga (screen); 141 | palette_ega (screen); 142 | 143 | /* return the new screen */ 144 | return screen; 145 | } 146 | 147 | /** 148 | * Set the screen palette. 149 | * @param screen is the screen to affect. 150 | * @param p is the palette number, 0..5. 151 | * @param c is the background colour, 0..15. 152 | */ 153 | void scr_palette (Screen *screen, int palette, int colour) 154 | { 155 | /* update the palette and colour in the screen data */ 156 | screen->palette = palette; 157 | screen->colour = colour; 158 | 159 | /* update the palette and colour on the screen */ 160 | palette_cga (screen); 161 | palette_ega (screen); 162 | } 163 | 164 | /** 165 | * Put a bitmap onto the screen. 166 | * @param dst is the screen to affect. 167 | * @param src is the source bitmap. 168 | * @param x is the x coordinate at which the bitmap is to be placed. 169 | * @param y is the y coordinate at which the bitmap is to be placed. 170 | * @param d is the draw mode. 171 | */ 172 | void scr_put (Screen *dst, Bitmap *src, int x, int y, DrawMode draw) 173 | { 174 | /* local variables */ 175 | char far *d; /* address to copy data to */ 176 | char *s; /* address to copy data from */ 177 | int r; /* row counter */ 178 | int b; /* byte counter */ 179 | 180 | /* copy the pixels */ 181 | for (r = 0; r < src->height; ++r) 182 | 183 | /* DRAW_PSET can be copied by a quicker method */ 184 | if (draw == DRAW_PSET) { 185 | d = (r % 2) 186 | ? x / 4 + (y + r - 1) * 40 + (char far *) 0xb8002000 187 | : x / 4 + (y + r) * 40 + (char far *) 0xb8000000; 188 | s = src->pixels + src->width / 4 * r; 189 | _fmemcpy (d, s, src->width / 4); 190 | } 191 | 192 | /* the other draw operations need doing byte by byte */ 193 | else 194 | for (b = 0; b < src->width / 4; ++b) { 195 | d = b + ((r % 2) 196 | ? x / 4 + (y + r - 1) * 40 + (char far *) 0xb8002000 197 | : x / 4 + (y + r) * 40 + (char far *) 0xb8000000); 198 | s = b + src->pixels + src->width / 4 * r; 199 | switch (draw) { 200 | case DRAW_PRESET: 201 | *d = ~*s; 202 | break; 203 | case DRAW_AND: 204 | *d &= *s; 205 | break; 206 | case DRAW_OR: 207 | *d |= *s; 208 | break; 209 | case DRAW_XOR: 210 | *d ^= *s; 211 | break; 212 | } 213 | } 214 | } 215 | 216 | /** 217 | * Get a bitmap from the screen. 218 | * @param src is the screen from which to take the bitmap. 219 | * @param dst is the destination bitmap, whose size is already set. 220 | * @param x is the x coordinate where the desired pattern lies. 221 | * @param y is the y coordinate where the desired pattern lies. 222 | */ 223 | void scr_get (Screen *src, Bitmap *dst, int x, int y) 224 | { 225 | /* local variables */ 226 | char far *s; /* address to copy data from */ 227 | char *d; /* address to copy data to */ 228 | int r; /* row counter */ 229 | 230 | /* copy the pixels */ 231 | for (r = 0; r < dst->height; ++r) { 232 | s = (r % 2) 233 | ? x / 4 + (y + r - 1) * 40 + (char far *) 0xb8002000 234 | : x / 4 + (y + r) * 40 + (char far *) 0xb8000000; 235 | d = dst->pixels + dst->width / 4 * r; 236 | _fmemcpy (d, s, dst->width / 4); 237 | } 238 | } 239 | 240 | /** 241 | * Draw a box on the screen, filled in the current ink colour. 242 | * @param screen is the screen to affect. 243 | * @param x is the x coordinate of the top left of the box. 244 | * @param y is the y coordinate of the top left of the box. 245 | * @param width is the width of the box. 246 | * @param height is the height of the box. 247 | * The draw mode is always DRAW_PUT. For anything more sophisticated, 248 | * the scr_put() function should be used. 249 | */ 250 | void scr_box (Screen *screen, int x, int y, int width, int height) 251 | { 252 | /* local variables */ 253 | char v; /* value to write to the screen */ 254 | int r; /* row counter */ 255 | char far *d; /* address to write to */ 256 | 257 | /* determine the byte value that will fill the box */ 258 | v = screen->ink * 0x55; 259 | 260 | /* fill each individual row */ 261 | for (r = 0; r < height; ++r) { 262 | d = (r % 2) 263 | ? x / 4 + (y + r - 1) * 40 + (char far *) 0xb8002000 264 | : x / 4 + (y + r) * 40 + (char far *) 0xb8000000; 265 | _fmemset (d, v, width / 4); 266 | } 267 | } 268 | 269 | /** 270 | * Print some text on the screen in the current ink colour. 271 | * @param screen is the screen to affect. 272 | * @param x is the x coordinate where the text should appear. 273 | * @param y is the y coordinate where the text should appear. 274 | * @param message is the message to print. 275 | * The text is printed in a box of the paper colour. 276 | */ 277 | void scr_print (Screen *screen, int x, int y, char *message) 278 | { 279 | /* local variables */ 280 | int b; /* character pointer */ 281 | int r; /* row of character */ 282 | int v; /* value of byte in character */ 283 | int far *d; /* pointer to destination byte on screen */ 284 | 285 | /* only try to print if a font is selected */ 286 | if (! screen->font) return; 287 | 288 | /* print each character */ 289 | for (b = 0; message[b]; ++b) 290 | for (r = 0; r < 8; ++r) { 291 | d = (int far *) (2 * b + ((r % 2) 292 | ? x / 4 + (y + r - 1) * 40 + (char far *) 0xb8002000 293 | : x / 4 + (y + r) * 40 + (char far *) 0xb8000000)); 294 | v = screen->font->pixels[2 * r + 16 * (message[b] - 295 | screen->font->first)] + 0x100 * screen->font->pixels[1 296 | + 2 * r + 16 * (message[b] - screen->font->first)]; 297 | if (screen->ink != 3 || screen->paper != 0) 298 | v = (v & 0x5555 * screen->ink) 299 | | ((0xffff ^ v) & 0x5555 * screen->paper); 300 | *d = v; 301 | } 302 | } 303 | 304 | /** 305 | * Set the ink colour for scr_box and scr_print operations. 306 | * @param screen is the screen to affect. 307 | * @param ink is the colour to use, 0..3. 308 | */ 309 | void scr_ink (Screen *screen, int ink) 310 | { 311 | screen->ink = ink; 312 | } 313 | 314 | /** 315 | * Set the paper colour for scr_print operations. 316 | * @param screen is the screen to affect. 317 | * @param paper is the colour to use, 0..3. 318 | */ 319 | void scr_paper (Screen *screen, int paper) 320 | { 321 | screen->paper = paper; 322 | } 323 | 324 | /** 325 | * Set the font for scr_print operations. 326 | * @param screen is the screen to affect. 327 | * @param font is the font to use. 328 | */ 329 | void scr_font (Screen *screen, Font *font) 330 | { 331 | screen->font = font; 332 | } 333 | 334 | /** 335 | * Reset the screen back to text mode which graphic output is finished. 336 | * @param screen is the screen to affect. 337 | */ 338 | void scr_destroy (Screen *screen) 339 | { 340 | screen->mode = 3; 341 | set_mode (screen); 342 | free (screen); 343 | } 344 | --------------------------------------------------------------------------------