bit better gfx/vdu Manifest

Talk among developers, and propose and discuss general development planning/tackling/etc... feature in this forum.
Post Reply
kraehe
Merchant
Merchant
Posts: 34
Joined: Thu Dec 04, 2008 4:26 am

bit better gfx/vdu Manifest

Post by kraehe »

Moin Guru's,

I like my own a bit better gfx/vdu Manifest. Its best used if you add

Code: Select all

<var name="PercentageSpeedChangeToFaultSearch" value="300"/>
to your vegastrike.config. The patch will add prices to the left side manifest m and sum up cargo volume, tonnage and price, the right side manifest v will only show one cargo per group for most locations and also announces the price per unit, to benefit trade.

Code: Select all

*** src/gfx/vdu.cpp~	Wed Dec 17 07:23:31 2008
--- src/gfx/vdu.cpp	Mon Dec 15 11:28:12 2008
*************** void VDU::DrawManifest (Unit * parent, U
*** 1059,1069 ****
    }else {
      retval+=string ("--------\nCredits: ")+tostring((int)_Universe->AccessCockpit()->credits)+/*string(".")+tostring (((int)(_Universe->AccessCockpit()->credits*100))%100) +*/string("\n");
    }
    unsigned int numCargo =target->numCargo();
!   for (unsigned int i=0;i<numCargo;i++) {
!     if ((target->GetCargo(i).GetCategory().find("upgrades/")!=0)&&(target->GetCargo(i).quantity>0))
!       retval+=target->GetManifest (i,parent,parent->GetVelocity())+string (" (")+tostring (target->GetCargo(i).quantity)+string (")\n");
!   }
    static float background_alpha=XMLSupport::parse_float(vs_config->getVariable("graphics","hud","text_background_alpha","0.0625"));
    GFXColor tpbg=tp->bgcol;
    bool automatte=(0==tpbg.a);
--- 1059,1104 ----
    }else {
      retval+=string ("--------\nCredits: ")+tostring((int)_Universe->AccessCockpit()->credits)+/*string(".")+tostring (((int)(_Universe->AccessCockpit()->credits*100))%100) +*/string("\n");
    }
+   unsigned int load = 0;
+   unsigned int cred = 0;
+   unsigned int vol  = 0;
    unsigned int numCargo =target->numCargo();
!   unsigned int maxCargo = 16;
!   string lastCat;
!   for (unsigned int i=0;i<numCargo;i++)
!     if ((target->GetCargo(i).GetCategory().find("upgrades/")!=0)
! 	&& (target->GetCargo(i).quantity>0)) {
!       Cargo  ca = target->GetCargo(i);
!       int    cq = ca.quantity;
!       float  cm = ca.mass;
!       float  cv = ca.volume;
!       float  cp = ca.price;
!       string cc = ca.GetCategory();
!       load += cq*(int)cm;
!       cred += cq*(int)cp;
!       vol  += cq*(int)cv;
!       if (((target == parent)
!         || (maxCargo + i >= numCargo)
! 	||  lastCat.compare(cc)
! 	  ) && (maxCargo > 0)) {
! 	maxCargo--;
! 	lastCat = cc;
! 	// retval+=tostring(maxCargo)+string(" ");
! 	// retval+=cc+string(" ");
!         if (target==parent)
!           if (cm > cv)
! 	    retval+=tostring(cq*(int)cm)+string("t ");
!           else
! 	    retval+=tostring(cq*(int)cv)+string("sqm ");
! 	retval+=target->GetManifest (i,parent,parent->GetVelocity())
! 	      + string(" $")+tostring(((target==parent)?cq:1)*(int)cp)
!               + string("\n");
!       }
!     }
!   if (target==parent)
!       retval+=tostring(load)+string("t load ")+
! 	  tostring(vol)+string("sqm $")+
! 	  tostring(cred)+string("\n");
    static float background_alpha=XMLSupport::parse_float(vs_config->getVariable("graphics","hud","text_background_alpha","0.0625"));
    GFXColor tpbg=tp->bgcol;
    bool automatte=(0==tpbg.a);
please test this patch.

ciao,Kraehe
Last edited by kraehe on Thu Dec 18, 2008 1:27 pm, edited 1 time in total.
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Re: bit better gfx/vdu Manifest

Post by loki1950 »

Thx kraehe i really like guys who provide the code for there request :wink: That should help the trader types a lot.As i have mentioned a few times most of the code team seem to be tied up in real life ATM so with the holiday season hopefully they have time to drop by though pyramid may take an interest as he has commit access to svn :D

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Re: bit better gfx/vdu Manifest

Post by pyramid »

