stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus doc/ChangeLog.html doc/ccl/research.h...


From: Russell Smith
Subject: [Stratagus-CVS] stratagus doc/ChangeLog.html doc/ccl/research.h...
Date: Tue, 25 Nov 2003 14:59:52 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Russell Smith <address@hidden>  03/11/25 14:59:51

Modified files:
        doc            : ChangeLog.html 
        doc/ccl        : research.html 
        src/ai         : ai_resource.c 
        src/clone      : player.c 
        src/include    : upgrade.h upgrade_structs.h 
        src/network    : commands.c 
        src/unit       : depend.c upgrade.c 

Log message:
        Per UnitType limits (from François Beerten)

Patches:
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.585 stratagus/doc/ChangeLog.html:1.586
--- stratagus/doc/ChangeLog.html:1.585  Fri Nov 21 10:52:35 2003
+++ stratagus/doc/ChangeLog.html        Tue Nov 25 14:59:45 2003
@@ -2,7 +2,7 @@
 <html>
 <head>
 <!--
-----   $Id: ChangeLog.html,v 1.585 2003/11/21 15:52:35 pludov Exp $
+----   $Id: ChangeLog.html,v 1.586 2003/11/25 19:59:45 mr-russ Exp $
 
 ----   (c) Copyright 1998-2003 by Lutz Sammer
 
@@ -36,6 +36,7 @@
 <li>Future 2.00 Release<p>
     <ul>
     <li>++
+    <li>Per UnitType limits (from François Beerten)
     <li>Record and check sync info in replay (from Ludovic Pollet)
     <li>Fixed Bug #6670 Support for keyboards other than QWERTY (from Ludovic 
Pollet)
     <li>AI can use automatically transporters (Task #2852) (from Ludovic 
Pollet)
Index: stratagus/doc/ccl/research.html
diff -u stratagus/doc/ccl/research.html:1.16 
stratagus/doc/ccl/research.html:1.17
--- stratagus/doc/ccl/research.html:1.16        Tue Oct 28 17:35:40 2003
+++ stratagus/doc/ccl/research.html     Tue Nov 25 14:59:47 2003
@@ -83,19 +83,46 @@
 <a href="../../data/ccl/human/upgrade.ccl"> 
$LIBARYPATH/ccl/human/upgrade.ccl</a> ,
 <a href="../../data/ccl/orc/upgrade.ccl"> $LIBARYPATH/ccl/orc/upgrade.ccl</a>
 
