[Logo]
 
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Universal Cost function  XML
Forum Index -> Druids RPG Go to Page: Previous  1, 2
Author Message
Szlat

Wicked Sick!

Joined: 05/18/2005 18:32:41
Messages: 2124
Location: UK
Offline

So I was thinking of something along these lines:

Code:
 class CostRPGAbility extends RPGAbility
 	abstract;
 
 var int MinWeaponSpeed;
 var int MinHealthBonus;
 var int MinAdrenalineMax;
 var int MinDB;
 var int MinDR;
 var int MinAmmo;
 
 var int WeaponSpeedStep;
 var int HealthBonusStep;
 var int AdrenalineMaxStep;
 var int DBStep;
 var int DRStep;
 var int AmmoStep;
 
 var int MinPlayerLevel;
 var int PlayerLevelStep;
 // or
 var Array< int > PlayerLevelReqd;
 
 // if LevelCost set, takes precedence over (default.StartingCost + default.CostAddPerLevel * CurrentLevel)
 var Array< int > LevelCost;		
 
 var Array<class<RPGAbility> > ExcludingAbilities;	// if you have one of these you cannot purchase
 var Array<class<RPGAbility> > RequiredAbilities;	// you must have all of these
 
 static simulated function int GetCost(RPGPlayerDataObject Data, int CurrentLevel)
 {
 	local int x;
 	local int ab;
 	local bool gotab;
 	
 	if (Data == None)
 		return 0;
 	
 	// check the stats
 	if (Data.WeaponSpeed < default.MinWeaponSpeed + (CurrentLevel * default.WeaponSpeedStep))
 		return 0;
 	if (Data.HealthBonus < default.MinHealthBonus + (CurrentLevel * default.HealthBonusStep))
 		return 0;
 	if (Data.AdrenalineMax < default.MinAdrenalineMax + (CurrentLevel * default.AdrenalineMaxStep))
 		return 0;
 	if (Data.Attack < default.MinDB + (CurrentLevel * default.DBStep))
 		return 0;
 	if (Data.Defense < default.MinDR + (CurrentLevel * default.DRStep))
 		return 0;
 	if (Data.AmmoMax < default.MinAmmo + (CurrentLevel * default.AmmoStep))
 		return 0;
 
 	// now check the player level
 	if(Data.Level < (default.MinPlayerLevel + CurrentLevel*default.PlayerLevelStep))
 		return 0;
 
 	if (default.PlayerLevelReqd.length > CurrentLevel)
 		if (default.PlayerLevelReqd[CurrentLevel+1] > Data.Level)
 			return 0;
 
 	// check for excluding abilities
 	for (ab = 0; ab < default.ExcludingAbilities.length; ab++)
 		for (x = 0; x < Data.Abilities.length; x++)
 			if (Data.Abilities[x] == default.ExcludingAbilities[ab])
 				return 0;
 	// now check for required abilities
 	for (ab = 0; ab < default.RequiredAbilities.length; ab++)
 	{
 		gotab = false;
 		for (x = 0; x < Data.Abilities.length; x++)
 			if (Data.Abilities[x] == default.RequiredAbilities[ab])
 				gotab = true;
 		if (!gotab)
 			return 0;
 	}
 
 	if (CurrentLevel < default.MaxLevel)
 	{
 		if (default.LevelCost.length <= CurrentLevel)
 			return default.StartingCost + default.CostAddPerLevel * CurrentLevel;
 		else
 			return default.LevelCost[CurrentLevel+1];
 	}
 	else
 		return 0;
 }
 
 static simulated function int Cost(RPGPlayerDataObject Data, int CurrentLevel)
 {
 	// this is called serverside from ServerAddAbility. 
 	// Need to do standard processing, and add a subclass check just in case
 	// pass in dummy subclass. It will then go and find it.
 	return static.SubClassCost(Data, CurrentLevel, "");		
 }
 
 static simulated function int SubClassCost(RPGPlayerDataObject Data, int CurrentLevel, string curSubClass)
 {
 	// this is a clientside request from the StatsMenu
 	// and we should have already checked the ability is valid if subClass is set.
 	// if subClass is not set, then it will be a server side call from ServerAddAbility
 	local int curSubClasslevel;
 	local class<RPGClass> curClass;
 	local int CostValue;
 	local int x;
 	local int y;
 
 	// first check the basics
 	CostValue = static.GetCost(Data, CurrentLevel);
 	if (CostValue <= 0)
 		return 0;
 	
 	// ok, passed that. Now let's check class and subclass
 	// now really want to do a if ( Level.NetMode == NM_Client)
 	// but have no actors to work with.
 	// instead bodge on the fact the ownerid isnt set in Data on clients
 	if ( Data.OwnerID == "")
 	{
 		// we are clientside, so can't really do any more testing
 		if (curSubClass == "")
 		{
 			// shouldn't really happen. SubClass should have been set. 
 			// Must be the stats menu misbehaving somehow, and the old call must have been used
 			return 0;		// return 0 to stop people buying what they shouldnt
 		}
 		return CostValue;		
 	}
 
 	if (curSubClass == "")
 	{
 		// first find class and subclass
 		curClass = None;
 		// first lets find the class
 		for (y = 0; y < Data.Abilities.length; y++)
 			if (ClassIsChildOf(Data.Abilities[y], class'RPGClass'))
 			{
 				// found the class
 				curClass = class<RPGClass>(Data.Abilities[y]);
 			}
 			else
 			if (ClassIsChildOf(Data.Abilities[y], class'SubClass'))
 			{
 				//found the subclass
 				curSubClassLevel = Data.AbilityLevels[y];
 				if (curSubClassLevel < class'SubClass'.default.SubClasses.length)
 					curSubClass = class'SubClass'.default.SubClasses[curSubClassLevel];
 			}
 		
 		// ok now check the subclass text
 		if (curClass == None)
 			curSubClass = "None";		// for no class
 		else
 		{
 			if (curSubClass == "")
 			{
 				// if got a class but no sub class, the abilities are configured under the class ability name
 				curSubClass = curClass.default.AbilityName;								
 			}
 		}
 	}
 
 	// now check ability is available
 	for (x = 0; x < class'SubClass'.default.AbilityConfigs.length; x++)
 	{
 		if (curSubClass == class'SubClass'.default.AbilityConfigs[x].AvailableSubClass && default.Class == class'SubClass'.default.AbilityConfigs[x].AvailableAbility)
 		{
 			if (CurrentLevel < class'SubClass'.default.AbilityConfigs[x].MaxLevel)
 				return CostValue;
 			else
 				return 0;
 		}
 	}
 
 	return CostValue;
 }
 
 DefaultProperties
 {
 	AbilityName="Costed RPG Ability"
 	Description=""
 	
 	MinWeaponSpeed=0
 	MinHealthBonus=0
 	MinAdrenalineMax=100
 	MinDB=0
 	MinDR=0
 	MinAmmo=0
 	MinPlayerLevel=0
 
 	WeaponSpeedStep=0
 	HealthBonusStep=0
 	AdrenalineMaxStep=0
 	DBStep=0
 	DRStep=0
 	AmmoStep=0
 	PlayerLevelStep=0
 }
 

