map x colourtable x colormap

O Ilusionista

Captain 100K
What is the difference between those 3 options?

I know how to use all:
int  iMap = getentityproperty(ent, "map");
map = getentityproperty(ent, "colourmap");
map = getentityproperty(ent, "colourtable", 4);

But I know that setdrawmethod doesn't likes "map", but "colourmap".

Any idea? I am just curious.
 
I tend to forget which is which for map vs. colourmap, but I can explain colourtable.

Colourtable is a pointer to the colortable itself, rather than an item in a list of colortables. This allows you to apply a colourtable directly to entities, scripted sprites and graphics without need of a matching map list. It's a rarely used but VERY powerful feature of the script engine.

Take a look at this video, and pay attention to the enemy icon/life; it should be obvious they are scripted. The life blocks are just precolored sprites drawn in based on % of life remaining, no big deal. The icon colors are another story. By default any scripted graphic uses the background palette, which would of course be untenable for an enemy icon. Since it's just a drawn graphic there's no list of maps, so at first you'd think an entity spawned for each enemy icon would be needed. This would in turn mean a model for every enemy and npc in the game, with a map list matched to the main model. Duplication city. Nightmare!

That is where colourtable comes in. By de-referencing the actual color table pointer in use by an entity and applying it to a script drawn icon in the entity's folder, you can skip right past all that mess. Assuming the icon has an entry matched table (which of course it does), it then assumes the matching colors. No muss, no fuss.

http://youtu.be/JossdCHwwIw

Here's the script that makes it happen. It's out of date but still works, and extremely efficiently at that. The important part is the enemy icon draw. First, get the colourmap pointer, then apply it to the global drawmethod (any directly drawn graphic uses the global draw). Draw the sprite, then restore global draw.

The effect on screen is a perfectly color matched icon. All done without use of a single entity. No duplicated models and maps to maintain, no resource hogging, no worrying about having to spawn, move and kill things. Add/remove maps from the main entity all you want, it won't matter; whatever color the main entity is in game, the icon is too. Simple and clean, the way it should be.

Now knowing that a coluortable can be applied from anything to anything else, just imagine what else you could with it...

:)

Code:
#include	"data/scripts/vars/constants.h"

#import	"data/scripts/traileru.c"		//Shadow trails.
//#import	"data/scripts/com/ani0013.h"	//Jump animation if steping off an edge.

