Commented a bunch of files.

This commit is contained in:
Ryan "Lofenyy" Medeiros 2023-07-01 02:14:53 -06:00
parent b64dac0a19
commit 230629e4bb
3 changed files with 137 additions and 77 deletions

View File

@ -231,4 +231,9 @@ For every city except Coffee City, the following should be present and accessibl
\subsection{Rosemary City}
\section{Planned Features}
Shiny Monsters
Legendary Monsters
Monster encyclopedia

View File

@ -63,134 +63,150 @@ int main()
halfdelay(2);
clear();
// Draw our Base tiles
// For all existing base tiles, draw them.
for (int C = 0; C < map[aMap].nBase; C++)
{
//If this tile is active, unwalkable, invisible and white-on-blue
if ((map[aMap].Base[C].active) && (map[aMap].Base[C].walk == 0) &&
(map[aMap].Base[C].t == ' ') && (map[aMap].Base[C].c == 48))
{
// Draw an animated water tile
attron(COLOR_PAIR(map[aMap].Base[C].c));
mvprintw(map[aMap].Base[C].y - y, map[aMap].Base[C].x - x, "%c",
tile_W[A % 8]);
attroff(COLOR_PAIR(map[aMap].Base[C].c));
if ((map[aMap].Base[C].x - (xmax / 2) == x) &&
(map[aMap].Base[C].y - (ymax / 2) == y))
{
mvprintw(ymax - 2, 0, "Walkable: %s\nColor: %i",
map[aMap].Base[C].walk ? "True" : "False",
map[aMap].Base[C].c);
}
}
//If this tile isn't all-of-the-above
else if (map[aMap].Base[C].active)
{
//Draw it normally
attron(COLOR_PAIR(map[aMap].Base[C].c));
mvprintw(map[aMap].Base[C].y - y, map[aMap].Base[C].x - x, "%c",
map[aMap].Base[C].t);
attroff(COLOR_PAIR(map[aMap].Base[C].c));
if ((map[aMap].Base[C].x - (xmax / 2) == x) &&
(map[aMap].Base[C].y - (ymax / 2) == y))
{
mvprintw(ymax - 2, 0, "Walkable: %s\nColor: %i",
map[aMap].Base[C].walk ? "True" : "False",
map[aMap].Base[C].c);
}
}
//If we're hovering over this base tile
if ((map[aMap].Base[C].x - (xmax / 2) == x) &&
(map[aMap].Base[C].y - (ymax / 2) == y))
{
//Print out useful info in the bottom-left screen
mvprintw(ymax - 2, 0, "Walkable: %s\nColor: %i",
map[aMap].Base[C].walk ? "True" : "False",
map[aMap].Base[C].c);
}
}
// Draw our Info tiles
// For all existing info tiles, draw them.
for (int C = 0; C < map[aMap].nInfo; C++)
{
// If the given info tile is active
if (map[aMap].Info[C].active)
{
// Draw it with the appropriate character and colour
attron(COLOR_PAIR(map[aMap].Info[C].c));
mvprintw(map[aMap].Info[C].y - y, map[aMap].Info[C].x - x, "%c",
map[aMap].Info[C].t);
attroff(COLOR_PAIR(map[aMap].Info[C].c));
if ((map[aMap].Info[C].x - (xmax / 2) == x) &&
(map[aMap].Info[C].y - (ymax / 2) == y))
{
mvprintw(ymax - 1, 0, "%s", map[aMap].Info[C].dialog);
}
}
// If we're hovering over the given info tile
if ((map[aMap].Info[C].x - (xmax / 2) == x) &&
(map[aMap].Info[C].y - (ymax / 2) == y))
{
// Print out its dialog in the bottom left of the screen
mvprintw(ymax - 1, 0, "%s", map[aMap].Info[C].dialog);
}
}
// Draw our Item tiles
// For all existing item tiles, draw them.
for (int C = 0; C < map[aMap].nItem; C++)
{
// If the given item tile is active
if (map[aMap].Item[C].active)
{
// Draw it with the appropriate character and colour
attron(COLOR_PAIR(map[aMap].Item[C].c));
mvprintw(map[aMap].Item[C].y - y, map[aMap].Item[C].x - x, "%c",
map[aMap].Item[C].t);
attroff(COLOR_PAIR(map[aMap].Item[C].c));
if ((map[aMap].Item[C].x - (xmax / 2) == x) &&
(map[aMap].Item[C].y - (ymax / 2) == y))
{
mvprintw(ymax - 1, 0, "ID#: %i", map[aMap].Item[C].ID);
}
}
// If we're hovering over the given item tile
if ((map[aMap].Item[C].x - (xmax / 2) == x) &&
(map[aMap].Item[C].y - (ymax / 2) == y))
{
// Print out its the item ID in the bottom left of the screen
mvprintw(ymax - 1, 0, "ID#: %i", map[aMap].Item[C].ID);
}
}
// Draw our Door tiles
// For all existing door tiles, draw them.
for (int C = 0; C < map[aMap].nDoor; C++)
{
// If the given door tile is active
if (map[aMap].Door[C].active)
{
// Draw it with the appropriate character and colour
attron(COLOR_PAIR(map[aMap].Door[C].c));
mvprintw(map[aMap].Door[C].y - y, map[aMap].Door[C].x - x, "%c",
map[aMap].Door[C].t);
attroff(COLOR_PAIR(map[aMap].Door[C].c));
if ((map[aMap].Door[C].x - (xmax / 2) == x) &&
(map[aMap].Door[C].y - (ymax / 2) == y))
{
mvprintw(ymax - 2, 0, "Status: %s\nMap: %i X: %li Y: %li",
map[aMap].Door[C].lock ? "Locked" : "Unlocked",
map[aMap].Door[C].ID, map[aMap].Door[C].nx,
map[aMap].Door[C].ny);
}
}
// If we're hovering over the given item tile
if ((map[aMap].Door[C].x - (xmax / 2) == x) &&
(map[aMap].Door[C].y - (ymax / 2) == y))
{
//Print out useful info in the bottom-left screen
mvprintw(ymax - 2, 0, "Status: %s\nMap: %i X: %li Y: %li",
map[aMap].Door[C].lock ? "Locked" : "Unlocked",
map[aMap].Door[C].ID, map[aMap].Door[C].nx,
map[aMap].Door[C].ny);
}
}
// Draw our Character tiles
// For all existing character tiles, draw them.
for (int C = 0; C < map[aMap].nChar; C++)
{
// If the given char tile is active
if (map[aMap].Char[C].active)
{
// Draw it with the appropriate text character and colour
attron(COLOR_PAIR(map[aMap].Char[C].c));
mvprintw(map[aMap].Char[C].y - y, map[aMap].Char[C].x - x, "%c",
map[aMap].Char[C].t);
attroff(COLOR_PAIR(map[aMap].Char[C].c));
if ((map[aMap].Char[C].x - (xmax / 2) == x) &&
(map[aMap].Char[C].y - (ymax / 2) == y))
{
mvprintw(ymax - 1, 0, "Name: %s - Type: %s - Moves: %s",
map[aMap].Char[C].name,
map[aMap].Char[C].type ? "Aggressive" : "Passive",
map[aMap].Char[C].move ? "Yes" : "No");
mvprintw(ymax - 2, 0, "Dialogue 1: %s",
map[aMap].Char[C].dialog1);
mvprintw(ymax - 3, 0, "Dialogue 2: %s",
map[aMap].Char[C].dialog2);
mvprintw(ymax - 4, 0,
"Monsters: %i-%i %i-%i %i-%i %i-%i %i-%i",
map[aMap].Char[C].mon[0].type,
map[aMap].Char[C].mon[0].level,
map[aMap].Char[C].mon[1].type,
map[aMap].Char[C].mon[1].level,
map[aMap].Char[C].mon[2].type,
map[aMap].Char[C].mon[2].level,
map[aMap].Char[C].mon[3].type,
map[aMap].Char[C].mon[3].level,
map[aMap].Char[C].mon[4].type,
map[aMap].Char[C].mon[4].level);
}
}
// If we're hovering over the given item tile
if ((map[aMap].Char[C].x - (xmax / 2) == x) &&
(map[aMap].Char[C].y - (ymax / 2) == y))
{
//Print out useful info in the bottom-left screen
mvprintw(ymax - 1, 0, "Name: %s - Type: %s - Moves: %s",
map[aMap].Char[C].name,
map[aMap].Char[C].type ? "Aggressive" : "Passive",
map[aMap].Char[C].move ? "Yes" : "No");
mvprintw(ymax - 2, 0, "Dialogue 1: %s",
map[aMap].Char[C].dialog1);
mvprintw(ymax - 3, 0, "Dialogue 2: %s",
map[aMap].Char[C].dialog2);
mvprintw(ymax - 4, 0,
"Monsters: %i-%i %i-%i %i-%i %i-%i %i-%i",
map[aMap].Char[C].mon[0].type,
map[aMap].Char[C].mon[0].level,
map[aMap].Char[C].mon[1].type,
map[aMap].Char[C].mon[1].level,
map[aMap].Char[C].mon[2].type,
map[aMap].Char[C].mon[2].level,
map[aMap].Char[C].mon[3].type,
map[aMap].Char[C].mon[3].level,
map[aMap].Char[C].mon[4].type,
map[aMap].Char[C].mon[4].level);
}
}
// Display useful information.
// Display coordinates and tool/tips in the top left.
attron(COLOR_PAIR(0));
mvprintw(0, 0, "Map: %i X: %li Y: %li", aMap, x, y);
mvprintw(1, 0, "Tooltip: %c Color: %i Walkable: %s", (char)tip, tipColor,
@ -199,15 +215,17 @@ int main()
// Display our cursor based on what tool we're using.
switch (tool)
{
// If continuous painting is off
case 0:
mvprintw(ymax / 2, xmax / 2, "!");
break;
// If continuous painting is on
case 1:
mvprintw(ymax / 2, xmax / 2, "#");
break;
}
// Process our controls.
// Get and process our user input.
k = getch();
if (k == KEY_UP)
y--;
@ -221,14 +239,17 @@ int main()
saveMap();
if (k == KEY_F(6))
loadMap();
// if(k == KEY_F(7)) copyMap();
// if(k == KEY_F(7))
// copyMap();
if (k == KEY_F(8))
// Toggle continuous painting
tool = !tool;
if (k == 'b')
// Change our tooltip
turnTip();
if (k == ' ')
addBase();
if (tool == 1)
if (tool == 1) //If continuous painting is on
addBase();
if (k == 'i')
addInfo();

View File

@ -267,29 +267,50 @@ int addChar()
return 0;
}
// Deactivate any tiles that our cursor is over
int delTile()
{
// Deactivate any tiles that our cursor is over
// For every base tile
for (int C = 0; C < map[aMap].nBase; C++)
// If our cursor is over it,
if ((map[aMap].Base[C].x == x + (xmax / 2)) &&
(map[aMap].Base[C].y == y + (ymax / 2)))
// Deactivate it
map[aMap].Base[C].active = 0;
// For every info tile
for (int C = 0; C < map[aMap].nInfo; C++)
// If our cursor is over it,
if ((map[aMap].Info[C].x == x + (xmax / 2)) &&
(map[aMap].Info[C].y == y + (ymax / 2)))
// Deactivate it
map[aMap].Info[C].active = 0;
// For every item tile
for (int C = 0; C < map[aMap].nItem; C++)
// If our cursor is over it,
if ((map[aMap].Item[C].x == x + (xmax / 2)) &&
(map[aMap].Item[C].y == y + (ymax / 2)))
// Deactivate it
map[aMap].Item[C].active = 0;
// For every door tile
for (int C = 0; C < map[aMap].nDoor; C++)
// If our cursor is over it,
if ((map[aMap].Door[C].x == x + (xmax / 2)) &&
(map[aMap].Door[C].y == y + (ymax / 2)))
// Deactivate it
map[aMap].Door[C].active = 0;
// For every char tile
for (int C = 0; C < map[aMap].nChar; C++)
// If our cursor is over it,
if ((map[aMap].Char[C].x == x + (xmax / 2)) &&
(map[aMap].Char[C].y == y + (ymax / 2)))
// Deactivate it
map[aMap].Char[C].active = 0;
// Exit gracefully
return 0;
}
@ -352,9 +373,11 @@ int newMap()
}
else
{
// Or else, record our new number of maps.
nMap = n;
}
// Exit gracefully
return 0;
}
@ -372,12 +395,14 @@ int saveMap()
FILE *fp = fopen(buffer, "w");
if (fp == NULL)
return 1;
// Save our header, with the number of active maps.
fprintf(fp, "<document maps=\"%i\">\n", nMap);
// For every map
for (uint_fast8_t C = 0; C < nMap; C++)
{
//Print out a header giving valuable info for memory allocation.
fprintf(fp,
"\t<map bases=\"%i\" infos=\"%i\" items=\"%i\" doors=\"%i\" "
"chars=\"%i\">\n",
@ -388,6 +413,7 @@ int saveMap()
{
if (map[C].Base[B].active)
{
//Print out an XML tag with its info.
fprintf(fp,
"\t\t<base x=\"%li\" y=\"%li\" t=\"%i\" c=\"%i\" "
"walk=\"%i\" />\n",
@ -400,6 +426,7 @@ int saveMap()
{
if (map[C].Info[B].active)
{
//Print out an XML tag with its info.
fprintf(fp,
"\t\t<info x=\"%li\" y=\"%li\" t=\"%i\" c=\"%i\" "
"dialog=\"%s \" />\n",
@ -412,6 +439,7 @@ int saveMap()
{
if (map[C].Item[B].active)
{
//Print out an XML tag with its info.
fprintf(fp,
"\t\t<item x=\"%li\" y=\"%li\" t=\"%i\" c=\"%i\" ID=\"%i\" "
"/>\n",
@ -424,6 +452,7 @@ int saveMap()
{
if (map[C].Door[B].active)
{
//Print out an XML tag with its info.
fprintf(
fp,
"\t\t<door x=\"%li\" y=\"%li\" t=\"%i\" c=\"%i\" lock=\"%i\" "
@ -438,6 +467,7 @@ int saveMap()
{
if (map[C].Char[B].active)
{
//Print out an XML tag with its info.
fprintf(
fp,
"\t\t<char x=\"%li\" y=\"%li\" t=\"%i\" c=\"%i\" type=\"%i\" "
@ -461,7 +491,8 @@ int saveMap()
}
fprintf(fp, "</document>\n");
// Exit gracefully
fclose(fp);
return 0;
}
@ -520,27 +551,27 @@ int loadMap()
&map[iMap].nBase, &map[iMap].nInfo, &map[iMap].nItem,
&map[iMap].nDoor, &map[iMap].nChar);
// Allocate our memory
// Allocate our memory, return 1 on error.
map[iMap].Base =
realloc(map[iMap].Base, map[iMap].nBase * sizeof(struct Base));
if (map[iMap].Base == NULL)
return 0;
return 1;
map[iMap].Info =
realloc(map[iMap].Info, map[iMap].nInfo * sizeof(struct Info));
if (map[iMap].Base == NULL)
return 0;
return 1;
map[iMap].Item =
realloc(map[iMap].Item, map[iMap].nItem * sizeof(struct Item));
if (map[iMap].Item == NULL)
return 0;
return 1;
map[iMap].Door =
realloc(map[iMap].Door, map[iMap].nDoor * sizeof(struct Door));
if (map[iMap].Door == NULL)
return 0;
return 1;
map[iMap].Char =
realloc(map[iMap].Char, map[iMap].nChar * sizeof(struct Char));
if (map[iMap].Char == NULL)
return 0;
return 1;
// This makes it work for some reason.
strncpy(buffer, "", 256);
@ -551,6 +582,8 @@ int loadMap()
{
// This makes it work for some reason.
strncpy(buffer, "", 256);
//Switch maps and reset our values
iMap++;
iBase = 0;
iInfo = 0;
@ -677,5 +710,6 @@ int loadMap()
}
}
// Exit gracefully
return 0;
}