Source:NetHack 3.4.3/src/rip.c

From NetHackWiki
(Redirected from Source:Ref/center)
Jump to: navigation, search

Below is the full text to src/rip.c from NetHack 3.4.3. To link to a particular line, write [[rip.c#line123]], for example.

Top of file

  1. /*	SCCS Id: @(#)rip.c	3.4	2003/01/08	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2.  
  3. STATIC_DCL void FDECL(center, (int, char *));
  4.  
  5. extern const char * const killed_by_prefix[];	/* from topten.c */
  6.  
  7. #if defined(TTY_GRAPHICS) || defined(X11_GRAPHICS) || defined(GEM_GRAPHICS) || defined(MSWIN_GRAPHICS)
  8. # define TEXT_TOMBSTONE
  9. #endif
  10. #if defined(mac) || defined(__BEOS__) || defined(WIN32_GRAPHICS)
  11. # ifndef TEXT_TOMBSTONE
  12. #  define TEXT_TOMBSTONE
  13. # endif
  14. #endif
  15.  
  16. #ifdef TEXT_TOMBSTONE
  17.  
  18. #ifndef NH320_DEDICATION
  19. /* A normal tombstone for end of game display. */
  20. static const char *rip_txt[] = {
  21. "                       ----------",
  22. "                      /          \\",
  23. "                     /    REST    \\",
  24. "                    /      IN      \\",
  25. "                   /     PEACE      \\",
  26. "                  /                  \\",
  27. "                  |                  |", /* Name of player */
  28. "                  |                  |", /* Amount of $ */
  29. "                  |                  |", /* Type of death */
  30. "                  |                  |", /* . */
  31. "                  |                  |", /* . */
  32. "                  |                  |", /* . */
  33. "                  |       1001       |", /* Real year of death */
  34. "                 *|     *  *  *      | *",
  35. "        _________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
  36. 0
  37. };
  38. #define STONE_LINE_CENT 28	/* char[] element of center of stone face */
  39. #else	/* NH320_DEDICATION */
  40. /* NetHack 3.2.x displayed a dual tombstone as a tribute to Izchak. */
  41. static const char *rip_txt[] = {
  42. "              ----------                      ----------",
  43. "             /          \\                    /          \\",
  44. "            /    REST    \\                  /    This    \\",
  45. "           /      IN      \\                /  release of  \\",
  46. "          /     PEACE      \\              /   NetHack is   \\",
  47. "         /                  \\            /   dedicated to   \\",
  48. "         |                  |            |  the memory of   |",
  49. "         |                  |            |                  |",
  50. "         |                  |            |  Izchak Miller   |",
  51. "         |                  |            |   1935 - 1994    |",
  52. "         |                  |            |                  |",
  53. "         |                  |            |     Ascended     |",
  54. "         |       1001       |            |                  |",
  55. "      *  |     *  *  *      | *        * |      *  *  *     | *",
  56. " _____)/\\|\\__//(\\/(/\\)/\\//\\/|_)________)/|\\\\_/_/(\\/(/\\)/\\/\\/|_)____",
  57. 0
  58. };
  59. #define STONE_LINE_CENT 19	/* char[] element of center of stone face */
  60. #endif	/* NH320_DEDICATION */
  61. #define STONE_LINE_LEN 16	/* # chars that fit on one line
  62. 				 * (note 1 ' ' border)
  63. 				 */
  64. #define NAME_LINE 6		/* *char[] line # for player name */
  65. #define GOLD_LINE 7		/* *char[] line # for amount of gold */
  66. #define DEATH_LINE 8		/* *char[] line # for death description */
  67. #define YEAR_LINE 12		/* *char[] line # for year */
  68.  
  69. static char **rip;

center

  1. STATIC_OVL void
  2. center(line, text)
  3. int line;
  4. char *text;
  5. {
  6. 	register char *ip,*op;
  7. 	ip = text;
  8. 	op = &rip[line][STONE_LINE_CENT - ((strlen(text)+1)>>1)];
  9. 	while(*ip) *op++ = *ip++;
  10. }

genl_outrip

  1. void
  2. genl_outrip(tmpwin, how)
  3. winid tmpwin;
  4. int how;
  5. {
  6. 	register char **dp;
  7. 	register char *dpx;
  8. 	char buf[BUFSZ];
  9. 	register int x;
  10. 	int line;
  11.  
  12. 	rip = dp = (char **) alloc(sizeof(rip_txt));
  13. 	for (x = 0; rip_txt[x]; x++) {
  14. 		dp[x] = (char *) alloc((unsigned int)(strlen(rip_txt[x]) + 1));
  15. 		Strcpy(dp[x], rip_txt[x]);
  16. 	}
  17. 	dp[x] = (char *)0;
  18.  
  19. 	/* Put name on stone */
  20. 	Sprintf(buf, "%s", plname);
  21. 	buf[STONE_LINE_LEN] = 0;
  22. 	center(NAME_LINE, buf);
  23.  
  24. 	/* Put $ on stone */
  25. #ifndef GOLDOBJ
  26. 	Sprintf(buf, "%ld Au", u.ugold);
  27. #else
  28. 	Sprintf(buf, "%ld Au", done_money);
  29. #endif
  30. 	buf[STONE_LINE_LEN] = 0; /* It could be a *lot* of gold :-) */
  31. 	center(GOLD_LINE, buf);
  32.  
  33. 	/* Put together death description */
  34. 	switch (killer_format) {
  35. 		default: impossible("bad killer format?");
  36. 		case KILLED_BY_AN:
  37. 			Strcpy(buf, killed_by_prefix[how]);
  38. 			Strcat(buf, an(killer));
  39. 			break;
  40. 		case KILLED_BY:
  41. 			Strcpy(buf, killed_by_prefix[how]);
  42. 			Strcat(buf, killer);
  43. 			break;
  44. 		case NO_KILLER_PREFIX:
  45. 			Strcpy(buf, killer);
  46. 			break;
  47. 	}
  48.  
  49. 	/* Put death type on stone */
  50. 	for (line=DEATH_LINE, dpx = buf; line<YEAR_LINE; line++) {
  51. 		register int i,i0;
  52. 		char tmpchar;
  53.  
  54. 		if ( (i0=strlen(dpx)) > STONE_LINE_LEN) {
  55. 				for(i = STONE_LINE_LEN;
  56. 				    ((i0 > STONE_LINE_LEN) && i); i--)
  57. 					if(dpx[i] == ' ') i0 = i;
  58. 				if(!i) i0 = STONE_LINE_LEN;
  59. 		}
  60. 		tmpchar = dpx[i0];
  61. 		dpx[i0] = 0;
  62. 		center(line, dpx);
  63. 		if (tmpchar != ' ') {
  64. 			dpx[i0] = tmpchar;
  65. 			dpx= &dpx[i0];
  66. 		} else  dpx= &dpx[i0+1];
  67. 	}
  68.  
  69. 	/* Put year on stone */
  70. 	Sprintf(buf, "%4d", getyear());
  71. 	center(YEAR_LINE, buf);
  72.  
  73. 	putstr(tmpwin, 0, "");
  74. 	for(; *dp; dp++)
  75. 		putstr(tmpwin, 0, *dp);
  76.  
  77. 	putstr(tmpwin, 0, "");
  78. 	putstr(tmpwin, 0, "");
  79.  
  80. 	for (x = 0; rip_txt[x]; x++) {
  81. 		free((genericptr_t)rip[x]);
  82. 	}
  83. 	free((genericptr_t)rip);
  84. 	rip = 0;
  85. }
  86.  
  87. #endif	/* TEXT_TOMBSTONE */
  88.  
  89. /*rip.c*/