ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Sat Dec 14, 2019 8:34 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Oct 12, 2012 6:39 pm 
Offline
Uruivellas

Joined: Thu Nov 18, 2010 6:42 pm
Posts: 744
I'm working on an addon with a lot of small changes to a large number of talents. Two questions:

1. Is there any way to see a revision history of individual functions/class definitions, etc. so that I can see if, say, the specific Fireflash talent definition (not just the fire.lua file) has been updated?

2. Is there a superload equivalent way to update only part of a talent definition, but leave the rest alone? In the case of Fireflash, I'd like to change only the "radius = function(...." part of the definition, but leave the rest alone, so that I don't need to rewrite that part of the addon if something else in the talent changes between game versions.

_________________
Author of the Infinite 500 and PlenumTooltip addons, and the joys of Scaling in ToME.


Top
 Profile  
 
PostPosted: Fri Oct 12, 2012 8:14 pm 
Offline
Sher'Tul

Joined: Mon Nov 24, 2003 2:31 pm
Posts: 1252
Location: South Africa
I die somethong like that in the constitution stamina addon, where i changed the stamina recover talent. So yes you can for the second part. Not sure about the first bot.


Top
 Profile  
 
PostPosted: Sat Oct 13, 2012 12:05 am 
Offline
Wyrmic

Joined: Wed Aug 22, 2012 12:16 am
Posts: 200
It's a little cumbersome but (assuming you're trying to track svn HEAD):
Code:
svn log -r BASE:HEAD --diff [path]
You have to check the line numbers that start the diff chunks against your local version to see what function they're in. A two step deal, but that's what I do. You'll probably want to pipe the output through more or another pager. If you use a graphical svn client, I have no help to offer.


Top
 Profile  
 
PostPosted: Sun Oct 14, 2012 4:50 pm 
Offline
Uruivellas

Joined: Thu Nov 18, 2010 6:42 pm
Posts: 744
Thanks for the replies. After some more digging, I've partially rewritten _M:newTalent in ActorTalents.lua to allow talents to be redefined multiple times. Superloading the old function, this merges (overwrites) new talent definitions on top of the old, greatly simplifying talent updates. Only changed fields (besides talent name and type) need to be included in the addon's overload or data definitions.

For example:

Code:
Original talent def                 Update def                           Effective (running) def
newTalent{                          newTalent{                           newTalent{
  name = "Fireflash",                 name = "Fireflash",                  name = "Fireflash",
  type = {"spell/fire",3},            type = {"spell/fire",3},             type = {"spell/fire",3},

....                                                                         <original fields carried over>

  range =7.                             ...                                 range =7.

...                                                                           <original fields carried over>

  radius = <original radius>,         radius = <new radius>,               radius = <new radius>,

...                                     ...                                  <original fields carried over>

  info = <original info>,             info = <new info>,                   info = <new info>,

}                                    }                                    }


I think this functionality should be added to the engine, since it makes addon talent changes much easier, faster to develop (and run) and more robust with respect to changing game versions. I've only updated the definition for talents, but similar functionality for actors, objects, etc, could also be done. I will post the new function definition after I've tested it a bit more.

_________________
Author of the Infinite 500 and PlenumTooltip addons, and the joys of Scaling in ToME.


Top
 Profile  
 
PostPosted: Sun Oct 14, 2012 8:27 pm 
Offline
Wyrmic

Joined: Wed Aug 22, 2012 12:16 am
Posts: 200
Hachem_Muche wrote:
Thanks for the replies. After some more digging, I've partially rewritten _M:newTalent in ActorTalents.lua to allow talents to be redefined multiple times. Superloading the old function, this merges (overwrites) new talent definitions on top of the old, greatly simplifying talent updates.

Talent updates are already fairly easy if you use hooks in your addon. Put a load.lua file in the hooks subdirectory of your mod and add a "ToME:load" hook:
Code:
require "engine.class"
require "engine.interface.ActorTalents"

class:bindHook("ToME:load", function (self, data)
   ActorTalents:loadDefinition("/data-my-mod/path/to/talent-changer.lua")
end)

Then, because the loadDefinition() function sets the environment in which its argument file runs, you can assign the talent you want to change to a local variable and override just the fields you want to change:
Code:
local talent_to_change = Talents:getTalentFromId(Talents.T_TALENT_ID)

talent_to_change.value_to_change = 7
talent_to_change.function_to_change = function (actor, talent)
   print "This message will show up in the log."
end

And it all works without any engine or module class changes, although I do agree it's not at all obvious. I figured out how to do it by tracing my way through the code.

Changing items is even easier using the (undocumented, even on the wiki) "Entity:loadList" hook. You don't even need extra files for this one. Just put the changes directly in load.lua. The name of the file that's being loaded is in data.file and all the items created in that file are stored in the data.res table. Say you wanted to add a couple gold to the price of Prox's foot:
Code:
require "engine.class"

class:bindHook("Entity:loadList", function (self, data)
   if data.file == "/data/general/objects/boss-artifacts.lua" then
      for _, item in ipairs(data.res) do
         if item.name == "Prox's Lucky Halfling Foot" then item.cost = item.cost + 2 end
      end
   end
end)

And, of course, don't forget to enable hooks in your init.lua file!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group