kraehe wrote:

Code: Select all

<var name="PercentageSpeedChangeToFaultSearch" value="300"/>
What does this config variable exactly do?

The patch was applied, though I have changed the string formatting a bit: m^2 for square meters, and Cr. for credits.
Strange thing, when listing the target manifest for some stations and ships, there is only garbage strings displayed (though with prices) and continuously scrolling. I think this has been reported already before long time ago. This doesn't happen with Atlantis and surely it's nothing with your patch, but I thought I'd mention it here. Looks like there is some pointer screwed *before* it gets to the VDU.

Thanks for this excellent contribution!

Btw, I have also applied the easiest doxygen style formatting to the beginning of both your patched files (vdu.cpp and unit_collide.cpp) using three slashes "///" with at least 2 lines and commenting only the generic role of the file. A good practice would be to comment each file when applying changes, so that at some point in the future we will be able to run doxygen and get an overview of what the code files are responsible for.
kraehe
Merchant
Merchant
Posts: 34
Joined: Thu Dec 04, 2008 4:26 am

Re: bit better gfx/vdu Manifest

Post by kraehe »

Moin Pyramid,
pyramid wrote:
kraehe wrote:

Code: Select all

<var name="PercentageSpeedChangeToFaultSearch" value="300"/>
What does this config variable exactly do?

Strange thing, when listing the target manifest for some stations and ships, there is only garbage strings displayed (though with prices) and continuously scrolling. I think this has been reported already before long time ago. This doesn't happen with Atlantis and surely it's nothing with your patch, but I thought I'd mention it here. Looks like there is some pointer screwed *before* it gets to the VDU.
I first thought this scrambling is a bug ... no no: its a feature, implemented by someone else. Hit Home & Backspace, and the scramble will end. Or set PercentageSpeedChangeToFaultSearch to a reasonable value. imho, 300 is a good choice, as it would only scramble on a newbie Llama, if you fly at full speed. I also use this value, even if I fly a Franklin. Searching for promising trade targets is done at trade speed, in my game style. And sorry, you can not view the manifest of a ship in SPEC.
The patch was applied, though I have changed the string formatting a bit: m^2 for square meters, and Cr. for credits.
Thanks for this excellent contribution!
*oups* could you please remove those two debugging lines ;)
// retval+=tostring(maxCargo)+string(" ");
// retval+=cc+string(" ");
Btw, I have also applied the easiest doxygen style formatting to the beginning of both your patched files (vdu.cpp and unit_collide.cpp) using three slashes "///" with at least 2 lines and commenting only the generic role of the file. A good practice would be to comment each file when applying changes, so that at some point in the future we will be able to run doxygen and get an overview of what the code files are responsible for.
VS lacks documentation, and I fear it would be a hard job to do it now. But a small start is better than nothing. It would be good practice, if changes also include a tag for the author who wrote it initially and those who patched on it, so one can ask if questions about the code arise.

An other point where I want to improve the VDU was, to tell the radius and distance to docking port for planets. But here my first hack failed, because radius is a protected class variable. But I'll try a 2nd hack this weekend, I think.

ciao,Kraehe
pyramid
Expert Mercenary
Expert Mercenary
Posts: 988
Joined: Thu Jun 15, 2006 1:02 am
Location: Somewhere in the vastness of space
Contact:

Re: bit better gfx/vdu Manifest

Post by pyramid »

Moin, Kraehe (or should it be Krähe? 8) )

Re: Config. OK, maybe I misread and didn't get this was to fix the text garbling. I will add that line to standard vs.config. NOt sure who created such a feature, but it seems to make little sense.

Since you'll be still working on vdu, I'll take the debug lines once you come up with another patch.

Please feel free to add author info to those code lines you are changing.
kraehe
Merchant
Merchant
Posts: 34
Joined: Thu Dec 04, 2008 4:26 am

Re: bit better gfx/vdu Manifest

Post by kraehe »

Moin Pyramid,
pyramid wrote: Since you'll be still working on vdu, I'll take the debug lines once you come up with another patch.
*ok* here is the next patch targeting on gfx/vdu.cpp and gfx/cockpit.cpp.

Code: Select all

Index: src/gfx/cockpit.cpp
===================================================================
--- src/gfx/cockpit.cpp	(revision 12506)
+++ src/gfx/cockpit.cpp	(working copy)
@@ -1498,15 +1498,12 @@
 		  return (float)UnitImages::TOOFAR;
 	  }
   case UnitImages::CANDOCK_MODAL:
