Announcement

Collapse
No announcement yet.

DEBUG: Slic Dtabase Access

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DEBUG: Slic Dtabase Access

    I am trying to figure out where the problem of the slic database access lies. So far I know this:

    Code:
    	int1 = GovernmentDB(GOVERNMENT_CORPORATE_REPUBLIC).CrimeOffset;
    This does work the argument of GovernmentDB is a string variable of the government name or something like this. This doesn't work and make the game crash:

    Code:
    	int1 = GovernmentDB(3).CrimeOffset;
    I also know that the code somewhere converts the GOVERNMENT_CORPORATE_REPUBLIC into a number. Unfortunatly I don't know where it is determined that GovernmentDB accepts just an advance name/type or whatever but not a number, maybe it is somewhere in these *.y or *.l files determined, but so far I wasn't able to find it.

    I only found the place where you can have a GovernmentDB, unfortunatly it is a template and the parser is so far a miracle to me.

    So does anyone has some knowledge about Bison?

    -Martin
    Last edited by Martin Gühmann; January 15, 2004, 19:04.
    Civ2 military advisor: "No complaints, Sir!"

  • #2
    Well I found the place where it is defined and it is actual much easier to make it work for array like database refferences and add a way to get the number of entries in the database then to make it work at all.

    So far I have working these syntaces:

    Code:
    GovernmentDB(6);
    GovernmentDB(6).CrimeOffset;
    GovernmentDB(i);
    GovernmentDB(i).CrimeOffset;
    But this doen't work:

    Code:
    GovernmentDB(GovernmentDB(i));
    GovernmentDB(government[0]).CrimeOffset;
    GovernmentDB(i + 1);
    GovernmentDB(IsHumanPlayer(g.player));
    GovernmentDB(i + i).CrimeOffset;
    And here a small piece of the code from slic.y:

    Code:
    	|   DBREF '(' expression ')' REF NAME { slicif_add_op(SOP_PUSHI, slicif_find_db_value_by_index($1.dbptr, $3.val, $6.name)); }
    DBREF is something like OrderDB or anyother of the valids DB function and this is the first argument of the syntax definition. The '(' is the second part of the syntax definition, expression the thirsd ')' the forth, REF the fifth and NAME the sixth. Here we use the slicif_find_db_value_by_index to access the database. $1.dbptr comes from DBREF from the first part of the syntax definition. And $3.val comes from expression and is supposed to contain an integervalue, well it does contain something, something that can be interpreted as integer but that is not the value that the expression should contain. It looks for me that this value is never initialized.

    -Martin
    Civ2 military advisor: "No complaints, Sir!"

    Comment


    • #3
      I am trying to figure out where the problem of the slic database access lies.
      Are you trying to find a function that returns the GovernmentDB index rather than the string?

      I only found the place where you can have a GovernmentDB, unfortunatly it is a template and the parser is so far a miracle to me.
      Me too.

      Comment


      • #4
        OK, in the meantime I figured out that the slic.y and slic.l files contain the diffinition for syntax and such stuff, but it does not the code that does the computation at run time. So I have a valid syntax but the game still does not understand it.

        -Martin
        Civ2 military advisor: "No complaints, Sir!"

        Comment


        • #5
          I've used a parser generator before, but never Bison. I don't like the way it does things compared to the other one I've used, and I can't quite figure out what's really going on...

          I guess the problem here is that when you call .val on the expression it is returning the wrong thing - because the expression cannot be evaluated at compile time, so you need to shift the evaluation to be performed at run time.

          Quite how to do this I am not sure...

          Comment


          • #6
            I already found out where the stuff is calculated at run time, but unfortunatly I have to do some stuff for uni so that I can't look into it for the next one or two weeks.

            -Martin
            Civ2 military advisor: "No complaints, Sir!"

            Comment


            • #7
              I'm looking into this for the other issue. I'll probably bump into at least some info for this when I'm doing the alterations to the parser.

              Comment


              • #8
                This is actual slic not the database, the database parser generates actual some C++ code that is finally used in the program, but I think I don't need go into the details here.

                -Martin
                Civ2 military advisor: "No complaints, Sir!"

                Comment


                • #9
                  right... I understand...

                  Bison and flex parse the db structure datafiles, used by ctpdb to create the actual database parser and db classes in ctp2.exe

                  The issue is that the accessor used by the slic function accessing the data object takes a constant identifier.. rather than an index.

                  Comment


                  • #10
                    Originally posted by MrBaggins
                    right... I understand...

                    Bison and flex parse the db structure datafiles, used by ctpdb to create the actual database parser and db classes in ctp2.exe
                    Well that's right for Slic and the user interface but not for the database. The database files themselves are generated by dbgen and it looks like dbgen was writen by the CTP2 programmers.

                    Originally posted by MrBaggins
                    The issue is that the accessor used by the slic function accessing the data object takes a constant identifier.. rather than an index.
                    That's the problem for the Slic database function.

                    -Martin
                    Civ2 military advisor: "No complaints, Sir!"

                    Comment


                    • #11
                      So far I got this working:

                      Code:
                      	int_t i;
                      	i = 1;
                      	int8 = GovernmentDB(army[0].size + i + GovernmentDB(GOVERNMENT_CORPORATE_REPUBLIC) + IsHumanPlayer(g.player));
                      Well this is stupid but it should be possible according the slic documentation. The return value is the value of the argument, given there is a database entry with such an index, otherwise it returns -1 one, in the debug version you get an assert, but that shouldn't be a problem in the release version, well I think I leave the assert in maybe it is usefull at other places.

                      Unfortunatly this doesn't work as expected:

                      Code:
                      	government[0] = 3;
                      	int8 = GovernmentDB(government[0]);
                      -1 is returned.

                      Also this works:

                      Code:
                      	government[0] = 3;
                      	int8 = government[0];
                      -Martin
                      Civ2 military advisor: "No complaints, Sir!"

                      Comment


                      • #12
                        Now I have something like this working:

                        Code:
                        unitrecord[0] = MGUnit.type;
                        int7 = UnitDB(unitrecord[0]).ShieldCost;
                        int6 = UnitDB(unitrecord[0]).MaxMovePoints;
                        int9 = UnitDB(UNIT_SETTLER).MaxMovePoints;
                        As it is from the standart game known you get array index of bounce errors if you put between the assignment of the build in arry and it call some code. Does anybody know how the MaxMovePoints flag behaves in the official game, I tried it on the settler and I got 10000 MaxMovePoints instead of 100 as you find it in the unit.txt. Well at least with unit name and with a number you get the same value for MaxMovePoints. Well also in the Great Libary this is taken in consideration. So we shouldn't change it.

                        Another point I have now is when I use the /slicreload either from the Cheat Editor or from the Chat Window the CTP_LEAKS_99998.TXT gets filled with a lot of leaks.

                        So I fast does CTP2 quit afterwards you reloaded slic heavily.

                        -Martin
                        Civ2 military advisor: "No complaints, Sir!"

                        Comment


                        • #13
                          Nice work, Martin.

                          I tried it on the settler and I got 10000 MaxMovePoints instead of 100 as you find it in the unit.txt.
                          Some of the members of UnitRecord are doubles (m_MaxMovePoints is one of them) and Mr Ogre wrote:

                          Floating point values are multiplied by 100 and converted to ints, since SLIC does not otherwise support floating point variables.
                          I guess this is what you're seeing and you'll have to counter it.

                          Comment


                          • #14
                            Originally posted by Peter Triggs
                            Some of the members of UnitRecord are doubles (m_MaxMovePoints is one of them) and Mr Ogre wrote:
                            Indeed this flag is a float.

                            I also figuered out why there is now such a long delay until the program shuts down, in earlier versions of CTP2 I got some thousand asserts on close, and of course I had to click on the quit button. So I just notice now how long it need to write the CTP_LEAKS_99999.TXT and that was also the reason why it was so empty.

                            By the way now also this does something:

                            Code:
                            int2 = UnitDB();
                            This returns the number of entries in the according database. And it is computed during run time so that you can detect via slic when someone added something to the database during a game, so that you can warn him via slic.

                            The only problem I have is that this doesn't work:

                            Code:
                            		int3 = GovernmentDB(i).TooManyCitiesThreshold;
                            		int4 = GovernmentDB(i);
                            But this is only a problem that can be easily solved during compiling time.

                            Then some further cleaning and I can release this.

                            -Martin
                            Civ2 military advisor: "No complaints, Sir!"

                            Comment


                            • #15
                              I'm not having any luck with this Slic Database code. I put the following simple Slic script into the Activision World Map scenario and can't get it parsed. Am I missing something?

                              Code:
                              HandleEvent(BeginTurn) 'Test' post {
                              
                                  int_t i;
                                  int_t numunits;
                                  unit_t tmpUnit;
                              
                                  int_t unit2;
                                  int_t unit3;
                                  int_t unit4;
                                 
                                  if (g.year>0){
                                       numUnits=player[0].units;
                                       if (numUnits){
                                            for (i=0; i < numUnits; i=i+1){
                                                 GetUnitByIndex(player[0],i,tmpUnit);
                                                  if (tmpUnit.valid){
                                                         unit[0]=tmpUnit;
                                                         unit2=unitDB(UNIT_TANK);
                                                         unit3=unitDB(tmpUnit.type);
                                                         unit4=unitDB(unit[0].type);
                              
                                                    }
                                            }			    
                                     }
                                  }
                              }

                              Comment

                              Working...