Major refactoring.
This commit is contained in:
parent
5dc807b309
commit
0b65266c9a
|
@ -19,32 +19,78 @@
|
|||
|
||||
#include "engineCore.c"
|
||||
|
||||
// Our current map
|
||||
uint_fast8_t aMap = 0;
|
||||
// Our selected tool and tooltip for base tiles
|
||||
uint_fast8_t continuousPainting = 0;
|
||||
uint_fast16_t Btip = '#';
|
||||
uint_fast8_t BtipColor = 0;
|
||||
uint_fast8_t BtipWalk = 0;
|
||||
|
||||
// Our screen size
|
||||
uint_fast16_t xmax = 0;
|
||||
uint_fast16_t ymax = 0;
|
||||
// Show a menu where the user can select their colour
|
||||
int colorPick()
|
||||
{
|
||||
char buffer1[8] = "";
|
||||
char buffer2[8] = "";
|
||||
uint_fast8_t a;
|
||||
uint_fast8_t b;
|
||||
|
||||
// Our cursor location
|
||||
uint_fast16_t x = 0;
|
||||
uint_fast16_t y = 0;
|
||||
echo();
|
||||
clear();
|
||||
mvprintw(0, 0, "Foreground:");
|
||||
mvprintw(1, 0, "Black) 0");
|
||||
mvprintw(2, 0, "Red) 1");
|
||||
mvprintw(3, 0, "Green) 2");
|
||||
mvprintw(4, 0, "Yellow) 3");
|
||||
mvprintw(5, 0, "Blue) 4");
|
||||
mvprintw(6, 0, "Magenta) 5");
|
||||
mvprintw(7, 0, "Cyan) 6");
|
||||
mvprintw(8, 0, "White) 7\n");
|
||||
|
||||
// Our keypress
|
||||
uint_fast16_t k = 0;
|
||||
getnstr(buffer1, 8);
|
||||
|
||||
// Our selected tool and tooltip
|
||||
uint_fast8_t tool = 0;
|
||||
uint_fast16_t tip = '#';
|
||||
uint_fast8_t tipColor = 0;
|
||||
uint_fast8_t tipWalk = 0;
|
||||
mvprintw(10, 0, "Background:");
|
||||
mvprintw(11, 0, "Black) 0");
|
||||
mvprintw(12, 0, "Red) 1");
|
||||
mvprintw(13, 0, "Green) 2");
|
||||
mvprintw(14, 0, "Yellow) 3");
|
||||
mvprintw(15, 0, "Blue) 4");
|
||||
mvprintw(16, 0, "Magenta) 5");
|
||||
mvprintw(17, 0, "Cyan) 6");
|
||||
mvprintw(18, 0, "White) 7\n");
|
||||
|
||||
// Animated tiles
|
||||
char tile_W[8] = {'~', '.', ' ', ' ', ' ', '.', '~', '^'};
|
||||
getnstr(buffer2, 8);
|
||||
|
||||
// Our mouse events
|
||||
MEVENT event;
|
||||
a = atoi(buffer1);
|
||||
b = atoi(buffer2);
|
||||
|
||||
return 10 * (b) + (a + 1);
|
||||
}
|
||||
|
||||
// Change our tooltip for a different one
|
||||
int turnTip()
|
||||
{
|
||||
char buffer1[1] = "";
|
||||
char buffer2[1] = "";
|
||||
uint_fast8_t walk = 0;
|
||||
|
||||
echo();
|
||||
|
||||
// Ask our necessary details.
|
||||
mvprintw(5, 0, "What character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
mvprintw(6, 0, "Are these tiles walkable? (1 = yes, 0 = no) ");
|
||||
getnstr(buffer2, 1);
|
||||
walk = atoi(buffer2);
|
||||
|
||||
// Set our variables to our aquired values
|
||||
BtipColor = colorPick();
|
||||
BtipWalk = walk;
|
||||
Btip = buffer1[0];
|
||||
|
||||
// end gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Show a help screen for the user
|
||||
int help()
|
||||
{
|
||||
char buffer[1] = "";
|
||||
|
@ -60,49 +106,56 @@ int help()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int colorPick()
|
||||
{
|
||||
char buffer1[8] = "";
|
||||
char buffer2[8] = "";
|
||||
uint_fast8_t a;
|
||||
uint_fast8_t b;
|
||||
|
||||
echo();
|
||||
clear();
|
||||
mvprintw(0, 0, "Background:");
|
||||
mvprintw(1, 0, "Black) 0");
|
||||
mvprintw(2, 0, "Red) 1");
|
||||
mvprintw(3, 0, "Green) 2");
|
||||
mvprintw(4, 0, "Yellow) 3");
|
||||
mvprintw(5, 0, "Blue) 4");
|
||||
mvprintw(6, 0, "Magenta) 5");
|
||||
mvprintw(7, 0, "Cyan) 6");
|
||||
mvprintw(8, 0, "White) 7\n");
|
||||
|
||||
getnstr(buffer1, 8);
|
||||
|
||||
mvprintw(10, 0, "Foreground:");
|
||||
mvprintw(11, 0, "Black) 0");
|
||||
mvprintw(12, 0, "Red) 1");
|
||||
mvprintw(13, 0, "Green) 2");
|
||||
mvprintw(14, 0, "Yellow) 3");
|
||||
mvprintw(15, 0, "Blue) 4");
|
||||
mvprintw(16, 0, "Magenta) 5");
|
||||
mvprintw(17, 0, "Cyan) 6");
|
||||
mvprintw(18, 0, "White) 7\n");
|
||||
|
||||
getnstr(buffer2, 8);
|
||||
|
||||
a = atoi(buffer1);
|
||||
b = atoi(buffer2);
|
||||
|
||||
return 10 * (a) + (b + 1);
|
||||
}
|
||||
|
||||
#include "engineMaps.h"
|
||||
|
||||
// Map editor for our game
|
||||
int main()
|
||||
{
|
||||
// Our current map
|
||||
uint_fast8_t aMap = 0;
|
||||
|
||||
// Our screen size
|
||||
uint_fast16_t xmax = 0;
|
||||
uint_fast16_t ymax = 0;
|
||||
|
||||
// Our cursor location
|
||||
uint_fast16_t x = 0;
|
||||
uint_fast16_t y = 0;
|
||||
|
||||
// Our keypress
|
||||
uint_fast16_t k = 0;
|
||||
|
||||
// Animated tiles
|
||||
char tile_W[8] = {'~', '.', ' ', ' ', ' ', '.', '~', '^'};
|
||||
|
||||
// Potential tile values
|
||||
uint_fast8_t c = 0;
|
||||
uint_fast8_t t = 0;
|
||||
char dialog[256] = "";
|
||||
uint_fast8_t ID = 0;
|
||||
uint_fast8_t lock = 0;
|
||||
uint_fast8_t nx = 0;
|
||||
uint_fast8_t ny = 0;
|
||||
uint_fast8_t type = 0;
|
||||
uint_fast8_t move = 0;
|
||||
char name[256] = "";
|
||||
char text1[256] = "";
|
||||
char text2[256] = "";
|
||||
struct mapmonster mon[5];
|
||||
|
||||
//Text buffers
|
||||
char buffer1[256] = "";
|
||||
char buffer2[256] = "";
|
||||
char buffer3[256] = "";
|
||||
char buffer4[256] = "";
|
||||
char buffer5[256] = "";
|
||||
char buffer6[256] = "";
|
||||
char buffer7[256] = "";
|
||||
char buffer8[256] = "";
|
||||
char buffer9[256] = "";
|
||||
char bufferA[256] = "";
|
||||
char bufferB[256] = "";
|
||||
char bufferC[256] = "";
|
||||
char bufferD[256] = "";
|
||||
|
||||
// Start our game engine and start a blank map
|
||||
initEngine();
|
||||
newMap();
|
||||
|
@ -255,12 +308,12 @@ int main()
|
|||
// 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,
|
||||
tipWalk ? "True" : "False");
|
||||
mvprintw(1, 0, "Tooltip: %c Color: %i Walkable: %s", (char)Btip, BtipColor,
|
||||
BtipWalk ? "True" : "False");
|
||||
mvprintw(2, 0, "Press 'h' for help.");
|
||||
|
||||
// Display our cursor based on what tool we're using.
|
||||
switch (tool)
|
||||
switch (continuousPainting)
|
||||
{
|
||||
// If continuous painting is off
|
||||
case 0:
|
||||
|
@ -283,33 +336,147 @@ int main()
|
|||
if (k == KEY_RIGHT)
|
||||
x++;
|
||||
if (k == KEY_F(5))
|
||||
saveMap();
|
||||
{
|
||||
echo();
|
||||
mvprintw(4,0,"Save name: ");
|
||||
getnstr(buffer1, 8);
|
||||
|
||||
saveMap(buffer1);
|
||||
}
|
||||
if (k == KEY_F(6))
|
||||
loadMap();
|
||||
{
|
||||
echo();
|
||||
mvprintw(4,0,"Load name: ");
|
||||
getnstr(buffer1, 8);
|
||||
|
||||
loadMap(buffer1);
|
||||
}
|
||||
// if(k == KEY_F(7))
|
||||
// copyMap();
|
||||
if (k == KEY_F(8))
|
||||
// Toggle continuous painting
|
||||
tool = !tool;
|
||||
continuousPainting = !continuousPainting;
|
||||
if (k == 'b')
|
||||
// Change our tooltip
|
||||
turnTip();
|
||||
if (k == ' ')
|
||||
addBase();
|
||||
if (tool == 1) // If continuous painting is on
|
||||
addBase();
|
||||
addBase(x, y, aMap, xmax, ymax, Btip, BtipColor, BtipWalk);
|
||||
if (continuousPainting == 1) // If continuous painting is on
|
||||
addBase(x, y, aMap, xmax, ymax, Btip, BtipColor, BtipWalk);
|
||||
if (k == 'i')
|
||||
addInfo();
|
||||
{
|
||||
echo();
|
||||
mvprintw(5, 0, "Which character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
t = buffer1[0];
|
||||
mvprintw(6, 0, "What would you like the sign to say? ");
|
||||
getnstr(dialog, 256);
|
||||
|
||||
c = colorPick();
|
||||
|
||||
addInfo(x, y, aMap, xmax, ymax, t, c, dialog);
|
||||
}
|
||||
if (k == 'o')
|
||||
addItem();
|
||||
{
|
||||
echo();
|
||||
mvprintw(5, 0, "Which character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
t = buffer1[0];
|
||||
mvprintw(6, 0, "Which item is this? ");
|
||||
getnstr(buffer2, 8);
|
||||
ID = atoi(buffer2);
|
||||
|
||||
c = colorPick();
|
||||
|
||||
addItem(x, y, aMap, xmax, ymax, t, c, ID);
|
||||
}
|
||||
if (k == 'd')
|
||||
addDoor();
|
||||
{
|
||||
echo();
|
||||
mvprintw(5, 0, "Which character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
t = buffer1[0];
|
||||
mvprintw(6, 0, "Is the door locked? (1 = YES/0 = NO) ");
|
||||
getnstr(buffer2, 1);
|
||||
lock = atoi(buffer2);
|
||||
mvprintw(7, 0, "Which map does this door go to? (#) ");
|
||||
getnstr(buffer3, 8);
|
||||
ID = atoi(buffer3);
|
||||
mvprintw(8, 0, "Which X value does this door go to? (#) ");
|
||||
getnstr(buffer4, 8);
|
||||
nx = atoi(buffer4);
|
||||
mvprintw(9, 0, "Which Y value does this door go to? (#) ");
|
||||
getnstr(buffer5, 8);
|
||||
ny = atoi(buffer5);
|
||||
|
||||
c = colorPick();
|
||||
|
||||
addDoor(x, y, aMap, xmax, ymax, t, c, lock, ID, nx, ny);
|
||||
}
|
||||
if (k == 'p')
|
||||
addChar();
|
||||
{
|
||||
echo();
|
||||
mvprintw(5, 0, "Which character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
t = buffer1[0];
|
||||
|
||||
mvprintw(6, 0, "Is this character aggressive? (1 = YES/0 = NO) ");
|
||||
getnstr(buffer2, 1);
|
||||
type = atoi(buffer2);
|
||||
|
||||
mvprintw(7, 0, "Does this character wander? (1 = YES/0 = NO) ");
|
||||
getnstr(buffer3, 1);
|
||||
move = atoi(buffer3);
|
||||
|
||||
mvprintw(8, 0, "What is their name? ");
|
||||
getnstr(name, 256);
|
||||
|
||||
mvprintw(9, 0, "What do they say when they want to fight? ");
|
||||
getnstr(text1, 256);
|
||||
|
||||
mvprintw(10, 0, "What do they say when they don't want to fight? ");
|
||||
getnstr(text2, 256);
|
||||
|
||||
mvprintw(11, 0, "What type is their 1st monster? ");
|
||||
getnstr(buffer4, 8);
|
||||
mon[0].type = atoi(buffer4);
|
||||
mvprintw(12, 0, "What type is their 2nd monster? ");
|
||||
getnstr(buffer5, 8);
|
||||
mon[1].type = atoi(buffer5);
|
||||
mvprintw(13, 0, "What type is their 3rd monster? ");
|
||||
getnstr(buffer6, 8);
|
||||
mon[2].type = atoi(buffer6);
|
||||
mvprintw(14, 0, "What type is their 4th monster? ");
|
||||
getnstr(buffer7, 8);
|
||||
mon[3].type = atoi(buffer7);
|
||||
mvprintw(15, 0, "What type is their 5th monster? ");
|
||||
getnstr(buffer8, 8);
|
||||
mon[4].type = atoi(buffer8);
|
||||
|
||||
mvprintw(16, 0, "What level is their 1st monster? ");
|
||||
getnstr(buffer9, 8);
|
||||
mon[0].level = atoi(buffer9);
|
||||
mvprintw(17, 0, "What level is their 2nd monster? ");
|
||||
getnstr(bufferA, 8);
|
||||
mon[1].level = atoi(bufferA);
|
||||
mvprintw(18, 0, "What level is their 3rd monster? ");
|
||||
getnstr(bufferB, 8);
|
||||
mon[2].level = atoi(bufferB);
|
||||
mvprintw(19, 0, "What level is their 4th monster? ");
|
||||
getnstr(bufferC, 8);
|
||||
mon[3].level = atoi(bufferC);
|
||||
mvprintw(20, 0, "What level is their 5th monster? ");
|
||||
getnstr(bufferD, 8);
|
||||
mon[4].level = atoi(bufferD);
|
||||
|
||||
c = colorPick();
|
||||
|
||||
addChar(x, y, aMap, xmax, ymax, t, c, type, move, name, text1, text2, mon);
|
||||
}
|
||||
if (k == 'h')
|
||||
help();
|
||||
if (k == KEY_BACKSPACE)
|
||||
delTile();
|
||||
delTile(x, y, aMap, xmax, ymax);
|
||||
if ((k == KEY_PPAGE) && (aMap < (nMap - 1)))
|
||||
aMap++;
|
||||
if ((k == KEY_NPAGE) && (aMap > 0))
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
// ---
|
||||
|
||||
#include <ncurses.h>
|
||||
#include "engineMaps.h"
|
||||
|
||||
// To run at the beginning of the game.
|
||||
void initEngine()
|
||||
|
|
|
@ -12,337 +12,220 @@
|
|||
// not, see https://www.gnu.org/licenses/.
|
||||
|
||||
// Add a new Base tile
|
||||
int addBase()
|
||||
uint_fast8_t addBase(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax,
|
||||
uint_fast8_t ymax, uint_fast8_t t, uint_fast8_t c, uint_fast8_t walk)
|
||||
{
|
||||
// Allocate space for the new tile.
|
||||
map[aMap].nBase++;
|
||||
map[aMap].Base = realloc(map[aMap].Base, map[aMap].nBase * sizeof(struct Base));
|
||||
map[z].nBase++;
|
||||
map[z].Base = realloc(map[z].Base, map[z].nBase * sizeof(struct Base));
|
||||
|
||||
// If this fails, do nothing.
|
||||
if (map[aMap].Base == NULL)
|
||||
if (map[z].Base == NULL)
|
||||
{
|
||||
map[aMap].nBase--;
|
||||
map[z].nBase--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Otherwise, set our values
|
||||
map[aMap].Base[map[aMap].nBase - 1].x = x + (xmax / 2);
|
||||
map[aMap].Base[map[aMap].nBase - 1].y = y + (ymax / 2);
|
||||
map[aMap].Base[map[aMap].nBase - 1].t = tip;
|
||||
map[aMap].Base[map[aMap].nBase - 1].c = tipColor;
|
||||
map[aMap].Base[map[aMap].nBase - 1].walk = tipWalk;
|
||||
map[aMap].Base[map[aMap].nBase - 1].active = 1;
|
||||
map[z].Base[map[z].nBase - 1].x = x + (xmax / 2);
|
||||
map[z].Base[map[z].nBase - 1].y = y + (ymax / 2);
|
||||
map[z].Base[map[z].nBase - 1].t = t;
|
||||
map[z].Base[map[z].nBase - 1].c = c;
|
||||
map[z].Base[map[z].nBase - 1].walk = walk;
|
||||
map[z].Base[map[z].nBase - 1].active = 1;
|
||||
|
||||
// End gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add a new info tile
|
||||
int addInfo()
|
||||
int addInfo(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax, uint_fast8_t ymax,
|
||||
uint_fast8_t t, uint_fast8_t c, char dialog[255])
|
||||
{
|
||||
char buffer2[1] = "";
|
||||
|
||||
// Allocate space for the new tile.
|
||||
map[aMap].nInfo++;
|
||||
map[aMap].Info = realloc(map[aMap].Info, map[aMap].nInfo * sizeof(struct Info));
|
||||
map[z].nInfo++;
|
||||
map[z].Info = realloc(map[z].Info, map[z].nInfo * sizeof(struct Info));
|
||||
|
||||
// If this fails, do nothing.
|
||||
if (map[aMap].Info == NULL)
|
||||
if (map[z].Info == NULL)
|
||||
{
|
||||
map[aMap].nInfo--;
|
||||
map[z].nInfo--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get our dialog
|
||||
echo();
|
||||
mvprintw(3, 0, "What character would you like to print? ");
|
||||
getnstr(buffer2, 1);
|
||||
|
||||
mvprintw(4, 0, "What would you like the sign to say? ");
|
||||
getnstr(map[aMap].Info[map[aMap].nInfo - 1].dialog, 255);
|
||||
|
||||
// Otherwise, set our values
|
||||
map[aMap].Info[map[aMap].nInfo - 1].x = x + (xmax / 2);
|
||||
map[aMap].Info[map[aMap].nInfo - 1].y = y + (ymax / 2);
|
||||
map[aMap].Info[map[aMap].nInfo - 1].c = colorPick();
|
||||
map[aMap].Info[map[aMap].nInfo - 1].t = buffer2[0];
|
||||
map[aMap].Info[map[aMap].nInfo - 1].active = 1;
|
||||
map[z].Info[map[z].nInfo - 1].x = x + (xmax / 2);
|
||||
map[z].Info[map[z].nInfo - 1].y = y + (ymax / 2);
|
||||
map[z].Info[map[z].nInfo - 1].c = c;
|
||||
map[z].Info[map[z].nInfo - 1].t = t;
|
||||
strncpy(map[z].Info[map[z].nInfo - 1].dialog, dialog, 255);
|
||||
map[z].Info[map[z].nInfo - 1].active = 1;
|
||||
|
||||
// End gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add a new item tile
|
||||
int addItem()
|
||||
int addItem(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax, uint_fast8_t ymax,
|
||||
uint_fast8_t t, uint_fast8_t c, uint_fast8_t ID)
|
||||
{
|
||||
char buffer1[1];
|
||||
char buffer3[8];
|
||||
|
||||
// Allocate space for the new tile.
|
||||
map[aMap].nItem++;
|
||||
map[aMap].Item = realloc(map[aMap].Item, map[aMap].nItem * sizeof(struct Item));
|
||||
map[z].nItem++;
|
||||
map[z].Item = realloc(map[z].Item, map[z].nItem * sizeof(struct Item));
|
||||
|
||||
// If this fails, do nothing.
|
||||
if (map[aMap].Item == NULL)
|
||||
if (map[z].Item == NULL)
|
||||
{
|
||||
map[aMap].nItem--;
|
||||
map[z].nItem--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get our item ID#
|
||||
echo();
|
||||
mvprintw(3, 0, "What character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
|
||||
mvprintw(4, 0, "What item is this? (ID#) ");
|
||||
getnstr(buffer3, 8);
|
||||
map[aMap].Item[map[aMap].nItem - 1].ID = atoi(buffer3);
|
||||
|
||||
// Otherwise, set our values
|
||||
map[aMap].Item[map[aMap].nItem - 1].x = x + (xmax / 2);
|
||||
map[aMap].Item[map[aMap].nItem - 1].y = y + (ymax / 2);
|
||||
map[aMap].Item[map[aMap].nItem - 1].t = buffer1[0];
|
||||
map[aMap].Item[map[aMap].nItem - 1].c = colorPick();
|
||||
map[aMap].Item[map[aMap].nItem - 1].active = 1;
|
||||
map[z].Item[map[z].nItem - 1].x = x + (xmax / 2);
|
||||
map[z].Item[map[z].nItem - 1].y = y + (ymax / 2);
|
||||
map[z].Item[map[z].nItem - 1].t = t;
|
||||
map[z].Item[map[z].nItem - 1].c = c;
|
||||
map[z].Item[map[z].nItem - 1].ID = ID;
|
||||
map[z].Item[map[z].nItem - 1].active = 1;
|
||||
|
||||
// End gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add a new door tile
|
||||
int addDoor()
|
||||
int addDoor(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax, uint_fast8_t ymax,
|
||||
uint_fast8_t t, uint_fast8_t c, uint_fast8_t lock, uint_fast8_t ID, uint_fast8_t nx,
|
||||
uint_fast8_t ny)
|
||||
{
|
||||
char buffer1[1];
|
||||
char buffer3[8];
|
||||
char buffer4[8];
|
||||
char buffer5[8];
|
||||
char buffer6[8];
|
||||
|
||||
// Allocate space for the new tile.
|
||||
map[aMap].nDoor++;
|
||||
map[aMap].Door = realloc(map[aMap].Door, map[aMap].nDoor * sizeof(struct Door));
|
||||
map[z].nDoor++;
|
||||
map[z].Door = realloc(map[z].Door, map[z].nDoor * sizeof(struct Door));
|
||||
|
||||
// If this fails, do nothing.
|
||||
if (map[aMap].Door == NULL)
|
||||
if (map[z].Door == NULL)
|
||||
{
|
||||
map[aMap].nDoor--;
|
||||
map[z].nDoor--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get our info
|
||||
echo();
|
||||
mvprintw(3, 0, "What character would you like to print? ");
|
||||
getnstr(buffer1, 1);
|
||||
mvprintw(4, 0, "Which map will this door go to? ");
|
||||
getnstr(buffer3, 8);
|
||||
mvprintw(5, 0, "What X value? ");
|
||||
getnstr(buffer4, 8);
|
||||
mvprintw(6, 0, "What Y value? ");
|
||||
getnstr(buffer5, 8);
|
||||
mvprintw(7, 0, "Is this door locked? ");
|
||||
getnstr(buffer6, 8);
|
||||
|
||||
// Otherwise, set our values
|
||||
map[aMap].Door[map[aMap].nDoor - 1].x = x + (xmax / 2);
|
||||
map[aMap].Door[map[aMap].nDoor - 1].y = y + (ymax / 2);
|
||||
map[aMap].Door[map[aMap].nDoor - 1].t = buffer1[0];
|
||||
map[aMap].Door[map[aMap].nDoor - 1].c = colorPick();
|
||||
map[aMap].Door[map[aMap].nDoor - 1].lock = atoi(buffer6);
|
||||
map[aMap].Door[map[aMap].nDoor - 1].ID = atoi(buffer3);
|
||||
map[aMap].Door[map[aMap].nDoor - 1].nx = atoi(buffer4);
|
||||
map[aMap].Door[map[aMap].nDoor - 1].ny = atoi(buffer5);
|
||||
map[aMap].Door[map[aMap].nDoor - 1].active = 1;
|
||||
map[z].Door[map[z].nDoor - 1].x = x + (xmax / 2);
|
||||
map[z].Door[map[z].nDoor - 1].y = y + (ymax / 2);
|
||||
map[z].Door[map[z].nDoor - 1].t = t;
|
||||
map[z].Door[map[z].nDoor - 1].c = c;
|
||||
map[z].Door[map[z].nDoor - 1].lock = lock;
|
||||
map[z].Door[map[z].nDoor - 1].ID = ID;
|
||||
map[z].Door[map[z].nDoor - 1].nx = nx;
|
||||
map[z].Door[map[z].nDoor - 1].ny = ny;
|
||||
map[z].Door[map[z].nDoor - 1].active = 1;
|
||||
|
||||
// End gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add a new char tile
|
||||
int addChar()
|
||||
int addChar(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax, uint_fast8_t ymax,
|
||||
uint_fast8_t t, uint_fast8_t c, uint_fast8_t type, uint_fast8_t move, char name[256],
|
||||
char dialog1[256], char dialog2[256], struct mapmonster mons[5])
|
||||
{
|
||||
char buffer1[1];
|
||||
char buffer2[1];
|
||||
|
||||
char buffer3[8];
|
||||
char buffer4[8];
|
||||
char buffer5[8];
|
||||
char buffer6[8];
|
||||
char buffer7[8];
|
||||
|
||||
char buffer8[8];
|
||||
char buffer9[8];
|
||||
char bufferA[8];
|
||||
char bufferB[8];
|
||||
char bufferC[8];
|
||||
|
||||
char bufferD[8];
|
||||
|
||||
// Allocate space for the new tile.
|
||||
map[aMap].nChar++;
|
||||
map[aMap].Char = realloc(map[aMap].Char, map[aMap].nChar * sizeof(struct Char));
|
||||
map[z].nChar++;
|
||||
map[z].Char = realloc(map[z].Char, map[z].nChar * sizeof(struct Char));
|
||||
|
||||
// If this fails, do nothing.
|
||||
if (map[aMap].Char == NULL)
|
||||
if (map[z].Char == NULL)
|
||||
{
|
||||
map[aMap].nChar--;
|
||||
map[z].nChar--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get our info
|
||||
echo();
|
||||
mvprintw(3, 0, "What character would you like to print? ");
|
||||
getnstr(bufferD, 8);
|
||||
|
||||
mvprintw(5, 0, "Is this guy passive or aggressive? (1 = aggressive, 0 = passive) ");
|
||||
getnstr(buffer1, 1);
|
||||
mvprintw(6, 0, "Does he wander or stay still? (1 = wanders, 0 = still) ");
|
||||
getnstr(buffer2, 1);
|
||||
mvprintw(7, 0, "What is his/her name? ");
|
||||
getnstr(map[aMap].Char[map[aMap].nChar - 1].name, 256);
|
||||
mvprintw(8, 0, "What do they say when they want to fight? ");
|
||||
getnstr(map[aMap].Char[map[aMap].nChar - 1].dialog1, 256);
|
||||
mvprintw(9, 0, "What do they say when they don't want to fight? ");
|
||||
getnstr(map[aMap].Char[map[aMap].nChar - 1].dialog2, 256);
|
||||
|
||||
mvprintw(10, 0, "What's the 1st monster they carry? (ID#) ");
|
||||
getnstr(buffer3, 8);
|
||||
mvprintw(11, 0, "What's the 2nd monster they carry? (ID#) ");
|
||||
getnstr(buffer4, 8);
|
||||
mvprintw(12, 0, "What's the 3rd monster they carry? (ID#) ");
|
||||
getnstr(buffer5, 8);
|
||||
mvprintw(13, 0, "What's the 4th monster they carry? (ID#) ");
|
||||
getnstr(buffer6, 8);
|
||||
mvprintw(14, 0, "What's the 5th monster they carry? (ID#) ");
|
||||
getnstr(buffer7, 8);
|
||||
|
||||
mvprintw(15, 0, "What level is the 1st monster they carry? (#) ");
|
||||
getnstr(buffer8, 8);
|
||||
mvprintw(16, 0, "What level is the 2nd monster they carry? (#) ");
|
||||
getnstr(buffer9, 8);
|
||||
mvprintw(17, 0, "What level is the 3rd monster they carry? (#) ");
|
||||
getnstr(bufferA, 8);
|
||||
mvprintw(18, 0, "What level is the 4th monster they carry? (#) ");
|
||||
getnstr(bufferB, 8);
|
||||
mvprintw(19, 0, "What level is the 5th monster they carry? (#) ");
|
||||
getnstr(bufferC, 8);
|
||||
|
||||
// Otherwise, set our values
|
||||
map[aMap].Char[map[aMap].nChar - 1].x = x + (xmax / 2);
|
||||
map[aMap].Char[map[aMap].nChar - 1].y = y + (ymax / 2);
|
||||
map[aMap].Char[map[aMap].nChar - 1].t = bufferD[0];
|
||||
map[aMap].Char[map[aMap].nChar - 1].c = colorPick();
|
||||
map[aMap].Char[map[aMap].nChar - 1].type = atoi(buffer1);
|
||||
map[aMap].Char[map[aMap].nChar - 1].move = atoi(buffer2);
|
||||
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[0].type = atoi(buffer3);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[1].type = atoi(buffer4);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[2].type = atoi(buffer5);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[3].type = atoi(buffer6);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[4].type = atoi(buffer7);
|
||||
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[0].level = atoi(buffer8);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[1].level = atoi(buffer9);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[2].level = atoi(bufferA);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[3].level = atoi(bufferB);
|
||||
map[aMap].Char[map[aMap].nChar - 1].mon[4].level = atoi(bufferC);
|
||||
|
||||
map[aMap].Char[map[aMap].nChar - 1].active = 1;
|
||||
map[z].Char[map[z].nChar - 1].x = x + (xmax / 2);
|
||||
map[z].Char[map[z].nChar - 1].y = y + (ymax / 2);
|
||||
map[z].Char[map[z].nChar - 1].t = t;
|
||||
map[z].Char[map[z].nChar - 1].c = c;
|
||||
map[z].Char[map[z].nChar - 1].type = type;
|
||||
map[z].Char[map[z].nChar - 1].move = move;
|
||||
strncpy(map[z].Char[map[z].nChar - 1].name, name, 256);
|
||||
strncpy(map[z].Char[map[z].nChar - 1].dialog1, dialog1, 256);
|
||||
strncpy(map[z].Char[map[z].nChar - 1].dialog2, dialog2, 256);
|
||||
map[z].Char[map[z].nChar - 1].mon[0].type = mons[0].type;
|
||||
map[z].Char[map[z].nChar - 1].mon[1].type = mons[1].type;
|
||||
map[z].Char[map[z].nChar - 1].mon[2].type = mons[2].type;
|
||||
map[z].Char[map[z].nChar - 1].mon[3].type = mons[3].type;
|
||||
map[z].Char[map[z].nChar - 1].mon[4].type = mons[4].type;
|
||||
map[z].Char[map[z].nChar - 1].mon[0].level = mons[0].level;
|
||||
map[z].Char[map[z].nChar - 1].mon[1].level = mons[1].level;
|
||||
map[z].Char[map[z].nChar - 1].mon[2].level = mons[2].level;
|
||||
map[z].Char[map[z].nChar - 1].mon[3].level = mons[3].level;
|
||||
map[z].Char[map[z].nChar - 1].mon[4].level = mons[4].level;
|
||||
map[z].Char[map[z].nChar - 1].active = 1;
|
||||
|
||||
// End gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Deactivate any tiles that our cursor is over
|
||||
int delTile()
|
||||
int delTile(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax, uint_fast8_t ymax)
|
||||
{
|
||||
// For every base tile
|
||||
for (int C = 0; C < map[aMap].nBase; C++)
|
||||
for (int C = 0; C < map[z].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)))
|
||||
if ((map[z].Base[C].x == x + (xmax / 2)) && (map[z].Base[C].y == y + (ymax / 2)))
|
||||
// Deactivate it
|
||||
map[aMap].Base[C].active = 0;
|
||||
map[z].Base[C].active = 0;
|
||||
|
||||
// For every info tile
|
||||
for (int C = 0; C < map[aMap].nInfo; C++)
|
||||
for (int C = 0; C < map[z].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)))
|
||||
if ((map[z].Info[C].x == x + (xmax / 2)) && (map[z].Info[C].y == y + (ymax / 2)))
|
||||
// Deactivate it
|
||||
map[aMap].Info[C].active = 0;
|
||||
map[z].Info[C].active = 0;
|
||||
|
||||
// For every item tile
|
||||
for (int C = 0; C < map[aMap].nItem; C++)
|
||||
for (int C = 0; C < map[z].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)))
|
||||
if ((map[z].Item[C].x == x + (xmax / 2)) && (map[z].Item[C].y == y + (ymax / 2)))
|
||||
// Deactivate it
|
||||
map[aMap].Item[C].active = 0;
|
||||
map[z].Item[C].active = 0;
|
||||
|
||||
// For every door tile
|
||||
for (int C = 0; C < map[aMap].nDoor; C++)
|
||||
for (int C = 0; C < map[z].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)))
|
||||
if ((map[z].Door[C].x == x + (xmax / 2)) && (map[z].Door[C].y == y + (ymax / 2)))
|
||||
// Deactivate it
|
||||
map[aMap].Door[C].active = 0;
|
||||
map[z].Door[C].active = 0;
|
||||
|
||||
// For every char tile
|
||||
for (int C = 0; C < map[aMap].nChar; C++)
|
||||
for (int C = 0; C < map[z].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)))
|
||||
if ((map[z].Char[C].x == x + (xmax / 2)) && (map[z].Char[C].y == y + (ymax / 2)))
|
||||
// Deactivate it
|
||||
map[aMap].Char[C].active = 0;
|
||||
map[z].Char[C].active = 0;
|
||||
|
||||
// Exit gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Change our tooltip for a different one
|
||||
int turnTip()
|
||||
{
|
||||
char buffer2[1] = "";
|
||||
char buffer4[1] = "";
|
||||
uint_fast8_t walk = 0;
|
||||
|
||||
echo();
|
||||
|
||||
// Ask our necessary details.
|
||||
mvprintw(4, 0, "What character would you like to print? ");
|
||||
getnstr(buffer2, 1);
|
||||
mvprintw(5, 0, "Are these tiles walkable? (1 = yes, 0 = no) ");
|
||||
getnstr(buffer4, 1);
|
||||
walk = atoi(buffer4);
|
||||
|
||||
// Set our variables to our aquired values
|
||||
tipColor = colorPick();
|
||||
tipWalk = walk;
|
||||
tip = buffer2[0];
|
||||
|
||||
// end gracefully
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allocate memory for our internal map
|
||||
int newMap()
|
||||
{
|
||||
uint_fast8_t n = 255;
|
||||
char buffer[1] = "";
|
||||
|
||||
// Allocate the needed memory
|
||||
map = malloc(n * sizeof(struct maps));
|
||||
map = malloc(255 * sizeof(struct maps));
|
||||
|
||||
// On failure, report error.
|
||||
if (map == NULL)
|
||||
{
|
||||
mvprintw(2, 0, "Unable to allocate memory.");
|
||||
getnstr(NULL, 0);
|
||||
getnstr(buffer, 1);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Or else, record our new number of maps.
|
||||
nMap = n;
|
||||
nMap = 255;
|
||||
}
|
||||
|
||||
// Exit gracefully
|
||||
|
@ -350,17 +233,10 @@ int newMap()
|
|||
}
|
||||
|
||||
// Save our internal world map as an XML document.
|
||||
int saveMap()
|
||||
int saveMap(char filename[256])
|
||||
{
|
||||
echo();
|
||||
char buffer[256] = "";
|
||||
|
||||
// Prompt for our file name
|
||||
mvprintw(3, 0, "Save name? ");
|
||||
getnstr(buffer, 256);
|
||||
|
||||
// Open the file. Exit on failure.
|
||||
FILE *fp = fopen(buffer, "w");
|
||||
FILE *fp = fopen(filename, "w");
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
|
||||
|
@ -466,7 +342,7 @@ int saveMap()
|
|||
}
|
||||
|
||||
// Load our world maps from an XML document.
|
||||
int loadMap()
|
||||
int loadMap(char filename[256])
|
||||
{
|
||||
int iMap = 0;
|
||||
int iBase = 0;
|
||||
|
@ -478,13 +354,8 @@ int loadMap()
|
|||
char substr[256] = "";
|
||||
FILE *fp;
|
||||
|
||||
// Prompt for our file name
|
||||
echo();
|
||||
mvprintw(3, 0, "Load name? ");
|
||||
getnstr(buffer, 256);
|
||||
|
||||
// Open file. Exit on failure
|
||||
fp = fopen(buffer, "r");
|
||||
fp = fopen(filename, "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
getnstr(buffer, 1);
|
||||
|
|
Loading…
Reference in New Issue