Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#2045 closed defect (fixed)

[PATCH] Cache technology modifiers based on both name and value

Reported by: O.Davoodi Owned by: O.Davoodi
Priority: Should Have Milestone: Alpha 15
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

Currently we only cache the technology modifiers based on the name of the value. In the current code, if the value changes, it is not registered in the TechManager and the older value is returned.

It has already broken the "TARDIS" cheat, which changes the player's maximum population. It can also cause problems in future (for example, when implementing a stat changer trigger effect).

To fix this, we can make the game cache the modifier based on both name and value.

Attachments (3)

techmanager-cache-value.patch (2.0 KB ) - added by O.Davoodi 11 years ago.
A patch to fix the issue
techmanager-cache-value.2.patch (2.0 KB ) - added by O.Davoodi 11 years ago.
New version
techmanager-cache-values.diff (2.6 KB ) - added by sanderd17 11 years ago.

Download all attachments as: .zip

Change History (13)

by O.Davoodi, 11 years ago

A patch to fix the issue

comment:1 by O.Davoodi, 11 years ago

Keywords: patch added

comment:2 by leper, 11 years ago

Keywords: cache technology modifier removed

I'm quite certain that delete this.modificationCache[valueName][ent]; will not work as it should be cacheBase instead of ent.

by O.Davoodi, 11 years ago

New version

comment:3 by O.Davoodi, 11 years ago

Fixed it.

comment:4 by O.Davoodi, 11 years ago

leper: do you have any other suggestions?

comment:5 by leper, 11 years ago

I'm not sure if clearModificationCache() works correctly, as I think the break could lead to missing some modifications. If you have two modifications with different curValues clearing the cache will just remove the first cached value, so I'd opt for removing the break.

I'm not really sure if the current way is the best way of handling this, but I can't think of a better way currently and if it works (and is properly tested) it should be committed IMO.

While we're at it we could add some tests for the TechnologyManager.

in reply to:  5 comment:6 by O.Davoodi, 11 years ago

I'm not sure if clearModificationCache() works correctly, as I think the break could lead to missing some modifications. If you have two modifications with different curValues clearing the cache will just remove the first cached value, so I'd opt for removing the break.

This is the case if the older modifications are actually not removed, because I don't see any way for us to have two caches with different curValue's unless we actually have not cleared the cache somewhere else.

While we're at it we could add some tests for the TechnologyManager.

I'm afraid I don't know how to do it. I have seen the test folders but don't know what do they do exactly.

comment:7 by leper, 11 years ago

Keywords: review added
Milestone: Alpha 14Alpha 15

by sanderd17, 11 years ago

comment:8 by sanderd17, 11 years ago

I think my patch is a bit cleaner, conceptually. As it doesn't allow one ent with two different old values to be cached.

comment:9 by leper, 10 years ago

Resolution: fixed
Status: newclosed

In 14205:

Cache technology modifiers based on original value. Patch from sanderd17 based on work by Spahbod. Fixes #2045.

comment:10 by leper, 10 years ago

Keywords: review removed
Note: See TracTickets for help on using tickets.