📄 main.c
字号:
break; mvaddstr(14, 14, "Type '1' to keep >"); ch = getanswer(" ", TRUE); } while (ch != '1'); if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) /* get coordinates for experimento */ for (;;) { mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? "); getstring(Databuf, SZ_DATABUF); sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y); if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER) mvaddstr(17, 0, "Invalid coordinates. Try again.\n"); else break; } for (;;) /* name the new character */ { mvprintw(18, 0, "Give your character a name [up to %d characters] ? ", SZ_NAME - 1); getstring(Player.p_name, SZ_NAME); truncstring(Player.p_name); /* remove trailing blanks */ if (Player.p_name[0] == '\0') /* no null names */ mvaddstr(19, 0, "Invalid name."); else if (findname(Player.p_name, &Other) >= 0L) /* cannot have duplicate names */ mvaddstr(19, 0, "Name already in use."); else /* name is acceptable */ break; addstr(" Pick another.\n"); } /* get a password for character */ Echo = FALSE; do { mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? "); getstring(Player.p_password, SZ_PASSWORD); mvaddstr(21, 0, "One more time to verify ? "); getstring(Databuf, SZ_PASSWORD); } while (strcmp(Player.p_password, Databuf) != 0); Echo = TRUE; return(allocrecord());}/**//************************************************************************// FUNCTION NAME: procmain()// FUNCTION: process input from player// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: dotampered(), changestats(), inputoption(), allstatslist(), / fopen(), wmove(), drandom(), sscanf(), fclose(), altercoordinates(), / waddstr(), fprintf(), distance(), userlist(), leavegame(), encounter(), / getstring(), wclrtobot()// GLOBAL INPUTS: Circle, Illcmd[], Throne, Wizard, Player, *stdscr, / Databuf[], Illmove[]// GLOBAL OUTPUTS: Player, Changed// DESCRIPTION:/ Process main menu options.//************************************************************************/procmain(){int ch; /* input */double x; /* desired new x coordinate */double y; /* desired new y coordinate */double temp; /* for temporary calculations */FILE *fp; /* for opening files */register int loop; /* a loop counter */bool hasmoved = FALSE; /* set if player has moved */ ch = inputoption(); mvaddstr(4, 0, "\n\n"); /* clear status area */ move(7, 0); clrtobot(); /* clear data on bottom area of screen */ if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7')) /* valar cannot move */ ch = ' '; switch (ch) { case 'K': /* move up/north */ case 'N': x = Player.p_x; y = Player.p_y + MAXMOVE(); hasmoved = TRUE; break; case 'J': /* move down/south */ case 'S': x = Player.p_x; y = Player.p_y - MAXMOVE(); hasmoved = TRUE; break; case 'L': /* move right/east */ case 'E': x = Player.p_x + MAXMOVE(); y = Player.p_y; hasmoved = TRUE; break; case 'H': /* move left/west */ case 'W': x = Player.p_x - MAXMOVE(); y = Player.p_y; hasmoved = TRUE; break; default: /* rest */ Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0 + Player.p_level / 3.0 + 2.0; Player.p_energy = MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield); if (Player.p_status != S_CLOAKED) /* cannot find mana if cloaked */ { Player.p_mana += (Circle + Player.p_level) / 4.0; if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) /* wandering monster */ encounter(-1); } break; case 'X': /* change/examine a character */ changestats(TRUE); break; case '1': /* move */ for (loop = 3; loop; --loop) { mvaddstr(4, 0, "X Y Coordinates ? "); getstring(Databuf, SZ_DATABUF); if (sscanf(Databuf, "%lf %lf", &x, &y) != 2) mvaddstr(5, 0, "Try again\n"); else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE()) ILLMOVE(); else { hasmoved = TRUE; break; } } break; case '2': /* players */ userlist(TRUE); break; case '3': /* message */ mvaddstr(4, 0, "Message ? "); getstring(Databuf, SZ_DATABUF); /* we open the file for writing to erase any data which is already there */ fp = fopen(_PATH_MESS, "w"); if (Databuf[0] != '\0') fprintf(fp, "%s: %s", Player.p_name, Databuf); fclose(fp); break; case '4': /* stats */ allstatslist(); break; case '5': /* good-bye */ leavegame(); /*NOTREACHED*/ case '6': /* cloak */ if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK) ILLCMD(); else if (Player.p_status == S_CLOAKED) Player.p_status = S_PLAYING; else if (Player.p_mana < MM_CLOAK) mvaddstr(5, 0, "No mana left.\n"); else { Changed = TRUE; Player.p_mana -= MM_CLOAK; Player.p_status = S_CLOAKED; } break; case '7': /* teleport */ /* * conditions for teleport * - 20 per (level plus magic level) * - OR council of the wise or valar or ex-valar * - OR transport from throne * transports from throne cost no mana */ if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT) ILLCMD(); else for (loop = 3; loop; --loop) { mvaddstr(4, 0, "X Y Coordinates ? "); getstring(Databuf, SZ_DATABUF); if (sscanf(Databuf, "%lf %lf", &x, &y) == 2) { temp = distance(Player.p_x, x, Player.p_y, y); if (!Throne /* can transport anywhere from throne */ && Player.p_specialtype <= SC_COUNCIL /* council, valar can transport anywhere */ && temp > (Player.p_level + Player.p_magiclvl) * 20.0) /* can only move 20 per exp. level + mag. level */ ILLMOVE(); else { temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */ if (!Throne && temp > Player.p_mana) mvaddstr(5, 0, "Not enough power for that distance.\n"); else { if (!Throne) Player.p_mana -= temp; hasmoved = TRUE; break; } } } } break; case 'C': case '9': /* monster */ if (Throne) /* no monsters while on throne */ mvaddstr(5, 0, "No monsters in the chamber!\n"); else if (Player.p_specialtype != SC_VALAR) /* the valar cannot call monsters */ { Player.p_sin += 1e-6; encounter(-1); } break; case '0': /* decree */ if (Wizard || Player.p_specialtype == SC_KING && Throne) /* kings must be on throne to decree */ dotampered(); else ILLCMD(); break; case '8': /* intervention */ if (Wizard || Player.p_specialtype >= SC_COUNCIL) dotampered(); else ILLCMD(); break; } if (hasmoved) /* player has moved -- alter coordinates, and do random monster */ { altercoordinates(x, y, A_SPECIFIC); if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) encounter(-1); }}/**//************************************************************************// FUNCTION NAME: titlelist()// FUNCTION: print title page// AUTHOR: E. A. Estes, 12/4/85// ARGUMENTS: none// RETURN VALUE: none// MODULES CALLED: fread(), fseek(), fopen(), fgets(), wmove(), strcpy(), / fclose(), strlen(), waddstr(), sprintf(), wrefresh()// GLOBAL INPUTS: Lines, Other, *stdscr, Databuf[], *Playersfp// GLOBAL OUTPUTS: Lines// DESCRIPTION:/ Print important information about game, players, etc.//************************************************************************/titlelist(){register FILE *fp; /* used for opening various files */bool councilfound = FALSE; /* set if we find a member of the council */bool kingfound = FALSE; /* set if we find a king */double hiexp, nxtexp; /* used for finding the two highest players */double hilvl, nxtlvl; /* used for finding the two highest players */char hiname[21], nxtname[21];/* used for finding the two highest players */ mvaddstr(0, 14, "W e l c o m e t o P h a n t a s i a (vers. 3.3.2)!"); /* print message of the day */ if ((fp = fopen(_PATH_MOTD, "r")) != NULL && fgets(Databuf, SZ_DATABUF, fp) != NULL) { mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf); fclose(fp); } /* search for king */ fseek(Playersfp, 0L, 0); while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED) /* found the king */ { sprintf(Databuf, "The present ruler is %s Level:%.0f", Other.p_name, Other.p_level); mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf); kingfound = TRUE; break; } if (!kingfound) mvaddstr(4, 24, "There is no ruler at this time."); /* search for valar */ fseek(Playersfp, 0L, 0); while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED) /* found the valar */ { sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login); mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf); break; } /* search for council of the wise */ fseek(Playersfp, 0L, 0); Lines = 10; while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED) /* found a member of the council */ { if (!councilfound) { mvaddstr(8, 30, "Council of the Wise:"); councilfound = TRUE; } /* This assumes a finite (<=5) number of C.O.W.: */ sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login); mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf); } /* search for the two highest players */ nxtname[0] = hiname[0] = '\0'; hiexp = 0.0; nxtlvl = hilvl = 0; fseek(Playersfp, 0L, 0); while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED) /* highest found so far */ { nxtexp = hiexp; hiexp = Other.p_experience; nxtlvl = hilvl; hilvl = Other.p_level; strcpy(nxtname, hiname); strcpy(hiname, Other.p_name); } else if (Other.p_experience > nxtexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED) /* next highest found so far */ { nxtexp = Other.p_experience; nxtlvl = Other.p_level; strcpy(nxtname, Other.p_name); } mvaddstr(15, 28, "Highest characters are:"); sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f", hiname, hilvl, nxtname, nxtlvl); mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf); /* print last to die */ if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL && fgets(Databuf, SZ_DATABUF, fp) != NULL) { mvaddstr(19, 25, "The last character to die was:"); mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf); fclose(fp); } refresh();}/**//************************************************************************// FUNCTION NAME: recallplayer()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -