Announcement

Collapse
No announcement yet.

Design: New SLIC functions

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

  • #46
    Originally posted by The Big Mc
    Martin I understand you point but slaves are used in a different way to specialist.

    A newbie on the slic front will look for an addslave function to add or remove a slave.
    Maybe from the player's point of view, but from the game mechanics point of view I don't see a difference. And your function can't remove any slave. By the way you also need a function that tells you how many specialists a city has engaged.

    Originally posted by The Big Mc
    However the next function I will do is a change specialist which I will be able to do very fast ones I nailed the problem in the add slave function or I made modify this one. But you can’t expect me to learn the ways of the source with a foot long section of code as easy as a 5 liner.

    As for my problem it starts when the city adds a pop by growing (but not it seams when the cheat mode ads one).
    Does the problem occur when you use your function or does it occur when the city grows? However your function still contains a problem you have to remove.

    I don't quote the line you have to find it on your own. But with the following description it shouldn't be a problem. Once you have retrieved the city and the count variables from the slic function argument list, you try again retrieve the city, but this time from the slic context. A very bad idea as you overwrite the city given from the parameter list, and espeacilly if your slic context does not contain any city. In this case the game crashes when you try to access the city's data.

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

    Comment


    • #47
      Code:
      SFN_ERROR Slic_Addslaves::Call(SlicArgList *args)
      {
      	
      	if(args->m_numArgs != 2)
      		return SFN_ERROR_NUM_ARGS;
      	Unit city;
      	BOOL res;
      
      	res = args->GetCity(0, city);
      	if(!res) {
      		return SFN_ERROR_TYPE_ARGS;
      	}
      	sint32 count;
      	if(!args->GetInt(1, count))
      		return SFN_ERROR_TYPE_ARGS;
      
      		city.CD()->ChangePopulation(count);
      		city.CD()->ChangeSpecialists(POP_SLAVE,count);
      
      	return SFN_ERROR_OK;
      }
      The cod works as I said martin the second a city grows by way of food growth ctp pulls a wobblier and crashes.


      If you will could you try this code in you version of the code and compile it yours may be more unto date then mine.
      "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
      The BIG MC making ctp2 a much unsafer place.
      Visit the big mc’s website

      Comment


      • #48
        Originally posted by the The Big Mc
        If you will could you try this code in you version of the code and compile it yours may be more unto date then mine.
        Well not today. At the week end would be better.

        Well actual the function looks good now, but I guess you have for the slaves to set the slave bit. Well and in this case I would model the function like the adds pop function. Actual the only change between an AddSlaves and an AddPops function is that it gets an additional player argument that is passed to the MakePop event call. You can find an instance of it with an slave added in the EnslaveSettlerEvent. Interestingly the slave's original nationality is stored, well actual it is only that the city has a slave from that nation. And I think we should leave the empty for loop in, as there should actual the kill pop event into it.

        And by the way if you need some information about what kind of s!*+ happened use the logs that are generated in the ..\ctp2_code\ctp\logs\ directory. The log files may catch the last Assert that is not catched by the windows popup window, nut that is the one you are looking for.

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

        Comment


        • #49
          add and remove slaves (got to rename the function now.)

          Code:
          SFN_ERROR Slic_Addslaves::Call(SlicArgList *args)
          {
          	
          	if(args->m_numArgs != 2)
          		return SFN_ERROR_NUM_ARGS;
          	Unit city;
          	BOOL res;
          
          	res = args->GetCity(0, city);
          	if(!res) {
          		return SFN_ERROR_TYPE_ARGS;
          	}
          	sint32 count;
          	if(!args->GetInt(1, count))
          		return SFN_ERROR_TYPE_ARGS;
          	
          	if(count < 0 ){
          		if(-city.CD()->SlaveCount() >= count){
          			count = 0-city.CD()->SlaveCount();
          		}
          		city.CD()->ChangeSpecialists(POP_SLAVE,count);
          		city.CD()->ChangePopulation(count);
          	}else if(count>0){
          		city.CD()->ChangePopulation(count);
          		city.CD()->ChangeSpecialists(POP_SLAVE,count);
          	}
          	return SFN_ERROR_OK;
          }
          "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
          The BIG MC making ctp2 a much unsafer place.
          Visit the big mc’s website

          Comment


          • #50
            Originally posted by The Big Mc
            add and remove slaves (got to rename the function now.)
            Actual my intention was to lead you to a more generic ChangeSpecialists slic function, but as I now think that there are also some differences between slaves and the other specialists. The best is to keep that you have in your post before your last post as a base for such a function and start on the base of the AddPops slic function.

            Actual there should only two modification:

            1st: An additional input argument - the slave's original nationality
            2nd: An additional argument to the MakePop event that is the slave's orginal nationality. An instance as I have told you in my last post can be found in the EnslaveSettlerEvent. Search for that in the entire source code! And then you shouldn't experiment any crashes anymore.

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

            Comment


            • #51
              I am going to add the addslavebit which requires the previous slave owner. As for this function if I can stop it crashing then to me it’s finished it adds and removes slaves which is what I set out to do. After this I will create a change specialist function.

              In the mean time I am still trying to find out how the enslavement order works.
              "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
              The BIG MC making ctp2 a much unsafer place.
              Visit the big mc’s website

              Comment


              • #52
                Originally posted by The Big Mc
                I am going to add the addslavebit which requires the previous slave owner. As for this function if I can stop it crashing then to me it�s finished it adds and removes slaves which is what I set out to do.
                Actual this is very simple we know that the AddPops function works, and we know that the MakePop event works without crash, whether it adds a simple pop or a slave. So the idea is that you take the AddPops function modify it so that it takes a third argument - a player, and pass this argument to the MakePop event. To figure out how to make the MakePop event add a slave you figuere out how they used it in the EnslaveSettlerEvent. All you have to do is to find it in the source code. I gave you the string to look for and you have the text in file search function of your OS.

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

                Comment


                • #53
                  Martin I did examine the part of the code and the only difference is that mine at this point toes not modify the slave bit but even with the function the game still crashes.
                  "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
                  The BIG MC making ctp2 a much unsafer place.
                  Visit the big mc’s website

                  Comment


                  • #54
                    Actual my idea was that the MakePop event itsself is the problem if it is missing. It does all the necessary stuff that is needed to add a pop without any problems, like crashes. So why bothering with all the stuff. And the other advance is that it also can be dected by the slic engine so that it can be dected by code that should act whenever a slave is added.

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

                    Comment


                    • #55
                      I know this is the wrong place to put this, and I know this wouldn't be useful, but would this add a "to the power of" operator?

                      In SlicFrame.cpp after SOP_MULT in DoInstruction:
                      Code:
                      		case SOP_EXP: 
                      			sp = m_stack->Pop(type1, sval1);
                      			Assert(sp >= 0);
                      			sp = m_stack->Pop(type2, sval2);
                      			Assert(sp >= 0);
                      			sval3.m_int = Eval(type2, sval2) ^ Eval(type1, sval1);
                      			m_stack->Push(SS_TYPE_INT, sval3);
                      
                      			break;
                      And in slic.y:
                      Code:
                      expression: expression '+' expression { slicif_add_op(SOP_ADD); }
                      	|   expression '-' expression { slicif_add_op(SOP_SUB); }
                      	|   expression '*' expression { slicif_add_op(SOP_MULT); }
                      [b]	|   expression '^' expression { slicif_add_op(SOP_EXP); }[/b]
                      With the bolded bit showing my addition.
                      Caution! Under no circumstances confuse the mesh with the interleave operator, except under confusing circumstances!
                      -Intercal reference manual

                      People often remark of me, "You say sorry far to much!". To which my common-sense reply is "I apologise".

                      Comment


                      • #56
                        Originally posted by tombom
                        I know this is the wrong place to put this, and I know this wouldn't be useful, but would this add a "to the power of" operator?
                        Not quite - there are (at least) two problems with this.

                        Fisrtly, the '^' operator in C++ does bitwise XOR, not exponentation - you'll have to call some library function in SlicFrame.cpp to get exponentation.

                        Secondly, in slic.y you'll also need to specify the associativity and precedence of the new operator otherwise you'll get a slew of shift-reduce conflicts when yacc processes the parser. You might well have to change the lexer too. I don't have access to the source right now so I can't give any more details.

                        Comment


                        • #57
                          Thanks for that. Do you think this will work?

                          For the first one:
                          Code:
                          		case SOP_EXP: 
                          			sp = m_stack->Pop(type1, sval1);
                          			Assert(sp >= 0);
                          			sp = m_stack->Pop(type2, sval2);
                          			Assert(sp >= 0);
                          			sval3.m_int = pow(Eval(type2, sval2), Eval(type1, sval1));
                          			m_stack->Push(SS_TYPE_INT, sval3);
                          
                          			break;
                          With #include math.h at the top as well.

                          And then:
                          Code:
                          %left '*' '/' '%'
                          [b]%left '**'[/b]
                          at the top of slic.y.

                          Code:
                          expression: expression '+' expression { slicif_add_op(SOP_ADD); }
                          	|   expression '-' expression { slicif_add_op(SOP_SUB); }
                          	|   expression '*' expression { slicif_add_op(SOP_MULT); }
                          	|   expression '**' expression { slicif_add_op(SOP_EXP); }
                          Where the second bit was.

                          I checked the lexer, as far as i can see you don't need anything.
                          Last edited by tombom; January 23, 2005, 10:16.
                          Caution! Under no circumstances confuse the mesh with the interleave operator, except under confusing circumstances!
                          -Intercal reference manual

                          People often remark of me, "You say sorry far to much!". To which my common-sense reply is "I apologise".

                          Comment


                          • #58
                            Well, I'm no expert on the libraries (and I still can't look right now), but I think that pow function might be for doubles, rather than ints. This isn't a huge probelm, but it would be better to use one for ints if possible.

                            You'll also need to add SOP_EXP to the enumeration of SLIC operators somewhere.

                            Otherwise, I see no obvious problems. I'm not sure if yacc can cope with multi-character tokens like '**', but it may well. Of course, you can keep the SLIC operator called '^' if you want - just because it means something else in C++ is no reason not to use it for exponentation in SLIC (I doubt we'll ever want bitwise XOR in SLIC, but then again, you never know...).

                            Comment


                            • #59
                              Thanks for your help.

                              One problem I'm running into now is that I have no idea how to set the ACTIVISION_ORIGINAL thing in the .y files. Martin's changes have this around them with no problems, but I can't get it to work.

                              Attached is the untested code without ACTIVISON_ORIGINAL. ^ is the operator.
                              Last edited by tombom; January 23, 2005, 14:07.
                              Caution! Under no circumstances confuse the mesh with the interleave operator, except under confusing circumstances!
                              -Intercal reference manual

                              People often remark of me, "You say sorry far to much!". To which my common-sense reply is "I apologise".

                              Comment


                              • #60
                                Here is the file since you can't attach something when editing. Sorry for this DP.
                                Attached Files
                                Caution! Under no circumstances confuse the mesh with the interleave operator, except under confusing circumstances!
                                -Intercal reference manual

                                People often remark of me, "You say sorry far to much!". To which my common-sense reply is "I apologise".

                                Comment

                                Working...