+
+<a name="define-unit-allow"></a>
+<h3>(define-unit-allow name N N N N N N N N N N N N N N N N)</h3>
+
+Define how many units of each type a players can have during
+a level.
+
+<dl>
+<dt>name</dt>
+<dd>Name of an unit-type to be defined.
+</dd>
+<dt>N</dt>
+<dd>
+  The initial quantity of units per type at level start.
+  Each player has his quatinty, the first is for player 0 and the last
+  is for player 15.
+</dd>
+</dl>
+
+<h4>Example</h4>
+
+<pre>
+    ;; Allow the catapult for the 2nd player.
+    (define-unit-allow 'unit-catapult  0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
+</pre>
+
+
 <a name="define-allow"></a>
 <h3>(define-allow name str16)</h3>
 
-Define what unit-types and upgrades are enabled for each player during
+Define what upgrades are enabled for each player during
 a level.
 
 <dl>
 <dt>name</dt>
-<dd>Name of an unit-type or an upgrade to be defined.
+<dd>Name of an upgrade to be defined.
 </dd>
 <dt>str16</dt>
 <dd>
-  The initial allow state for the unit-type or upgrade at level start:
+  The initial allow state for the upgrade at level start:
   <ul>
   <li>A - Allowed
   <li>E - Enabled, allowed by level but currently forbidden
@@ -111,8 +138,8 @@
 <h4>Example</h4>
 
 <pre>
-    ;; Allow the catapult for all 16 players.
-    (define-allow 'unit-catapult  "AAAAAAAAAAAAAAAA")
+    ;; Allow the metal upgrade for all 16 players.
+    (define-allow 'upgrade-metal  "AAAAAAAAAAAAAAAA")
     ;;                             ^- player 0    ^- player 15
 </pre>
 
@@ -225,8 +252,13 @@
   <dd>Change the costs for the resource type of all unit-types
   or upgrade-ids given with '(apply-to ...).
   </dd>
-  <dt>'(allow unit-type-id N) or '(allow upgrade-id N)</dt>
-  <dd>Change the state of an unit-type or upgrade. N can be
+  <dt>'(allow-unit unit-type-id N)</dt>
+  <dd>
+      Change the state of an upgrade. N is the maximum quantity
+      of this unit per player.
+  </dd>
+  <dt>'(allow upgrade-id N)</dt>
+  <dd>Change the state of an upgrade. N can be
       <ul>
       <li>A - Allowed
       <li>E - Enabled, allowed by level but currently forbidden
@@ -327,7 +359,7 @@
 <a href="../../data/ccl/orc/upgrade.ccl"> $LIBARYPATH/ccl/orc/upgrade.ccl</a>
 
 <hr>
-Last changed: $Id: research.html,v 1.16 2003/10/28 22:35:40 jsalmon3 Exp $<br>
+Last changed: $Id: research.html,v 1.17 2003/11/25 19:59:47 mr-russ Exp $<br>
 All trademarks and copyrights on this page are owned by their respective 
owners.
 <address>(c) 2002-2003 by<a href="http://stratagus.org";>
 The Stratagus Project</a></address></body></html>
Index: stratagus/src/ai/ai_resource.c
diff -u stratagus/src/ai/ai_resource.c:1.82 stratagus/src/ai/ai_resource.c:1.83
--- stratagus/src/ai/ai_resource.c:1.82 Mon Nov 24 17:06:54 2003
+++ stratagus/src/ai/ai_resource.c      Tue Nov 25 14:59:48 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_resource.c,v 1.82 2003/11/24 22:06:54 pludov Exp $
+//      $Id: ai_resource.c,v 1.83 2003/11/25 19:59:48 mr-russ Exp $
 
 //@{
 
@@ -417,7 +417,7 @@
     AiUnitTypeTable *const *tablep;
     const AiUnitTypeTable *table;
 
-    if (!UnitIdAllowed(AiPlayer->Player, type->Type)) {
+    if (UnitIdAllowed(AiPlayer->Player, type->Type) == 0) {
        DebugLevel0Fn("Can't build `%s' now\n" _C_ type->Ident);
        return 0;
     }
Index: stratagus/src/clone/player.c
diff -u stratagus/src/clone/player.c:1.102 stratagus/src/clone/player.c:1.103
--- stratagus/src/clone/player.c:1.102  Thu Nov 20 02:59:43 2003
+++ stratagus/src/clone/player.c        Tue Nov 25 14:59:49 2003
@@ -1,4 +1,4 @@
-//       _________ __                 __                               
+//       _________ __                 __
 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: player.c,v 1.102 2003/11/20 07:59:43 nehalmistry Exp $
+//     $Id: player.c,v 1.103 2003/11/25 19:59:49 mr-russ Exp $
 
 //@{
 
@@ -220,7 +220,7 @@
     int j;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.102 2003/11/20 
07:59:43 nehalmistry Exp $\n\n");
+    CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.103 2003/11/25 
19:59:49 mr-russ Exp $\n\n");
 
     //
     // Dump table wc2 race numbers -> internal symbol.
@@ -639,6 +639,10 @@
        if (player->TotalNumUnits >= player->TotalUnitLimit) {
            NotifyPlayer(player, NotifyYellow, 0, 0, "Unit Limit Reached");
            return -4;
+       }
+       if (player->UnitTypesCount[type->Type] >=  
player->Allow.Units[type->Type]) {
+           NotifyPlayer(player, NotifyYellow, 0, 0, "Limit Reached for this 
unit type");
+           return -6;
        }
        return 1;
     } else {
Index: stratagus/src/include/upgrade.h
diff -u stratagus/src/include/upgrade.h:1.29 
stratagus/src/include/upgrade.h:1.30
--- stratagus/src/include/upgrade.h:1.29        Sun Aug 17 11:57:07 2003
+++ stratagus/src/include/upgrade.h     Tue Nov 25 14:59:49 2003
@@ -1,4 +1,4 @@
-//       _________ __                 __                               
+//       _________ __                 __
 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: upgrade.h,v 1.29 2003/08/17 15:57:07 n0body Exp $
+//     $Id: upgrade.h,v 1.30 2003/11/25 19:59:49 mr-russ Exp $
 
 #ifndef __UPGRADE_H__
 #define __UPGRADE_H__
@@ -160,8 +160,8 @@
 
 // all the following functions are just map handlers, no specific notes
 // id -- unit type id, af -- `A'llow/`F'orbid
-extern void AllowUnitId( Player* player, int id, char af );
-extern void AllowUnitByIdent( Player* player, const char* sid, char af );
+extern void AllowUnitId( Player* player, int id, int units );
+extern void AllowUnitByIdent( Player* player, const char* sid, int units );
 
 extern void AllowActionId( Player* player,  int id, char af );
 extern void AllowActionByIdent( Player* player, const char* sid, char af );
@@ -169,10 +169,10 @@
 extern void AllowUpgradeId( Player* player,  int id, char af );
 extern void AllowUpgradeByIdent( Player* player, const char* sid, char af );
 
-extern void AllowByIdent( Player* player, const char* sid, char af );
+extern void AllowByIdent( Player* player, const char* sid, int units );
 
-extern char UnitIdAllowed(const Player* player,  int id );
-extern char UnitIdentAllowed(const Player* player,const char* sid );
+extern int UnitIdAllowed(const Player* player,  int id );
+extern int UnitIdentAllowed(const Player* player,const char* sid );
 
 extern char ActionIdAllowed(const Player* player,  int id );
 extern char ActionIdentAllowed(const Player* player,const char* sid );
Index: stratagus/src/include/upgrade_structs.h
diff -u stratagus/src/include/upgrade_structs.h:1.27 
stratagus/src/include/upgrade_structs.h:1.28
--- stratagus/src/include/upgrade_structs.h:1.27        Tue Oct 21 18:31:32 2003
+++ stratagus/src/include/upgrade_structs.h     Tue Nov 25 14:59:49 2003
@@ -1,4 +1,4 @@
-//       _________ __                 __                               
+//       _________ __                 __
 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: upgrade_structs.h,v 1.27 2003/10/21 22:31:32 jsalmon3 Exp $
+//     $Id: upgrade_structs.h,v 1.28 2003/11/25 19:59:49 mr-russ Exp $
 
 #ifndef __UPGRADE_STRUCTS_H__
 #define __UPGRADE_STRUCTS_H__
@@ -183,7 +183,7 @@
   // `?' -- leave as is, `F' -- forbid, `A' -- allow
   // FIXME: see below allow more semantics?
   // FIXME: pointers or ids would be faster and less memory use
-  char ChangeUnits[UnitTypeMax];       /// allow/forbid units
+  int  ChangeUnits[UnitTypeMax];       /// add/remove allowed units
   char ChangeUpgrades[UpgradeMax];     /// allow/forbid upgrades
   char ApplyTo[UnitTypeMax];           /// which unit types are affected
 
@@ -206,7 +206,7 @@
 ***            @li `X' -- fixed, acquired can't be disabled
 */
 typedef struct _allow_ {
-    char       Units[UnitTypeMax];     /// units allowed/disallowed
+    int                Units[UnitTypeMax];     /// maximum amount of units 
allowed
     char       Upgrades[UpgradeMax];   /// upgrades allowed/disallowed
 } Allow;
 
Index: stratagus/src/network/commands.c
diff -u stratagus/src/network/commands.c:1.79 
stratagus/src/network/commands.c:1.80
--- stratagus/src/network/commands.c:1.79       Fri Nov 21 10:52:37 2003
+++ stratagus/src/network/commands.c    Tue Nov 25 14:59:49 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: commands.c,v 1.79 2003/11/21 15:52:37 pludov Exp $
+//     $Id: commands.c,v 1.80 2003/11/25 19:59:49 mr-russ Exp $
 
 //@{
 
@@ -240,7 +240,7 @@
 
     replay->Comment1 = strdup("Generated by Stratagus Version " VERSION 
"\"\n");
     replay->Comment2 = strdup("Visit http://Stratagus.Org for more 
information\"\n");
-    replay->Comment3 = strdup("$Id: commands.c,v 1.79 2003/11/21 15:52:37 
pludov Exp $");
+    replay->Comment3 = strdup("$Id: commands.c,v 1.80 2003/11/25 19:59:49 
mr-russ Exp $");
     
     if (GameSettings.NetGameType == SettingsSinglePlayerGame) {
        replay->Type = ReplaySinglePlayer;
@@ -681,6 +681,8 @@
     dunit = (ReplayStep->DestUnitNumber != -1 ? 
UnitSlots[ReplayStep->DestUnitNumber] : NoUnitP);
     val = ReplayStep->Value;
     num = ReplayStep->Num;
+
+    DebugCheck(strcmp(ReplayStep->UnitIdent,UnitSlots[unit]->Type->Ident));
     
     if (((signed)SyncRandSeed) != ReplayStep->SyncRandSeed) {
 #ifdef DEBUG   
Index: stratagus/src/unit/depend.c
diff -u stratagus/src/unit/depend.c:1.32 stratagus/src/unit/depend.c:1.33
--- stratagus/src/unit/depend.c:1.32    Wed Nov 12 15:31:17 2003
+++ stratagus/src/unit/depend.c Tue Nov 25 14:59:50 2003
@@ -1,4 +1,4 @@
-//       _________ __                 __                               
+//       _________ __                 __
 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: depend.c,v 1.32 2003/11/12 20:31:17 jsalmon3 Exp $
+//     $Id: depend.c,v 1.33 2003/11/25 19:59:50 mr-russ Exp $
 
 //@{
 
@@ -200,7 +200,7 @@
     if (!strncmp(target, "unit-", 5)) {
        // target string refers to unit-XXX
        rule.Kind.UnitType = UnitTypeByIdent(target);
-       if (UnitIdAllowed(player, rule.Kind.UnitType->Type) != 'A') {
+       if (UnitIdAllowed(player, rule.Kind.UnitType->Type) == 0) {  
            return 0;
        }
        rule.Type = DependRuleUnitType;
@@ -286,7 +286,7 @@
     const DependRule* temp;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: dependencies $Id: depend.c,v 1.32 2003/11/12 
20:31:17 jsalmon3 Exp $\n\n");
+    CLprintf(file,";;; MODULE: dependencies $Id: depend.c,v 1.33 2003/11/25 
19:59:50 mr-russ Exp $\n\n");
 
     // Save all dependencies
 
Index: stratagus/src/unit/upgrade.c
diff -u stratagus/src/unit/upgrade.c:1.66 stratagus/src/unit/upgrade.c:1.67
--- stratagus/src/unit/upgrade.c:1.66   Sat Nov 22 11:18:49 2003
+++ stratagus/src/unit/upgrade.c        Tue Nov 25 14:59:50 2003
@@ -1,4 +1,4 @@
-//       _________ __                 __                               
+//       _________ __                 __
 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: upgrade.c,v 1.66 2003/11/22 16:18:49 jsalmon3 Exp $
+//     $Id: upgrade.c,v 1.67 2003/11/25 19:59:50 mr-russ Exp $
 
 //@{
 
@@ -51,9 +51,9 @@
 #include "etlib/hash.h"
 
 local int AddUpgradeModifierBase(int, int, int, int, int, int, int, int, int,
-    int*, const char*, const char*, const char*, UnitType*);
+    int*, const int[UnitTypeMax], const char*, const char*, UnitType*);
 local int AddUpgradeModifier(int, int, int, int, int, int, int, int,
-    int*, const char*, const char*, const char*);
+    int*, const int[UnitTypeMax], const char*, const char*);
 
 /*----------------------------------------------------------------------------
 --     Variables
@@ -361,17 +361,17 @@
                    if (v & (1 << b)) {
                        AllowUnitId(player,
                            UnitTypeByWcNum(unit_for_bit[i * 16 + 0 + b * 
2])->Type,
-                               'A');
+                               UnitMax);
                        AllowUnitId(player,
                            UnitTypeByWcNum(unit_for_bit[i * 16 + 1 + b * 
2])->Type,
-                               'A');
+                               UnitMax);
                    } else {
                        AllowUnitId(player,
                            UnitTypeByWcNum(unit_for_bit[i * 16 + 0 + b * 
2])->Type,
-                               'F');
+                               0);
                        AllowUnitId(player,
                            UnitTypeByWcNum(unit_for_bit[i * 16 + 1 + b * 
2])->Type,
-                               'F');
+                               0);
                    }
                }
            }
@@ -544,7 +544,7 @@
     int p;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: upgrades $Id: upgrade.c,v 1.66 2003/11/22 
16:18:49 jsalmon3 Exp $\n\n");
+    CLprintf(file, ";;; MODULE: upgrades $Id: upgrade.c,v 1.67 2003/11/25 
19:59:50 mr-russ Exp $\n\n");
 
     /* remove?
     //
@@ -625,8 +625,8 @@
        }
 
        for (j = 0; j < UnitTypeMax; ++j) {     // allow/forbid units
-           if (UpgradeModifiers[i]->ChangeUnits[j] != '?') {
-               CLprintf(file, "\n  '(allow %s %d)",
+           if (UpgradeModifiers[i]->ChangeUnits[j] != 0) {
+               CLprintf(file, "\n  '(allow-unit %s %d)",
                    UnitTypes[j]->Ident,
                    UpgradeModifiers[i]->ChangeUnits[j]);
            }
@@ -657,20 +657,20 @@
     // Save the allow
     //
     for (i = 0; i < NumUnitTypes; ++i) {
-       CLprintf(file, "(define-allow '%s\t", UnitTypes[i]->Ident);
+       CLprintf(file, "(define-unit-allow '%s\t", UnitTypes[i]->Ident);
        if (strlen(UnitTypes[i]->Ident) < 9) {
-           CLprintf(file, "\t\t\t\"");
+           CLprintf(file, "\t\t\t");
        } else if (strlen(UnitTypes[i]->Ident) < 17) {
-           CLprintf(file, "\t\t\"");
+           CLprintf(file, "\t\t");
        } else if (strlen(UnitTypes[i]->Ident) < 25) {
-           CLprintf(file, "\t\"");
+           CLprintf(file, "\t");
        } else {
-           CLprintf(file, "\"");
+           CLprintf(file, "");
        }
        for (p = 0; p < PlayerMax; ++p) {
-           CLprintf(file, "%c", Players[p].Allow.Units[i]);
+           CLprintf(file, "%d ", Players[p].Allow.Units[i]);
        }
-       CLprintf(file, "\")\n");
+       CLprintf(file, ")\n");
     }
     CLprintf(file, "\n");
 
@@ -723,7 +723,7 @@
     int regeneration_rate;
     int hit_points;
     int costs[MaxCosts];
-    char units[UnitTypeMax];
+    int units[UnitTypeMax];
     char upgrades[UpgradeMax];
     char apply_to[UnitTypeMax];
     UnitType* convert_to;
@@ -737,7 +737,7 @@
     hit_points = 0;
     regeneration_rate = 0;
     memset(costs, 0, sizeof(costs));
-    memset(units, '?', sizeof(units));
+    memset(units, 0, sizeof(units));
     memset(upgrades, '?', sizeof(upgrades));
     memset(apply_to, '?', sizeof(apply_to));
     convert_to = NULL;
@@ -790,6 +790,18 @@
            free(name);
            value = gh_cdr(value);
            costs[i] = gh_scm2int(gh_car(value));
+       } else if (gh_eq_p(temp, gh_symbol2scm("allow-unit"))) {
+           value = gh_cdr(value);
+           str = gh_scm2newstr(gh_car(value), NULL);
+           value = gh_cdr(value);
+           DebugLevel3Fn("%s\n" _C_ str);
+           if (!strncmp(str, "unit-", 5)) {
+               units[UnitTypeIdByIdent(str)] = gh_scm2int(gh_car(value));
+           } else {
+               free(str);
+               errl("unit expected", NIL);
+           }
+           free(str);
        } else if (gh_eq_p(temp, gh_symbol2scm("allow"))) {
            value = gh_cdr(value);
            str = gh_scm2newstr(gh_car(value), NULL);
@@ -797,11 +809,9 @@
            DebugLevel3Fn("%s\n" _C_ str);
            if (!strncmp(str, "upgrade-", 8)) {
                upgrades[UpgradeIdByIdent(str)] = gh_scm2int(gh_car(value));
-           } else if (!strncmp(str, "unit-", 5)) {
-               units[UnitTypeIdByIdent(str)] = gh_scm2int(gh_car(value));
-           } else {
+           }else {
                free(str);
-               errl("upgrade or unit expected", NIL);
+               errl("upgrade expected", NIL);
            }
            free(str);
        } else if (gh_eq_p(temp, gh_symbol2scm("apply-to"))) {
@@ -1099,13 +1109,48 @@
 #endif
 
 /**
+**     Define which units are allowed and how much.
+*/
+local SCM CclDefineUnitAllow(SCM list)
+{
+    SCM value;
+    char* ident;
+    int i;
+
+    if (!gh_null_p(list)) {
+       value = gh_car(list);
+       list = gh_cdr(list);
+       ident = gh_scm2newstr(value, NULL);
+
+       if (strncmp(ident, "unit-", 5)) {
+            DebugLevel0Fn(" wrong ident %s\n" _C_ ident);
+            free(ident);
+            return SCM_UNSPECIFIED;
+       }
+
+       i=0;
+       while (!gh_null_p(list) && i<16) {
+           value = gh_car(list);
+           list = gh_cdr(list);
+           AllowUnitByIdent(&Players[i], ident, gh_scm2int(value));
+           ++i;
+       }
+
+       free(ident);
+    }
+
+    return SCM_UNSPECIFIED;
+}
+
+
+/**
 **     Define which units/upgrades are allowed.
 */
 #if defined(USE_GUILE) || defined(USE_SIOD)
 local SCM CclDefineAllow(SCM list)
 {
     SCM value;
-    char* str;
+    char* ident;
     char* ids;
     int i;
     int n;
@@ -1113,22 +1158,31 @@
     while (!gh_null_p(list)) {
        value = gh_car(list);
        list = gh_cdr(list);
-       str = gh_scm2newstr(value, NULL);
+       ident = gh_scm2newstr(value, NULL);
        value = gh_car(list);
        list = gh_cdr(list);
        ids = gh_scm2newstr(value, NULL);
 
        n = strlen(ids);
        if (n > 16) {
-           fprintf(stderr, "%s: Allow string too long %d\n", str, n);
+           fprintf(stderr, "%s: Allow string too long %d\n", ident, n);
            n = 16;
        }
 
-       for (i = 0; i < n; ++i) {
-           AllowByIdent(&Players[i], str, ids[i]);
+       if (!strncmp(ident, "unit-", 5)) {
+           for (i = 0; i < n; ++i) {
+               if(ids[i]=='A') AllowUnitByIdent(&Players[i], ident, UnitMax);
+               if(ids[i]=='F') AllowUnitByIdent(&Players[i], ident, 0);
+           }
+       } else if (!strncmp(ident, "upgrade-", 8)) {
+           for (i = 0; i < n; ++i) {
+               AllowUpgradeByIdent(&Players[i], ident, ids[i]);
+           }
+       } else {
+               DebugLevel0Fn(" wrong ident %s\n" _C_ ident);
        }
 
-       free(str);
+       free(ident);
        free(ids);
     }
 
@@ -1238,6 +1292,7 @@
     gh_new_procedureN("define-modifier", CclDefineModifier);
     gh_new_procedureN("define-upgrade", CclDefineUpgrade);
     gh_new_procedureN("define-allow", CclDefineAllow);
+    gh_new_procedureN("define-unit-allow", CclDefineUnitAllow);
 
     gh_new_procedureN("define-upgrade-wc-names", CclDefineUpgradeWcNames);
 #elif defined(USE_LUA)
@@ -1270,7 +1325,7 @@
 **     @param speed            Speed modification (Currently not possible).
 **     @param hit_points       Hitpoint modification.
 **     @param costs            Costs modification.
-**     @param af_units         Changes in allow units.
+**     @param units[UnitTypeMax]       Changes in allowed units.
 **     @param af_upgrades      Changes in allow upgrades.
 **     @param apply_to         Applies to this units.
 **     @param convert_to       Converts units to this unit-type.
@@ -1280,7 +1335,8 @@
 */
 local int AddUpgradeModifierBase(int uid, int attack_range, int sight_range,
     int basic_damage, int piercing_damage, int armor, int speed,
-    int hit_points, int regeneration_rate, int* costs,const char* af_units,
+    int hit_points, int regeneration_rate, int* costs,
+    const int units[UnitTypeMax],
     const char* af_upgrades, const char* apply_to, UnitType* convert_to)
 {
     int i;
@@ -1307,7 +1363,7 @@
        um->Modifier.Costs[i]   = costs[i];
     }
 
-    memcpy(um->ChangeUnits, af_units, sizeof(um->ChangeUnits));
+    memcpy(um->ChangeUnits, units, sizeof(um->ChangeUnits));
     memcpy(um->ChangeUpgrades, af_upgrades, sizeof(um->ChangeUpgrades));
     memcpy(um->ApplyTo, apply_to, sizeof(um->ApplyTo));
 
@@ -1325,9 +1381,9 @@
 local int AddUpgradeModifier(int uid, int attack_range, int sight_range,
     int basic_damage, int piercing_damage, int armor, int speed,
     int hit_points, int* costs,
+    const int units[UnitTypeMax],
     // following are comma separated list of required string id's
-    const char* af_units,    // "A:unit-mage,F:unit-grunt" -- allow mages, 
forbid grunts
-    const char* af_upgrades, // "F:upgrade-Shield1,R:upgrade-ShieldTotal" -- :)
+    const char* af_upgrades,
     const char* apply_to           // "unit-peon,unit-peasant"
     )
 {
@@ -1360,28 +1416,11 @@
     // FIXME: it will be good if things are checked for errors better!
     // FIXME: perhaps the function `strtok()' should be replaced with local 
one?
 
-    memset(um->ChangeUnits,    '?', sizeof(um->ChangeUnits));
+    memcpy(um->ChangeUnits, units, sizeof(um->ChangeUnits));
     memset(um->ChangeUpgrades, '?', sizeof(um->ChangeUpgrades));
     memset(um->ApplyTo,        '?', sizeof(um->ApplyTo));
 
     //
-    // get allow/forbid's for units
-    //
-    s1 = strdup(af_units);
-    DebugCheck(!s1);
-    for (s2 = strtok(s1, ","); s2; s2 = strtok(NULL, ",")) {
-       int id;
-       DebugCheck(!(s2[0] == 'A' || s2[0] == 'F'));
-       DebugCheck(!(s2[1] == ':'));
-       id = UnitTypeIdByIdent(s2 + 2);
-       if (id == -1) {
-           continue;           // should we cancel all and return error?!
-       }
-       um->ChangeUnits[id] = s2[0];
-    }
-    free(s1);
-
-    //
     // get allow/forbid's for upgrades
     //
     s1 = strdup(af_upgrades);
@@ -1436,6 +1475,9 @@
     )
 {
     Upgrade* up;
+    int units[UnitTypeMax];
+
+    memset(units,0,sizeof(UnitTypeMax));
 
     up = AddUpgrade(ident, icon, costs);
     if (!up)  {
@@ -1444,7 +1486,7 @@
     AddUpgradeModifier(up-Upgrades, attack_range, sight_range, basic_damage,
        piercing_damage, armor, speed, hit_points,
        mcosts,
-       "", "", // no allow/forbid maps
+       units, "", // no allow/forbid maps
        apply_to);
 }
 
@@ -1620,16 +1662,11 @@
     }
 
     for (z = 0; z < UnitTypeMax; ++z) {
-       // allow/forbid unit types for player
+       // add/remove allowed units
 
        // FIXME: check if modify is allowed
 
-       if (um->ChangeUnits[z] == 'A') {
-           player->Allow.Units[z] = 'A';
-       }
-       if (um->ChangeUnits[z] == 'F') {
-           player->Allow.Units[z] = 'F';
-       }
+       player->Allow.Units[z] += um->ChangeUnits[z];
 
        DebugCheck(!(um->ApplyTo[z] == '?' || um->ApplyTo[z] == 'X'));
 
@@ -1738,12 +1775,11 @@
 **
 **     @param player   Player to change
 **     @param id       unit type id
-**     @param af       `A'llow/`F'orbid/`R'eseached
+**     @param units    maximum amount of units allowed
 */
-global void AllowUnitId(Player* player, int id, char af)
+global void AllowUnitId(Player* player, int id, int units)
 {
-    DebugCheck(!(af == 'A' || af == 'F' || af == 'R'));
-    player->Allow.Units[id] = af;
+    player->Allow.Units[id] = units;
 }
 
 /**
@@ -1762,12 +1798,12 @@
 /**
 **     FIXME: docu
 */
-global char UnitIdAllowed(const Player* player, int id)
+global int UnitIdAllowed(const Player* player, int id)
 {
     // JOHNS: Don't be kind, the people should code correct!
-    DebugCheck(id < 0 || id >= UpgradeMax);
-    if (id < 0 || id >= UpgradeMax) {
-       return 'F';
+    DebugCheck(id < 0 || id >= UnitTypeMax);
+    if (id < 0 || id >= UnitTypeMax) {
+       return 0;
     }
     return player->Allow.Units[id];
 }
@@ -1804,9 +1840,9 @@
 /**
 **     FIXME: docu
 */
-global void AllowUnitByIdent(Player* player, const char* ident, char af)
+global void AllowUnitByIdent(Player* player, const char* ident, int units)
 {
-    AllowUnitId(player, UnitTypeIdByIdent(ident), af);
+    AllowUnitId(player, UnitTypeIdByIdent(ident), units);
 }
 
 /**
@@ -1818,20 +1854,6 @@
 }
 
 /**
-**     FIXME: docu
-*/
-global void AllowByIdent(Player* player,  const char* ident, char af)
-{
-    if (!strncmp(ident, "unit-", 5)) {
-       AllowUnitByIdent(player, ident, af);
-    } else if (!strncmp(ident, "upgrade-", 8)) {
-       AllowUpgradeByIdent(player, ident, af);
-    } else {
-       DebugLevel0Fn(" wrong ident %s\n" _C_ ident);
-    }
-}
-
-/**
 **     Return the allow state of an unit-type.
 **
 **     @param player   Check state for this player.
@@ -1842,7 +1864,7 @@
 **
 **     @see Allow
 */
-global char UnitIdentAllowed(const Player* player, const char* ident)
+global int UnitIdentAllowed(const Player* player, const char* ident)
 {
     return UnitIdAllowed(player, UnitTypeIdByIdent(ident));
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]