void main()
{
    void    vEnt;                                                                           //Entity placeholder.
    void    vMap;                                                                           //Color array placeholder.
    char    cName;                                                                          //Entity default name.
    int     iAni;                                                                           //Animations.
	int		iLiv    = -1;                                                                   //Living enemies.
	int		iKMap;                                                                          //KO map.
    int     iType;                                                                          //Entity type.
    int     iVRes   = openborvariant("vresolution");                                        //Current vertical resolution.
    int     iECnt   = openborvariant("ent_max");                                            //Current # of entities in play.
	int		iIndex;                                                                         //Player index.
    int     iEnt;                                                                           //Entity counter.
    int     iHSpr;                                                                          //Sprite index.
    float   fCnt    = 0.0;                                                                  //General counter.
    float   fJar;                                                                           //Mp Jar count.
    float   health;                                                                         //Current health
    float   fHPer;                                                                          //HP % of max.
    float   fFron   = 0.0;                                                                  //Front percentage (top 1/4 of HP)
    int     iDrop;                                                                          //Falling/Fallen AI flag.
	
	
	//Give Debug text a background.
	if (getglobalvar("debug_set"))
	{
		drawbox(0, 25, 480, 80, SYS_FRONTZ, RGB_BLACK, 6);
	}

	//tupdate();

	// Loop entity collection.
	for(iEnt=0; iEnt<iECnt; iEnt++)                                                         
	{
		
		//Get entity handle.
		vEnt = getentity(iEnt);                                      

		// Loop Valid handle, valid entity and alive?
		if(vEnt                                                                             
            && getentityproperty(vEnt, "exists")                                            
            && !getentityproperty(vEnt, "dead"))                                            
		{		

			// Player type?
		    if ((iType && iType == TYPE_PLAYER))											
		    {
				// Get player index.
				iIndex	= getentityproperty(vEnt, "playerindex");  

				// MP jar count.
				fJar	= getentityproperty(vEnt, "mp")/10;                                 

				// Get life % in quarters.
				fHPer   = 4 * (0.0 + (hlife(vEnt)));    

				// Get magic jar sprite.
				iHSpr   = getindexedvar(IDXG_ICOJAR);                                       

				// Loop jar count.
				for(fCnt=0; fCnt<fJar; fCnt++)                                              
				{
					// Draw magic jars
					drawsprite(iHSpr, iIndex*160+55+fCnt*11, iVRes-20, SYS_FRONTZ+18001);	
				}

				// Loop each quarter of life.
				for(fCnt=0.0; fCnt<fHPer; fCnt++)                                           
				{					
					fFron   = fHPer - fCnt;
                 
					// Get life block sprite.
					iHSpr   = getindexedvar(lblock(fFron));                                 

					// Draw life block.
					drawsprite(iHSpr, iIndex*160+53+fCnt*26, iVRes-31, SYS_FRONTZ+18001);   
				}
		    }
			else
			{
				// Getting ass kicked?
			    if(iDrop 
					|| getentityproperty(vEnt, "aiflag", "inpain") 
					|| iAni == AC_DEFPOSE) 
			    {
					// Get AI pain icon.
                    iHSpr	= getentityproperty(vEnt, "spritea", "sprite", AC_ICONS, ICON_AIPAIN);    
			    }
                else
                {
					// Get AI normal icon.
                    iHSpr	= getentityproperty(vEnt, "spritea", "sprite", AC_ICONS, ICON_AI);    
                }

				// Sprite valid?
                if(iHSpr)																	
                {
					// Get life block sprite.
                    fHPer   = hlife(vEnt);      

					// Get entitiy's colourmap pointer. 
                    vMap    = getentityproperty(vEnt, "colourmap");

					// Increment "living" index.
                    ++iLiv;                                                                 

					// Set global draw method to colourmap pointer.
                    setdrawmethod(NULL(), 1, 256, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, vMap);    

					// Draw icon.
                    drawsprite(iHSpr, (iLiv*41), 4, SYS_FRONTZ+18000);                        

					// Restore global draw defaults.
                    setdrawmethod(NULL(), 0, 256, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL());  

					// Get life block sprite.
                    iHSpr   = getindexedvar(lblock(fHPer));                                 

					// Draw life block.
                    drawsprite(iHSpr, 16+(iLiv*41), 8, SYS_FRONTZ+18000);						
                }
			}
        }	
	}
}

float hlife(void vEnt)
{
	float fHP	= 0.0 + getentityproperty(vEnt, "health");
	float fMHP	= 0.0 + getentityproperty(vEnt, "maxhealth");

	return fHP/fMHP;
}

int lblock(float fPer){

    int iHSpr;

    if (fPer >= 0.75)
    {
        iHSpr = IDXG_BLOCBLU;  //Blue
    }
    else if (fPer >= 0.50)
    {
        iHSpr = IDXG_BLOCYEL;  //Yellow
    }
    else if (fPer >= 0.25)
    {
        iHSpr = IDXG_BLOCORA;  //Orange
    }
    else
    {
        iHSpr = IDXG_BLOCRED;  //Red
    }

    return iHSpr;
}
 
hum, so basically I can get a colourtable from any entity and aply to any other, or sprite/graphics. That is pretty cool to know.
Thanks for the explanation.
 
O Ilusionista said:
hum, so basically I can get a colourtable from any entity and aply to any other, or sprite/graphics. That is pretty cool to know.
Thanks for the explanation.

Yep. You can apply it to anything. The panels, background layers, another entity, sprites, boxes, whatever. If it's on screen you can apply a colourtable to it. Huge possibilities there.

DC
 
Back
Top Bottom