The GetCost function essentially does the work of the old Cost funtion, and can be hacked to check what we want cost wise. The rest is SubClass checking code.
greg11

Wicked Sick!

Joined: 02/10/2008 20:00:40
Messages: 526
Location: Hood River, OR
Offline

Looks good.
For this to work, all of the abilities need to be subclassed off of this with their cost functions removed, and defaultvalues set, correct?

What should I work on?

Is the cost function for the old menu, or will it be used in the new one also?

I think we need to find new terms. One day we may need to subclass the subclass class.
Szlat

Wicked Sick!

Joined: 05/18/2005 18:32:41
Messages: 2124
Location: UK
Offline

greg11 wrote:
For this to work, all of the abilities need to be subclassed off of this with their cost functions removed, and defaultvalues set, correct? 
Agreed - although to date I haven't done new subclasses off the UT2004RPG abilities we are using. Doing it was relatively easy, though tedious. Testing it is more troublesome.

greg11 wrote:
What should I work on? 
See if there are any bugs. Any extra requirement checks you think ought to be in the configuration. I put in the ones you said earlier, but can't remember if I missed any. Plus, you could think about the description we present to the stats purchasing menu. We could have the ability desciption just as the ability text, and build up all the requirements onto it - so create a static function to assemble the description. Or perhaps we have the description as the ability text, and have a separate string for the requirements - I can easily add an extra display field to the AbilityDescription window.