-	  if(!target){ //FIXME
-		  return (float)UnitImages::READY;
-	  } else if(!target){ //FIXME
-		  return (float)UnitImages::TOOFAR;
-	  } else if(target->graphicOptions.InWarp){
-		  return (float)UnitImages::OFF;
-	  } else {
-		  return (float)UnitImages::NOMINAL;
-	  }
+	  Unit *todock = target->Target();
+	  if (todock && (todock->CanDockWithMe(target,1) != -1))
+	      return (todock->CanDockWithMe(target,0) != -1) ?
+		    (float)UnitImages::READY
+		  : (float)UnitImages::TOOFAR;
+	  return (float)UnitImages::NOMINAL;
   }
   return 1;
 }
Index: src/gfx/vdu.cpp
===================================================================
--- src/gfx/vdu.cpp	(revision 12506)
+++ src/gfx/vdu.cpp	(working copy)
@@ -783,7 +783,7 @@
   int i=0;
   char st[1024];
   memset(st,'\n',1023);
-  int tmplim=rows-1;
+  int tmplim=rows-3;
   if (draw_auto_message==true)
     tmplim--;
   st[tmplim]='\0';
@@ -791,9 +791,17 @@
   if (draw_auto_message){
     newst+=cp->autoMessage+"\n";
   }
-  retString128 qr=PrettyDistanceString(DistanceTwoTargets(parent,target));
-  newst+="Range: ";
-  newst+=qr.str;
+  double dist = DistanceTwoTargets(parent,target);
+  newst+=string("Range: ") + string(PrettyDistanceString(dist).str);
+  if ((target->isUnit()==PLANETPTR) && (target->CanDockWithMe(parent,1) != -1)) {
+      dist -= target->rSize() * UniverseUtil::getPlanetRadiusPercent();
+      if (dist < 0)
+	  newst+=string("\nDocking: Ready");
+      else
+      if (dist < target->rSize())
+	  newst+=string("\nDocking: ")+
+	      string(PrettyDistanceString(dist).str);
+  }
   static float background_alpha=XMLSupport::parse_float(vs_config->getVariable("graphics","hud","text_background_alpha","0.0625"));
   GFXColor tpbg=tp->bgcol;
   bool automatte=(0==tpbg.a);
@@ -1061,7 +1069,7 @@
   if (target!=parent) {
     retval+=string ("Tgt: ")+reformatName(target->name)+string("\n");
   }else {
-    retval+=string ("--------\nCredits: ")+tostring((int)_Universe->AccessCockpit()->credits)+/*string(".")+tostring (((int)(_Universe->AccessCockpit()->credits*100))%100) +*/string("\n");
+    retval+=string ("--------\nCredits: ")+tostring((int)_Universe->AccessCockpit()->credits)+string("\n");
   }
   unsigned int load = 0;
   unsigned int cred = 0;
@@ -1078,20 +1086,18 @@
       float  cv = ca.volume;
       float  cp = ca.price;
       string cc = ca.GetCategory();
-      load += cq*(int)cm;
       cred += cq*(int)cp;
-      vol  += cq*(int)cv;
+      vol  += (int)((float)cq*cv);
+      load += (int)((float)cq*cm);
       if (((target == parent) || (maxCargo + i >= numCargo) ||  lastCat.compare(cc)) && (maxCargo > 0)) {
         maxCargo--;
         lastCat = cc;
-        // retval+=tostring(maxCargo)+string(" ");
-        // retval+=cc+string(" ");
         if (target==parent)
-          if (cm > cv)
-            retval += tostring(cq*(int)cm)+string("t ");
+          if (cm >= cv)
+            retval += tostring((int)((float)cq*cm))+string("t ");
           else
-            retval += tostring(cq*(int)cv)+string("m^2 ");
-            retval += target->GetManifest (i,parent,parent->GetVelocity())
+            retval += tostring((int)((float)cq*cv))+string("m^2 ");
+        retval += target->GetManifest (i,parent,parent->GetVelocity())
             + string(" ") + tostring(((target==parent)?cq:1)*(int)cp)
             + string("Cr.\n");
       }

this is the cleaned up version against current svn. It will remove some debugging comments and does the rounding for cargos with less than a ton and less than a cubic meter right. So at first its a fix for my last patch.

At seconds it fixes a well known // FIXME and to enable DOCK: READY|TO FAR|- in cockpit.cpp, while the patch at gfx/vdu tells distance to dock for planets.

You will never hammer 'd' again and again, if you apply this together with the above patch to show distance to dock.

ciao,Kraehe

PS: I really would like to run the complete VS source code through indent -kr - when adding line numbers one could think VS is basic code ;)
Last edited by kraehe on Fri Dec 19, 2008 4:26 am, edited 1 time in total.
Post Reply