home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq090 / _vote.qc < prev    next >
Encoding:
Text File  |  1996-08-29  |  5.9 KB  |  201 lines

  1. /*
  2. **
  3. ** _vote.qc (Vote Code, 1.0)
  4. **
  5. ** Copyright (C) 1996 Johannes Plass
  6. ** 
  7. ** This program is free software; you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation; either version 2 of the License, or
  10. ** (at your option) any later version.
  11. ** 
  12. ** This program is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with this program; if not, write to the Free Software
  19. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ** 
  21. ** Author:   Johannes Plass (plass@dipmza.physik.uni-mainz.de)
  22. **
  23. */
  24.  
  25. void(entity player) VoteInfo =
  26. {
  27.    if (!USE_MODULE_VOTE) return;
  28.  
  29.    //             123456789#123456789#123456789#12345678
  30.    sprint(player,"# Vote: decide by voting.\n");
  31.    sprint(player,"  Type 'help-vote' for help.\n");
  32. };
  33.  
  34. void(entity player) VoteInit =
  35. {
  36.    if (!USE_MODULE_VOTE) return;
  37.  
  38.    stuffcmd(player,"alias help-vote \"impulse 211\";\n");
  39.    if (USE_SUBMODULE_VOTE_EXIT) {
  40.       stuffcmd(player,"alias vote-exit \"impulse 212\";\n");
  41.    }
  42.    if (USE_SUBMODULE_VOTE_EXIT) {
  43.       stuffcmd(player,"alias vote-exitrules \"impulse 213\";\n");
  44.    }
  45. };
  46.  
  47. void(entity player) VoteHelp =
  48. {
  49.    if (!USE_MODULE_VOTE) return;
  50.  
  51.    if (   !USE_SUBMODULE_VOTE_EXIT
  52.        && !USE_SUBMODULE_VOTE_EXITRULES) //#jp#(ExitRules)
  53.       return;
  54.  
  55.       //          123456789#123456789#123456789#12345678
  56.    sprint(player,"# Vote: vote via one of the commands\n");
  57.    VoteExitHelp(player);
  58.    VoteExitRulesHelp(player); //#jp#(ExitRules)
  59. };
  60.  
  61. float() VoteCheckVotes =
  62. {
  63.  
  64.    if (!USE_MODULE_VOTE) {
  65.       vote_checktime = vote_checktime + 500000;
  66.       return(0);
  67.    }
  68.    if (!vote_checktime) {
  69.       vote_checktime = time + 30;
  70.       return(0);
  71.    }
  72.    vote_checktime = vote_checktime + 10;
  73.  
  74.    if (   !USE_SUBMODULE_VOTE_EXIT
  75.        && !USE_SUBMODULE_VOTE_EXITRULES) //#jp#(ExitRules)
  76.       return(0);
  77.  
  78.    // dprint("VoteCheckVotes: executing\n");
  79.    {
  80.       local float n_exitrules,n_exit,p;
  81.       local entity e;
  82.       e = find(world, classname, "player");
  83.       p = n_exitrules = n_exit = 0;
  84.       while (e) {
  85.          if (e.deadflag != DEAD_DEAD) {
  86.             n_exitrules = n_exitrules + e.vote_exitrules;
  87.             n_exit      = n_exit      + e.vote_exit;
  88.             p = p + 1;
  89.          }
  90.          e = find(e, classname, "player");
  91.       }
  92.       if (p && n_exit && (n_exit >= p * 0.5)) {
  93.          VoteExitExit();
  94.          return(1);
  95.       }
  96.       if (p && n_exitrules && (n_exitrules >= p * 0.5)) {//#jp#(ExitRules)
  97.          VoteExitRulesDisable();            //#jp#(ExitRules)
  98.          return(1);                    //#jp#(ExitRules)
  99.       }                            //#jp#(ExitRules)
  100.       return(0);
  101.    }
  102. };
  103.  
  104. /*
  105. ===============================================================
  106.     Voting for exiting immediately
  107. ===============================================================
  108. */
  109.  
  110. void(entity player) VoteExitHelp =
  111. {
  112.    if (!USE_MODULE_VOTE) return;
  113.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  114.    //             123456789#123456789#123456789#12345678
  115.    sprint(player,"  vote-exit: the majority may decide\n");
  116.    sprint(player,"     to exit the level immediately.\n");
  117. };
  118.  
  119. void(entity player) VoteExitVote =
  120. {
  121.    if (!USE_MODULE_VOTE) return;
  122.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  123.  
  124.    // voting is not sensible on startlevel
  125.    if (world.model == "maps/start.bsp") {
  126.       //             123456789#123456789#123456789#12345678
  127.       sprint(player,"Voting for exiting not possible on\nthe start level.\n");
  128.       return;
  129.    }
  130.  
  131.    if (player.vote_exit) {
  132.       player.vote_exit = 0;
  133.       sprint(player,"Vote against exiting accepted\n");
  134.    } else {
  135.       player.vote_exit = 1;
  136.       sprint(player,"Vote for exiting accepted\n");
  137.    }
  138. };
  139.  
  140. void() VoteExitExit =
  141. {
  142.    if (!USE_MODULE_VOTE) return;
  143.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  144.    bprint ("The majority decided to exit.\n");
  145.    if (USE_MODULE_SERVERCONSOLE) {            //#jp#(ServerConsole)
  146.       dprint ("The majority decided to exit.\n");    //#jp#(ServerConsole)
  147.    }                            //#jp#(ServerConsole)
  148.    NextLevel();
  149. };
  150.  
  151. /*
  152. ===============================================================
  153.     Voting for disabling ExitRules
  154.     //#jp#(ExitRules)
  155. ===============================================================
  156. */
  157.  
  158. void(entity player) VoteExitRulesHelp =
  159. {
  160.    if (!USE_MODULE_VOTE) return;
  161.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  162.    //             123456789#123456789#123456789#12345678
  163.    sprint(player,"  vote-exitrules: the majority may \n");
  164.    sprint(player,"     disable the current ExitRules.\n");
  165. };
  166.  
  167. void(entity player) VoteExitRulesVote =
  168. {
  169.    if (!USE_MODULE_VOTE) return;
  170.    if (!USE_MODULE_EXITRULES) return;
  171.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  172.  
  173.    if (!exitrules_inited) { ExitRulesSetValues(); }
  174.    if (   exitrules_status != EXITRULES_STATUS_TIGHT
  175.        || world.model == "maps/start.bsp") {
  176.       //             123456789#123456789#123456789#12345678
  177.       sprint(player,"ExitRules are disbled on this level,\nvoting is not necessary.");
  178.       return;
  179.    }
  180.       //          123456789#123456789#123456789#12345678
  181.    sprint(player,"Vote for disabling ExitRules accepted\n");
  182.    player.vote_exitrules = 1;
  183. };
  184.  
  185. void() VoteExitRulesDisable =
  186. {
  187.    // dprint("VoteExitRulesDisable: executing\n");
  188.    if (!USE_MODULE_EXITRULES) return;
  189.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  190.    if (!exitrules_inited) { ExitRulesSetValues(); }
  191.    if (exitrules_status != EXITRULES_STATUS_TIGHT) return;
  192.  
  193.    //       123456789#123456789#123456789#12345678
  194.    bprint ("The majority disbled ExitRules, you\nmay exit at any time.\n");
  195.    if (USE_MODULE_SERVERCONSOLE) {            //#jp#(ServerConsole)
  196.       dprint ("The majority disabled ExitRules.\n");    //#jp#(ServerConsole)
  197.    }                            //#jp#(ServerConsole)
  198.    exitrules_status = EXITRULES_STATUS_SOFT;
  199. };
  200.  
  201.