home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1997 January / CD_shareware_1-97.iso / DOS / JUEGOS / SERVER1.ZIP / _VOTE.QC < prev    next >
Encoding:
Text File  |  1996-09-04  |  7.8 KB  |  257 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.    stuffcmd(player,"alias votes \"impulse 212\";\n");
  40.    if (USE_SUBMODULE_VOTE_EXIT) {
  41.       stuffcmd(player,"alias vote-exit \"impulse 213\";\n");
  42.    }
  43.    if (USE_SUBMODULE_VOTE_EXIT) {
  44.       stuffcmd(player,"alias vote-exitrules \"impulse 214\";\n");
  45.    }
  46. };
  47.  
  48. void(entity player) VoteHelp =
  49. {
  50.    if (!USE_MODULE_VOTE) return;
  51.  
  52.                // 123456789#123456789#123456789#12345678
  53.    sprint(player,"# Vote: vote via one of the commands\n");
  54.    VoteExitHelp(player);
  55.    VoteExitRulesHelp(player); //#jp#(ExitRules)
  56.    sprint(player,"  The command 'votes' shows current\n");
  57.    sprint(player,"  voting statistics.\n");
  58. };
  59.  
  60. void(entity player) VoteShowVotes =
  61. {
  62.    local float num2,req_votes;
  63.    local string numstr;
  64.  
  65.    //dprint("VoteShowVotes: executing\n");
  66.  
  67.    if (!USE_MODULE_VOTE) return;
  68.  
  69.    VoteCheckVotes();
  70.  
  71.    req_votes = 0;
  72.    num2 = vote_voters;
  73.    while (num2 > 0) { req_votes = req_votes + 1; num2 = num2 - 2; }
  74.  
  75.                // 123456789#123456789#123456789#12345678
  76.    sprint(player,"Statistics for ");
  77.    numstr = ftos(vote_voters);
  78.    sprint(player,numstr);
  79.    if (vote_voters != 1) sprint(player," voters:\n");
  80.    else                  sprint(player," voter:\n");
  81.    if (USE_SUBMODULE_VOTE_EXITRULES) {            //#jp#(ExitRules)
  82.       sprint(player,"  vote-exitrules: ");        //#jp#(ExitRules)
  83.       if (exitrules_status == EXITRULES_STATUS_TIGHT) {    //#jp#(ExitRules)
  84.          numstr = ftos(vote_pro_exitrules);        //#jp#(ExitRules)
  85.          sprint(player,numstr);                //#jp#(ExitRules)
  86.          sprint(player," (");                //#jp#(ExitRules)
  87.          numstr = ftos(req_votes);            //#jp#(ExitRules)
  88.          sprint(player,numstr);                //#jp#(ExitRules)
  89.          sprint(player," required)");            //#jp#(ExitRules)
  90.          sprint(player,"\n");                //#jp#(ExitRules)
  91.       } else {                        //#jp#(ExitRules)
  92.          sprint(player,"exiting is allowed\n");        //#jp#(ExitRules)    
  93.       }                            //#jp#(ExitRules)
  94.    }                            //#jp#(ExitRules)
  95.    if (USE_SUBMODULE_VOTE_EXIT) {
  96.       sprint(player,"  vote-exit:      ");
  97.       if (vote_exit_status & VOTE_EXIT_ENABLED) {
  98.          numstr = ftos(vote_pro_exit);
  99.          sprint(player,numstr);
  100.          sprint(player," (");
  101.          numstr = ftos(req_votes);
  102.          sprint(player,numstr);
  103.          sprint(player," required)");
  104.          sprint(player,"\n");
  105.       } else {
  106.          sprint(player,"disabled\n");    
  107.       }
  108.    }
  109. };
  110.  
  111. float() VoteThink =
  112. {
  113.  
  114.    //dprint("VoteThink: executing\n");
  115.  
  116.    if (!USE_MODULE_VOTE) {
  117.       vote_checktime = vote_checktime + 500000;
  118.       return;
  119.    }
  120.    if (!vote_checktime) {
  121.       // don't allow voting for exiting on start level
  122.       if (world.model == "maps/start.bsp") vote_exit_status = VOTE_EXIT_DISABLED;
  123.       else                                 vote_exit_status = VOTE_EXIT_ENABLED;
  124.       vote_checktime = time + 40;
  125.       return;
  126.    }
  127.    if (time < 60) return; // make sure all player are in the level
  128.  
  129.    vote_checktime = time + 10;
  130.  
  131.    VoteCheckVotes();
  132.  
  133.    if (vote_voters && vote_pro_exit && (vote_pro_exit >= vote_voters * 0.5)) {
  134.       VoteExitExit();
  135.       return;
  136.    }
  137.  
  138.    if (   vote_voters && vote_pro_exitrules        //#jp#(ExitRules)
  139.        && (vote_pro_exitrules >= vote_voters * 0.5)) {    //#jp#(ExitRules)
  140.       VoteExitRulesDisable();                //#jp#(ExitRules)
  141.    }                            //#jp#(ExitRules)
  142. };
  143.  
  144. void() VoteCheckVotes =
  145. {
  146.    local entity e;
  147.  
  148.    //dprint("VoteCheckVotes: executing\n");
  149.  
  150.    vote_voters = vote_pro_exitrules = vote_pro_exit = 0;
  151.    e = find(world, classname, "player");
  152.    while (e != world) {
  153.       if (!PlayerStatusPlayerIsBogusPlayer(e)) {
  154.          vote_pro_exitrules = vote_pro_exitrules + e.vote_exitrules;
  155.          vote_pro_exit      = vote_pro_exit      + e.vote_exit;
  156.          vote_voters = vote_voters + 1;
  157.       }
  158.       e = find(e, classname, "player");
  159.    }
  160. };
  161.  
  162. /*
  163. ===============================================================
  164.     Voting for exiting immediately
  165. ===============================================================
  166. */
  167.  
  168. void(entity player) VoteExitHelp =
  169. {
  170.    if (!USE_MODULE_VOTE) return;
  171.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  172.                // 123456789#123456789#123456789#12345678
  173.    sprint(player,"  vote-exit: the majority may decide\n");
  174.    sprint(player,"     to exit the level immediately.\n");
  175. };
  176.  
  177. void(entity player) VoteExitVote =
  178. {
  179.    if (!USE_MODULE_VOTE) return;
  180.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  181.  
  182.    if (vote_exit_status & VOTE_EXIT_DISABLED) {
  183.                   // 123456789#123456789#123456789#12345678
  184.       sprint(player,"Voting for exiting is not possible\non this level.\n");
  185.       return;
  186.    }
  187.  
  188.    if (player.vote_exit) {
  189.       player.vote_exit = 0;
  190.       sprint(player,"Vote against exiting accepted\n");
  191.    } else {
  192.       player.vote_exit = 1;
  193.       sprint(player,"Vote for exiting accepted\n");
  194.    }
  195.    vote_checktime = -100;
  196. };
  197.  
  198. void() VoteExitExit =
  199. {
  200.    if (!USE_MODULE_VOTE) return;
  201.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  202.    bprint ("The majority decided to exit.\n");
  203.    if (USE_MODULE_SERVERCONSOLE) {            //#jp#(ServerConsole)
  204.       dprint ("The majority decided to exit.\n");    //#jp#(ServerConsole)
  205.    }                            //#jp#(ServerConsole)
  206.    NextLevel();
  207. };
  208.  
  209. /*
  210. ===============================================================
  211.     Voting for disabling ExitRules
  212.     //#jp#(ExitRules)
  213. ===============================================================
  214. */
  215.  
  216. void(entity player) VoteExitRulesHelp =
  217. {
  218.    if (!USE_MODULE_VOTE) return;
  219.    if (!USE_SUBMODULE_VOTE_EXIT) return;
  220.                // 123456789#123456789#123456789#12345678
  221.    sprint(player,"  vote-exitrules: the majority may \n");
  222.    sprint(player,"     disable the current ExitRules.\n");
  223. };
  224.  
  225. void(entity player) VoteExitRulesVote =
  226. {
  227.    if (!USE_MODULE_VOTE) return;
  228.    if (!USE_MODULE_EXITRULES) return;
  229.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  230.  
  231.    if (exitrules_status != EXITRULES_STATUS_TIGHT) {
  232.                   // 123456789#123456789#123456789#12345678
  233.       sprint(player,"ExitRules are disbled on this level,\nvoting is not necessary.\n");
  234.       return;
  235.    }
  236.                // 123456789#123456789#123456789#12345678
  237.    sprint(player,"Vote for disabling ExitRules accepted\n");
  238.    player.vote_exitrules = 1;
  239.    vote_checktime = -100;
  240. };
  241.  
  242. void() VoteExitRulesDisable =
  243. {
  244.    //dprint("VoteExitRulesDisable: executing\n");
  245.    if (!USE_MODULE_EXITRULES) return;
  246.    if (!USE_SUBMODULE_VOTE_EXITRULES) return;
  247.    if (exitrules_status != EXITRULES_STATUS_TIGHT) return;
  248.  
  249.          // 123456789#123456789#123456789#12345678
  250.    bprint ("The majority disbled ExitRules, you\nmay exit at any time.\n");
  251.    if (USE_MODULE_SERVERCONSOLE) {            //#jp#(ServerConsole)
  252.       dprint ("The majority disabled ExitRules.\n");    //#jp#(ServerConsole)
  253.    }                            //#jp#(ServerConsole)
  254.    exitrules_status = EXITRULES_STATUS_SOFT;
  255. };
  256.  
  257.