home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume13 / dominion / part26 / spy.c < prev    next >
C/C++ Source or Header  |  1992-02-11  |  9KB  |  305 lines

  1.   /* spy.c -- things having to do with "other" nations and espionage */
  2.  
  3. /*
  4.  * Copyright (C) 1990 Free Software Foundation, Inc.
  5.  * Written by the dominion project.
  6.  *
  7.  * This file is part of dominion.
  8.  *
  9.  * dominion is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License as published
  11.  * by the Free Software Foundation; either version 1, or (at your option)
  12.  * any later version.
  13.  *
  14.  * This software is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this software; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. #include "dominion.h"
  25. #include "misc.h"
  26. #include <stdio.h>
  27. #include <ctype.h>
  28. #include <math.h>
  29.  
  30.   /* these macros represent the difficulty in gathering
  31.      inteligence in various areas.
  32.    */
  33. #define SPY_POP 1
  34. #define SPY_ECO 3
  35. #define SPY_MAG 4
  36. #define SPY_MIL 5
  37. #define SPY_TECHNO 5
  38. #define SPY_CAP 6
  39.  
  40. extern Sworld world;
  41. extern Suser user;
  42. extern char help_tag[];
  43.  
  44.   /* info on all nations in the world */
  45. char nations_report()
  46. {
  47.   WINDOW *w;
  48.   FILE *diplock;
  49.   char s[200];
  50.   Snation *np;
  51.   char c;
  52.   int i, done = 0, first_shown, n_shown, id;
  53.  
  54.   w = newwin(LINES-2, COLS, 0, 0); /* full screen */
  55.   werase(w);
  56.   touchwin(w);
  57.   sprintf(s, "report on all nations");
  58.   wmove(w, 0, (COLS-strlen(s))/2); /* make the string centered */
  59.   wstandout(w);
  60.   waddstr(w, s);
  61.   wclrtoeol(w);
  62.   wstandend(w);
  63.  
  64.     /* here go the guts */
  65.   sprintf(s,"World size is: %dx%d, there are %d nations",
  66.         world.xmax, world.ymax, world.n_nations);
  67.   wmove(w, 1, (COLS-strlen(s))/2); /* make the string centered */
  68.   waddstr(w, s);
  69.   mvwaddstr(w, 3, 0, " id");
  70.   mvwaddstr(w, 4, 0, "---");
  71.   mvwaddstr(w, 3, 5, "nation");
  72.   mvwaddstr(w, 4, 5, "------");
  73.   mvwaddstr(w, 3, 25, "mark");
  74.   mvwaddstr(w, 4, 25, "----");
  75.   mvwaddstr(w, 3, 31, "leader");
  76.   mvwaddstr(w, 4, 31, "------");
  77.   mvwaddstr(w, 3, 47, "race");
  78.   mvwaddstr(w, 4, 47, "----");
  79.   if (user.id == 0) {
  80.     mvwaddstr(w, 3, 55, "money");
  81.     mvwaddstr(w, 4, 55, "-----");
  82.     mvwaddstr(w, 3, 65, "civil");
  83.     mvwaddstr(w, 4, 65, "-----");
  84.   }
  85.     /* figure out which nations to show */
  86.   first_shown = 1;
  87.   n_shown = min(world.n_nations, LINES-10);
  88.   while (!done) {
  89.     strcpy(help_tag, "Nations Report");
  90.     for (i = 0; i < n_shown && i+first_shown < world.n_nations; ++i) {
  91.       np = &(world.nations[i+first_shown]);
  92.       mvwprintw(w, i+5, 0, "%3d", np->id);
  93.       wclrtoeol(w);
  94.       mvwaddstr(w, i+5, 5, np->name);
  95.       mvwaddch(w, i+5, 26, np->mark);
  96.       sprintf(s,"%-12.12s",np->leader);
  97.       mvwaddstr(w, i+5, 31, s);
  98.  
  99.       mvwaddstr(w, i+5, 47, np->race.name);
  100.  
  101.       if (!is_active_ntn(np)) {
  102.     mvwaddstr(w, i+5, 60, "DESTROYED");
  103.       } else if (user.id == 0) {
  104.     mvwprintw(w, i+5, 55, "%d", np->money);
  105.     mvwprintw(w, i+5, 65, "%d", get_n_civil(np));
  106.       }
  107.       if (np->npc_flag) {
  108.     mvwaddstr(w, i+5, 75, "npc");
  109.       }
  110.     }
  111.     wclrtobot(w);
  112.     mvwaddstr(w, LINES-4, 4,
  113.    "Options: [s]py on a nation, [<]/[,] previous screen, [>]/[.] next screen");
  114.     mvwaddstr(w, LINES-3, 4,
  115.           "Reports: [b]udget, [p]roduction, [i]nfo, [d]iplomacy");
  116.     wrefresh(w);
  117.     statline("type space when done, or F to dump to a file", "nations_report");
  118.  
  119.     switch (c = getch()) {
  120.     case '>':
  121.     case '.':
  122.       if (first_shown+n_shown < world.n_nations) {
  123.     first_shown += n_shown;
  124.       }
  125.       break;
  126.     case '<':
  127.     case ',':
  128.       if (first_shown > 1) {
  129.     first_shown -= n_shown;
  130.       }
  131.       break;
  132.     case 's':
  133.       mvwaddstr(w, LINES-3, 4, "  Number of nation to spy on? ");
  134.       wclrtoeol(w);
  135.       if (wget_number(w, &id) > 0 && is_active_ntn(&world.nations[id])
  136.       && id != user.np->id) {
  137.     if (user.id == 0) {    /* for the game master, give the total info */
  138.       (void) info_report(&world.nations[id]);
  139.     } else {
  140.       spy_report(id);
  141.     }
  142.     touchwin(w);
  143.       }
  144.       break;
  145.     case 'F':
  146.       dump_current_screen(w, "nations_report");
  147.       break;
  148.     case ' ':
  149.     case 'b':
  150.     case 'p':
  151.     case 'i':
  152.     case 'd':
  153.       done = 1;
  154.       break;
  155.     case '?':
  156.       online_info();
  157.       break;
  158.     default:
  159.       break;
  160.     }
  161.   }
  162.   delwin(w);
  163.   return c;
  164. }
  165.  
  166.   /* allow a nation to spy on anther */
  167. spy_report(id)
  168.      int id;
  169. {
  170.   WINDOW *spyw;
  171.   Snation *spied_np = &world.nations[id], *spying_np = user.np;
  172.   char s[EXECLEN];
  173.   char c;
  174.   int done = 0, bribe;        /* amount of jewels to get info */
  175.   int x, y;            /* for capital locations */
  176.  
  177.   strcpy(help_tag, "Nations Report");
  178.   spyw = newwin(18, 60, LINES-22, (COLS-60)/2);
  179.   werase(spyw);
  180.   touchwin(spyw);
  181.   while (!done) {
  182.     sprintf(s, "Espionage Report on nation %s", spied_np->name);
  183.     wmove(spyw, 1, (60-strlen(s))/2);
  184.     wstandout(spyw);
  185.     waddstr(spyw, s);
  186.     wclrtoeol(spyw);
  187.     wstandend(spyw);
  188.     /* put the guts between here and the wrefresh() */
  189.     mvwaddstr(spyw, 3, 5, "Spy on: [p]opulation, [e]conomy");
  190.     mvwaddstr(spyw, 4, 5, "        [m]ilitary, ma[g]ic, [C]apital location");
  191.     mvwaddstr(spyw, 5, 5, "        [t]echology, [T]echnology theft");
  192.     wclrtobot(spyw);
  193.     box(spyw, '|', '-');
  194.     wrefresh(spyw);
  195.     statline("type space when done, or F to dump to a file", "spy_report");
  196.     c = getch();
  197.     if (strchr("pemgCt", c) != NULL) {
  198.       mvwaddstr(spyw, 10, 1,
  199.         "How many jewels do you want to pay in bribes? ");
  200.       if (wget_number(spyw, &bribe) < 1 || bribe <= 0) {
  201.     continue;
  202.       }
  203.       if (bribe > spying_np->jewels) {
  204.     statline2_err("Hit space", "You don't have enough jewels");
  205.     continue;
  206.       }
  207.     }
  208.     switch (c) {
  209.     case '?':
  210.       online_info();
  211.       break;
  212.     case ' ':
  213.       done = 1;
  214.       break;
  215.     case 'p':            /* info on their population */
  216.       mvwprintw(spyw, 12, 6, "Population is %d",
  217.         spy_figure(get_n_civil(spied_np), bribe,
  218.         spying_np, spied_np, SPY_POP) );
  219.       break;
  220.     case 'e':            /* info on their military */
  221.       mvwprintw(spyw, 12, 4, "Money: %d",
  222.         spy_figure(spied_np->money, bribe,
  223.         spying_np, spied_np, SPY_ECO) );
  224.       mvwprintw(spyw, 12, 20, "Jewels: %d",
  225.         spy_figure(spied_np->jewels, bribe,
  226.         spying_np, spied_np, SPY_ECO) );
  227.       mvwprintw(spyw, 12, 36, "Metal: %d",
  228.         spy_figure(spied_np->metal, bribe,
  229.         spying_np, spied_np, SPY_ECO) );
  230.       mvwprintw(spyw, 13, 4, "Food: %d",
  231.         spy_figure(spied_np->food, bribe,
  232.         spying_np, spied_np, SPY_ECO) );
  233.       mvwprintw(spyw, 13, 20, "Tax: %d",
  234.         spy_figure(spied_np->taxes, bribe,
  235.         spying_np, spied_np, SPY_ECO) );
  236.       break;
  237.     case 'C':
  238.       x = spy_figure(spied_np->capital.x, bribe, spying_np, spied_np, SPY_CAP);
  239.       y = spy_figure(spied_np->capital.y, bribe, spying_np, spied_np, SPY_CAP);
  240.       x = xrel(x, y, spying_np->capital);
  241.       y = yrel(x, y, spying_np->capital);
  242.       mvwprintw(spyw, 13, 4, "Capital is at (%d, %d) ", x, y);
  243.       break;
  244.     case 't':            /* info on their technology */
  245.       mvwprintw(spyw, 12, 4, "Techno skill: %d",
  246.         spy_figure(spied_np->tech_skill, bribe,
  247.         spying_np, spied_np, SPY_TECHNO) );
  248.       break;
  249.     case 'm':            /* info on their military */
  250.       mvwprintw(spyw, 12, 4, "Soldiers: %d",
  251.         spy_figure(get_n_soldiers(spied_np), bribe,
  252.         spying_np, spied_np, SPY_MIL) );
  253.       break;
  254.     case 'g':            /* info on their magic */
  255.       mvwprintw(spyw, 12, 4, "Magic skill: %d",
  256.         spy_figure(spied_np->mag_skill, bribe,
  257.         spying_np, spied_np, SPY_MAG) );
  258.       mvwprintw(spyw, 13, 4, "Spell pts.: %d",
  259.         spy_figure(spied_np->spell_pts, bribe,
  260.         spying_np, spied_np, SPY_MAG) );
  261.       break;
  262.     }
  263.         /* this section is common to all bribes */
  264.     if (strchr("pemgCt", c) != NULL) {
  265.       mvwaddstr(spyw, 14, 10, "Hit space");
  266.       wrefresh(spyw);
  267.       get_space();
  268.       spying_np->jewels -= bribe;
  269.       cjewels(spying_np, -bribe);
  270.     }
  271.   }
  272.   delwin(spyw);
  273. }
  274.  
  275. spy_figure(n, expend, spying_np, spied_np, cost_fact)
  276.      int n,            /* number we modify here */
  277.        expend;            /* jewels spent on bribes */
  278.      Snation *spying_np, *spied_np; /* nations involved */
  279.      int cost_fact;        /* cost factor for type of info */
  280. {
  281.   double accuracy, error;
  282.   int figure;            /* the figure we actually return */
  283.   char s[400];
  284.  
  285.   if (spied_np->secrecy == 0) {
  286.     spied_np->secrecy = 1;    /* avoid divide-by-zero */
  287.   }
  288.   accuracy =
  289.     ((double) expend*spying_np->spy)/(cost_fact*spied_np->secrecy*100);
  290.   
  291.     /* now get the percent error */
  292.   error = 100*( exp(-sqrt(accuracy)) + 1.0/(5.0+accuracy) );
  293.   if (error > 100) {
  294.     error = 100;
  295.   }
  296. /*  sprintf(s, "acc=%f,%%err=%f", accuracy, error); */
  297.     /* now get the absolute error */
  298.   error = 1 + n*error/100.0;
  299.   figure = n + (RND() % ((int) error)) - (int) (error/2);
  300.  
  301. /*  statline2(s, ""); */
  302.  
  303.   return figure;
  304. }
  305.