greg11 wrote:
Is the cost function for the old menu, or will it be used in the new one also? 
The cost function is used in the old UT2004RPG code. I have changed the new SubClass stats menu to call the SubClassCost function, to save the effort of working out the subclass.

greg11 wrote:
I think we need to find new terms. One day we may need to subclass the subclass class. 
lol
Szlat

Wicked Sick!

Joined: 05/18/2005 18:32:41
Messages: 2124
Location: UK
Offline

One area not catered for is in AbilityMedicAwareness, where you need at least level 2 of LoadedHealing to be able to purchase.
greg11

Wicked Sick!

Joined: 02/10/2008 20:00:40
Messages: 526
Location: Hood River, OR
Offline

Szlat wrote:
One area not catered for is in AbilityMedicAwareness, where you need at least level 2 of LoadedHealing to be able to purchase. 


Does medic awareness really need this requirement?

What about an AbilityDependsOn array with corresponding AbilityDependsOnLvl.

I am still trying to see the big picture.
Once complete, will the cost function be replaced by SubClassCost? Meaning that the cost function should not be called, and UT2004RPG will not be handling any of the abilities anymore.
Thè-Hättêr

Wicked Sick!
[Avatar]

Joined: 06/09/2008 23:49:41
Messages: 615
Location: Mexico
Offline

i was reading this post, and along with the one of spidermines i just dont understand a single "bit" of what you guys post...

"Only a few find the way, some don't recognise it when they do, some don't ever want to."

Cheshire, The Cat


Alice and the Hatter: Quotes: Alice in Wonderland
Alice: What a funny watch! It tells the day of the month, and it doesn't tell what o'clock it is!
The Hatter: Why should it? Does your watch tell you what year it is?
Alice: Of course not, but that's because it stays the same year for such a long time together.
The Hatter: …which is just the case with mine.


HERE IS MY NEW SKIN ... please take time to download it
MY SKIN--

thanks road

working on a new skill please support and advice would be great
[MSN]
greg11

Wicked Sick!

Joined: 02/10/2008 20:00:40
Messages: 526
Location: Hood River, OR
Offline

The maxspidermines is a ability I am working on to give weapon masters the option to increase the number of mines they can lay out.

This discussion is about changes to the code that handles determining what abilities are available. It shouldn't change gameplay. It will put all of the code in one central program class instead of each ability having their own code.
Thè-Hättêr

Wicked Sick!
[Avatar]

Joined: 06/09/2008 23:49:41
Messages: 615
Location: Mexico
Offline

so you plan to compilate all the codes into one big code?

"Only a few find the way, some don't recognise it when they do, some don't ever want to."

Cheshire, The Cat


Alice and the Hatter: Quotes: Alice in Wonderland
Alice: What a funny watch! It tells the day of the month, and it doesn't tell what o'clock it is!
The Hatter: Why should it? Does your watch tell you what year it is?
Alice: Of course not, but that's because it stays the same year for such a long time together.
The Hatter: …which is just the case with mine.


HERE IS MY NEW SKIN ... please take time to download it
MY SKIN--

thanks road

working on a new skill please support and advice would be great
[MSN]
Szlat

Wicked Sick!

Joined: 05/18/2005 18:32:41
Messages: 2124
Location: UK
Offline

greg11 wrote:
Does medic awareness really need this requirement?  
There isn't much point seeing how much your teammates need healing, if you cant heal them. So why would anyone want to buy MedicAwareness without LoadedHealing? Why the level 2 restraint I don't know. It may even at one time have been a level 3 LoadedHealing restraint, which I might have lowered at some point.

greg11 wrote:
What about an AbilityDependsOn array with corresponding AbilityDependsOnLvl. 
Could do. There is already a RequiredAbilities array, so could just add a RequiredLevels array to go with it?

