1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
/*
* PROPRIETARY INFORMATION. This software is proprietary to POWDER
* Development, and is not to be reproduced, transmitted, or disclosed
* in any way without written permission.
*
* Produced by: Jeff Lait
*
* POWDER Development
*
* NAME: encyc_support.cpp ( POWDER Library, C++ )
*
* COMMENTS: This defines support functions for the encyclopedia.
*/
#include "glbdef.h"
#include <stdio.h>
#include "grammar.h"
#include "gfxengine.h"
#include "encyclopedia.h"
#include "encyc_support.h"
//
// Purely internal functions:
//
const encyclopedia_entry *
encyc_getentry(const char *bookname, int key)
{
const encyclopedia_book *book;
int booknum;
int entrynum;
for (booknum = 0; booknum < NUM_ENCYCLOPEDIA_BOOKS; booknum++)
{
book = glb_encyclopedia[booknum];
if (strcmp(book->bookname, bookname))
continue;
for (entrynum = 0; entrynum < book->numentries; entrynum++)
{
if (book->entries[entrynum]->key == key)
return book->entries[entrynum];
}
}
return 0;
}
//
// Externally available functions:
//
bool
encyc_hasentry(const char *book, int key)
{
const encyclopedia_entry *entry;
entry = encyc_getentry(book, key);
if (entry)
return true;
return false;
}
void
encyc_pageentry(const char *book, int key)
{
const encyclopedia_entry *entry;
int i;
entry = encyc_getentry(book, key);
// Nothing to view? Quit.
if (!entry)
return;
// Build word-wrapped display list.
for (i = 0; i < entry->numlines; i++)
{
gfx_pager_addtext(entry->lines[i]);
gfx_pager_newline();
}
}
void
encyc_viewentry(const char *book, int key)
{
const encyclopedia_entry *entry;
entry = encyc_getentry(book, key);
// Nothing to view? Quit.
if (!entry)
return;
encyc_pageentry(book, key);
gfx_pager_display();
}
void
encyc_viewSpellDescription(SPELL_NAMES spell)
{
BUF buf;
// Plain description:
gfx_pager_addtext(glb_spelldefs[spell].name);
gfx_pager_newline();
// Add standard spell stuff
gfx_pager_separator();
if (glb_spelldefs[spell].mpcost)
{
buf.sprintf("Magic Cost: %d", glb_spelldefs[spell].mpcost);
gfx_pager_addtext(buf);
gfx_pager_newline();
}
if (glb_spelldefs[spell].hpcost)
{
buf.sprintf("Health Cost: %d", glb_spelldefs[spell].hpcost);
gfx_pager_addtext(buf);
gfx_pager_newline();
}
if (glb_spelldefs[spell].xpcost)
{
buf.sprintf("EXP Cost: %d", glb_spelldefs[spell].xpcost);
gfx_pager_addtext(buf);
gfx_pager_newline();
}
buf.sprintf("Circle: ");
buf.strcat(gram_capitalize(glb_spelltypedefs[glb_spelldefs[spell].type].name));
gfx_pager_addtext(buf);
gfx_pager_newline();
// Output any prereqs.
const u8 *prereq;
prereq = (const u8 *) glb_spelldefs[spell].prereq;
if (prereq && *prereq)
{
gfx_pager_addtext("This requires ");
while (*prereq)
{
gfx_pager_addtext(glb_spelldefs[*prereq].name);
prereq++;
if (*prereq)
{
if (!prereq[1])
gfx_pager_addtext(" and ");
else
gfx_pager_addtext(", ");
}
}
gfx_pager_addtext(".");
gfx_pager_newline();
}
// Add encyclopedia entry, if any.
{
const encyclopedia_entry *entry;
entry = encyc_getentry("SPELL", spell);
if (entry)
{
gfx_pager_separator();
encyc_pageentry("SPELL", spell);
}
}
gfx_pager_display();
}
void
encyc_viewSkillDescription(SKILL_NAMES skill)
{
// Plain description:
gfx_pager_addtext(glb_skilldefs[skill].name);
gfx_pager_newline();
// Add standard skill stuff
gfx_pager_separator();
// Output any prereqs.
const u8 *prereq;
prereq = (const u8 *) glb_skilldefs[skill].prereq;
if (prereq && *prereq)
{
gfx_pager_addtext("This requires ");
while (*prereq)
{
gfx_pager_addtext(glb_skilldefs[*prereq].name);
prereq++;
if (*prereq)
{
if (!prereq[1])
gfx_pager_addtext(" and ");
else
gfx_pager_addtext(", ");
}
}
gfx_pager_addtext(".");
gfx_pager_newline();
}
// Add encyclopedia entry, if any.
{
const encyclopedia_entry *entry;
entry = encyc_getentry("SKILL", skill);
if (entry)
{
gfx_pager_separator();
encyc_pageentry("SKILL", skill);
}
}
gfx_pager_display();
}
|