Announcement

Collapse
No announcement yet.

DEBUG: Bugs in buildingutil.cpp ?

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

  • DEBUG: Bugs in buildingutil.cpp ?

    I was idly looking through the code and came upon the following lines in buildingutil.cpp. These three functions appear to be intended to return the maximum offense bonus for buildings present in a city. However, the body of the code seems to look for the wrong building characteristics for both water and ar improvements. AFAICS this implies that improvements such as costal forts or flak guns do not function as expected. The correction appears obvious. Thoughts?


    Code:
    double buildingutil_GetOffenseBonusLand(const uint64 built_improvements)
    {
    	double best = 0;
    	FOREACH_BUILT(GetOffenseBonusLand) {
    		double cur;
    		if(rec->GetOffenseBonusLand(cur) && cur > best)
    			best = cur;
    	}
    	return best;
    }
    
    double buildingutil_GetOffenseBonusWater(const uint64 built_improvements)
    {
    	double best = 0;
    	FOREACH_BUILT(GetOffenseBonusWater) {
    		double cur;
    		if(rec->GetOffenseBonusLand(cur) && cur > best)
    			best = cur;
    	}
    	return best;
    }
    
    double buildingutil_GetOffenseBonusAir(const uint64 built_improvements)
    {
    	double best = 0;
    	FOREACH_BUILT(GetOffenseBonusWater) {
    		double cur;
    		if(rec->GetOffenseBonusLand(cur) && cur > best)
    			best = cur;
    	}
    	return best;
    })

  • #2
    Yes it looks like some copy and paste work, so all you have to do is to find the right functions make shure all of them are implemented properly and plug them in.

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

    Comment


    • #3
      I replaced the code with the proper look up values. The code to actually return the values entered in buildings.txt looks correct. I havent tried to compile CTP2, yet. Here is the changed code:

      Code:
       
      
      double buildingutil_GetOffenseBonusWater(const uint64 built_improvements)
      {
      	// Iterate through all the buildings in the city
      	// and return the value of the MAXMIMUM bonus only,
      	// This bonus is not additive
      	double best = 0;
      	FOREACH_BUILT(GetOffenseBonusWater) {
      		double cur;
      		if(rec->GetOffenseBonusWater(cur) && cur > best)
      			best = cur;
      	// original code below checked for the wrong bonus
      	//	if(rec->GetOffenseBonusLand(cur) && cur > best)
      	//		best = cur;
      	}
      	return best;
      }
      
      double buildingutil_GetOffenseBonusAir(const uint64 built_improvements)
      {
      	// Iterate through all the buildings in the city
      	// and return the value of the MAXMIMUM bonus only,
      	// This bonus is not additive
      	double best = 0;
      	FOREACH_BUILT(GetOffenseBonusAir) {
      		double cur;
      		if(rec->GetOffenseBonusAir(cur) && cur > best)
      			best = cur;
      	}
      	return best;
      
      	// original code below checked for the wrong bonus
      	//	FOREACH_BUILT(GetOffenseBonusWater) {
      	//		double cur;
      	//		if(rec->GetOffenseBonusLand(cur) && cur > best)
      	//			best = cur;
      	//	}
      	//	return best;
      }

      Comment


      • #4
        nice one
        "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


        • #5
          Originally posted by The Big Mc
          nice one
          Yup nice one I just would reduce the commented lines like this:

          Code:
          double buildingutil_GetOffenseBonusAir(const uint64 built_improvements)
          {
          	// Iterate through all the buildings in the city
          	// and return the value of the MAXMIMUM bonus only,
          	// This bonus is not additive
          	double best = 0;
          	FOREACH_BUILT(GetOffenseBonusWater) {
          		double cur;
          		if(rec->GetOffenseBonusAir(cur) && cur > best)
          	//	Original Code:
          	//	if(rec->GetOffenseBonusLand(cur) && cur > best)
          			best = cur;
          	}
          	return best;
          }
          And finally you should add your name to the fix so that we know in the case of doubt who to bla.. äh I mean who to give the credits for the fix.

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

          Comment


          • #6
            Now youre finding AND fixing bugs i never knew existed, this is all going strangely quickly
            Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
            CtP2 AE Wiki & Modding Reference
            One way to compile the CtP2 Source Code.

            Comment

            Working...
            X