greg11 wrote:
I am still trying to see the big picture.
Once complete, will the cost function be replaced by SubClassCost? Meaning that the cost function should not be called, and UT2004RPG will not be handling any of the abilities anymore. 
There are some UT2004RPG abilities still in there, which are a bit more difficult to change since it involves updating everyones stats who have the ability.
I am planning the Clientside to call SubClassCost, but the UT2004RPG ServerBuyAbility function will still call Cost (which calls SubClassCost). I suppose I could replace ServerBuyAbility as well, but if we can get by with it there, it would be best.
greg11

Wicked Sick!

Joined: 02/10/2008 20:00:40
Messages: 526
Location: Hood River, OR
Offline

Szlat wrote:

I am planning the Clientside to call SubClassCost, but the UT2004RPG ServerBuyAbility function will still call Cost (which calls SubClassCost). I suppose I could replace ServerBuyAbility as well, but if we can get by with it there, it would be best. 


Ok I follow now.
greg11

Wicked Sick!

Joined: 02/10/2008 20:00:40
Messages: 526
Location: Hood River, OR
Offline

Thè-Hättêr wrote:
so you plan to compilate all the codes into one big code? 

It is more like standardizing a function common to all abilities.
Each ability, such as medicawareness, is a subclass of the rpgability class.
here "class" and "subclass" are programming terms, and not related to the player classes in the game.
The rpgability class is like a parent and the abilities are like children...each one inherits traits from rpgability, but use their own cost function. What Szlat is doing is adding a new parent that will pass a cost function that all abilities would use.
The cost function is how the ability menu knows if a player can buy the ability.
The class and subclasses are part of object oriented programming and inheritance: http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29
Szlat

Wicked Sick!

Joined: 05/18/2005 18:32:41
Messages: 2124
Location: UK
Offline

Nice explanation greg11.

So on a temporary basis, I have integrated the above CostRPGAbility into DruidsRPG. As we come up with improved versions we can update it, but it provides a starting point.
I have updated all abilities in the DruidsRPG to be based on the CostRPGAbility - either directly or through intermediate classes like RPGDeathAbility, EngineerAbility or MonsterAbiliity which are now based on CostRPGAbility rather than RPGAbility.
For some abilities which were extended from UT2004RPG abilities, I had to copy code from the UT2004RPG ability, since the new Druid ability has to be based on CostRPGAbility instead. e.g DruidRegen and DruidAdrenalineSurge.
So each of these abilities now has the cost restrictions configured in, rather than having a bespoke cost function. The only abilities now that have a Cost function are:
  • RPGClass - to check you haven't got any other Class purchased
  • SubClass - due to the funny way it works in that you choose a level rather than stepping through them.
  • AbilityMedicAwareness - as discussed above it depends on level 2 of a different ability

    DC also uses 8 UT2004RPG abilities - including Iron Legs, Fast Weapon Switch, Smart Healing etc. These have not changed at all, and so still use the old UT2004RPG cost function. At some point, we can subclass those into Druid abilities, but since that involves more work for Druid changing over peoples purchased abilities, I think leave it for the moment.

    So, should be in the next build.
  • Szlat

    Wicked Sick!

    Joined: 05/18/2005 18:32:41
    Messages: 2124
    Location: UK
    Offline

    Two slight changes.

    The first is that I have restricted bots so they cannot buy subclasses. They will not be able to intelligently change subclasses when they want to, so it is better for them to stick to the main classes.

    The second is a problem with high level bots. If the bot spawns at level 500, then it has a lot of skills to purchase in one go. The extra loop for checking if the ability is valid for that bot takes the code past the 10000000 iteration mark, and so the server crashes. So on a temporary basis, I have let bots buy any ability (except the subclass ability, and they will only be able to buy one class.)
    To be honest, I think this will probably be for the better anyway - bots are always underpowered, as they do not know how to use what they have.

    EDIT: Actually, I think I will move the Bot discussion to another thread. So, just the universal cost thread here please.
     
    Forum Index -> Druids RPG Go to Page: Previous  1, 2
    Go to: