The problem mainly is the repairer will only fix a few pieces of wall, like one or two pieces. So, it don't make it work. If you have better ideas to add to the code or to fix it.
Please write in the comment or answer what tou fix or add. Thank you very much. (My first time play Screeps and use stackoverflow
This my code:
var roleRepairer = {
run: function(creep)
{
if(creep.memory.repairing && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.repairing = false;
creep.say('🔄 harvest');
}
if(!creep.memory.repairing && creep.store.getFreeCapacity() == 0) {
creep.memory.repairing= true;
creep.say('🚧 repair');
}
if(!creep.memory.repairing && creep.carry.energy == creep.carryCapacity)
{
creep.say('repairing');
creep.memory.repairing = true;
}
if(creep.memory.repairing)
{
var potentialRepairSite = creep.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_ROAD || structure.structureType == STRUCTURE_RAMPART || structure.structureType == STRUCTURE_WALL)}});
for(i = 0; i < potentialRepairSite.length; i++)
{
if(creep.repair(potentialRepairSite[i]) == ERR_NOT_IN_RANGE)
{
creep.moveTo(potentialRepairSite[i], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
else
{
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
}
};
module.exports = roleRepairer;
Please help me fix it out, thank you.
Related
I cannot display the timeline in Fullcalender using the code in the link below.
ttps://codepen.io/dreamflying/pen/jRoPWB
Console error content.
What is defs at the point of the function call? It would appear that it is null.
You could alter the function to not execute if defs is null (only execute if not null)
something like this
function addDefs(defs) {
if(defs != null && defs.length > 0) {
for (var _i = 0; _i < defs.length; _i++) {
var def = defs[_i];
if (!isAdded[def.id]) {
isAdded[def.id] = true;
addDefs(def.deps);
hooks = combineHooks(hooks, def);
}
}
}
}
I have a pathfinding game and I want to generate a maze using randomized Kruskal's algorithm. I am using a rank-based disjoint set to detect cycles. Specifically, I am using this implementation.
However, it turns out that the mazes could not be solved at all. Which leads me to believe that something is wrong with my implementation logic.
function generateKruskals(grid)
{
grid = initWalls(grid);
let MST = {};
for(let i = 0; i < NUM_ROWS; i++)
{
for(let j = 0; j < NUM_COLS; j++)
{
let node = grid[i][j];
if(!node.isStart && !node.isFinish)
{
let entry = makeSet();
entry.data = node;
MST[[i, j]] = entry;
}
}
}
while(Object.keys(MST).length > 0)
{
let keys = Object.keys(MST);
let nodeKey = keys[Math.floor(Math.random() * keys.length)];
let nodeSet = MST[nodeKey];
let node = nodeSet.data;
let neighbors = getNeighborWalls(grid, node);
if (neighbors.length > 0){
let neighbor = neighbors[Math.floor(Math.random() * neighbors.length)];
let neighborNodeset = MST[[neighbor.row, neighbor.col]];
if (neighborNodeset !== undefined)
{
if (find(nodeSet) !== find(neighborNodeset)) tearDownWall(neighborNodeset.data);
union(nodeSet, neighborNodeset);
}
}
delete MST[nodeKey];
}
return grid;
}
Here is what the unsolvable maze looks like.
UPDATE: include the getNeighborWalls implementation.
export function getNeighborWalls(grid, node) {
let neighbors = [];
try {
let leftNeighbor = grid[node.row][node.col - 1];
if (isNodeAWall(leftNeighbor)) neighbors.push(leftNeighbor);
} catch (err) {}
try {
let rightNeighbor = grid[node.row][node.col + 1];
if (isNodeAWall(rightNeighbor)) neighbors.push(rightNeighbor);
} catch (err) {}
try {
let topNeighbor = grid[node.row - 1][node.col];
if (isNodeAWall(topNeighbor)) neighbors.push(topNeighbor);
} catch (err) {}
try {
let bottomNeighbor = grid[node.row + 1][node.col];
if (isNodeAWall(bottomNeighbor)) neighbors.push(bottomNeighbor);
} catch (err) {}
return neighbors;
}
I need to hide few fields in a Quick View Form based on an Option Set (Choice) selection in that Quick View form. However it is not working, so am sharing the code I used for the same here. In my code, I am trying to hide certain fields if the option selected is not equal to a particular value...
function hideFields(executionContext) {
var formContext = executionContext.getFormContext();
var quickViewControl = formContext.ui.quickForms.get("General");
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
var orgtypevalue = quickViewControl.getControl("new_organizationtype").getValue();
if (orgtypevalue != 248870006) {
quickViewControl.getControl("new_recipienttype").setVisible(false);
quickViewControl.getControl("new_businesstype").setVisible(false);
quickViewControl.getControl("new_businesstypecode").setVisible(false);
quickViewControl.getControl("new_businesstypecharacteristicstypecode").setVisible(false);
return;
}
else {
// Wait for some time and check again
setTimeout(getAttributeValue, 10, executionContext);
}
}
else {
console.log("No data to display in the quick view control.");
return;
}
else {
quickViewControl.getControl("new_recipienttype").setVisible(true);
quickViewControl.getControl("new_businesstype").setVisible(true);
quickViewControl.getControl("new_businesstypecode").setVisible(true);
quickViewControl.getControl("new_businesstypecharacteristicstypecode").setVisible(true);
return;
}
}
}
I need to know where am I wrong. Any help will be appreciated.
Thanks!
you need to update the following
first if version 9 I am updating this
"var quickViewControl = formContext.ui.quickForms.get("General");"
to "var quickViewControl = formContext._ui._quickForms.get("General");"
&
"var orgtypevalue = quickViewControl.getControl("new_organizationtype").getValue();"
to
"var orgtypevalue = quickViewControl.getAttribute("new_organizationtype").getValue();"
& update else with message to wait and call the function again like this
"setTimeout(hideFields, 10, executionContext);"
and add else for the If of "quickViewControl != undefined"
Kindly find the updated code:
function hideFields(executionContext) {
var formContext = executionContext.getFormContext();
var quickViewControl = formContext._ui._quickForms.get("General");
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
var orgtypevalue = quickViewControl.getAttribute("new_organizationtype").getValue();
if (orgtypevalue != 248870006) {
quickViewControl.getControl("new_recipienttype").setVisible(false);
quickViewControl.getControl("new_businesstype").setVisible(false);
quickViewControl.getControl("new_businesstypecode").setVisible(false);
quickViewControl.getControl("new_businesstypecharacteristicstypecode").setVisible(false);
return;
}
else {
// Wait for some time and check again
setTimeout(hideFields, 10, executionContext);
}
}
else {
//console.log("No data to display in the quick view control.");
//return;
setTimeout(hideFields, 10, executionContext);
}
}
}
is there a way of paning the bubble in the current view when there are regions which are outside the mapview?
E.g. https://dev2.gruppenunterkuenfte.de/nordrhein-westfalen__r187.html?vs=1
You can click on a bubble at the edge and you see them outside.
Using google: https://www.gruppenunterkuenfte.de/nordrhein-westfalen__r187.html?vs=1
will pan automatically in the full view ...
Regards
Chris
Might not be available out of the box, but something as follows could be done to check when opening the bubble and move the map center.
var checkBubble = function(evt) {
setTimeout(function() {
if(infoBubble && infoBubble.getState() == "open"){
var border = 50;
var objRect = infoBubble.getContentElement().parentElement.getBoundingClientRect();
var objStyleRight = Math.abs(parseInt(infoBubble.getContentElement().parentElement.style.right));
objStyleRight = objStyleRight ? objStyleRight : 0;
var mapRect = map.getElement().getBoundingClientRect();
var shiftX = 0;
var shiftY = 0;
// check, if infobubble isn't too far to up
if ((objRect.top-border) < mapRect.top) {
shiftY = (mapRect.top - (objRect.top-border));
}
// check, if infobubble isn't too far to the left
var objLeft = (objRect.left - objStyleRight);
if ((objLeft-border) < mapRect.left) {
shiftX = (mapRect.left - (objLeft-border));
} // check, if infobubble isn't too far to the right
else if ((objRect.right+border) > mapRect.right) {
shiftX = -(objRect.right - (mapRect.right-border));
}
if ((shiftX == 0) && (shiftY == 0)) {
return;
}
var currScreenCenter = map.geoToScreen(map.getCenter());
var newY = (currScreenCenter.y - shiftY);
var newX = (currScreenCenter.x - shiftX);
var newGeoCenter = map.screenToGeo(newX, newY);
map.setCenter(newGeoCenter, true);
}
}, 20);
}
map.addEventListener("mapviewchange",checkBubble);
Thanks a lot works great! I extend to the case that the bubble is outside at the bottom:
...
// check, if infobubble isn't too far to up
if ((objRect.top-border) < mapRect.top) {
shiftY = (mapRect.top - (objRect.top-border));
} else {
if ((objRect.bottom+border) > mapRect.bottom) {
shiftY = -(objRect.bottom - (mapRect.bottom-border));
}
}
...
Regards
Chris
Hi I want to have an event source which allows overlaying(collision with) other event sources without resizing.
But the other event sources should still be using the normal collision detection and resizing?
Did somebody have the same problem?
Ok I found the solution:
First change the function segCollide(seg1, seg2) in fullcalendar to:
function segsCollide(seg1, seg2) {
if(seg1.allowCollision || seg2.allowCollision)
{
return false
}
else
{
return seg1.end > seg2.start && seg1.start < seg2.end;
}
}
And sliceSegs() to:
function sliceSegs(events, visEventEnds, start, end) {
var segs = [],
i, len=events.length, event,
eventStart, eventEnd,
segStart, segEnd,
isStart, isEnd;
for (i=0; i<len; i++) {
event = events[i];
allowCollision = event.source.allowCollision;
eventStart = event.start;
eventEnd = visEventEnds[i];
if (eventEnd > start && eventStart < end) {
if (eventStart < start) {
segStart = cloneDate(start);
isStart = false;
}else{
segStart = eventStart;
isStart = true;
}
if (eventEnd > end) {
segEnd = cloneDate(end);
isEnd = false;
}else{
segEnd = eventEnd;
isEnd = true;
}
segs.push({
event: event,
start: segStart,
end: segEnd,
allowCollision: allowCollision,
isStart: isStart,
isEnd: isEnd,
msLength: segEnd - segStart
});
}
}
return segs.sort(segCmp);
}