KungFuClan / KungFuScreeps

https://screepers.gitbook.io/screeps-typescript-starter/
9 stars 4 forks source link

Improve MilitaryData.getRoomData CPU Usage to skip previously retrieved data #90

Closed UhmBrock closed 4 years ago

UhmBrock commented 4 years ago

The getRoomData method should be able to do the following

Ideally this will allow us to retrieve only the data we need at any given time. E.g.


const roomData: RoomData

_.forEach(creeps, (creep: Creep) => { 

        roomData = getRoomData(roomData, creep, { hostiles: true });

        if(roomData.hostiles.allHostiles.length === 0) {
                return;
        }

        // We do not get here if there were no hostiles, so we don't waste CPU getting ramparts
       roomData = getRoomData(roomData, creep, { openRamparts: true });
       // roomData should now contain the definitions for { hostiles, openRamparts }

       // from here we would go to an openRampart and handle hostiles as normal