aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking
Commit message (Expand)AuthorAge
...
* tcb: Fix crash when player is nilLinus Jahn2020-09-01
* DISCARD ON MERGE!: Temporary compatibility fix: translate signal aspects back...orwell962020-07-23
* Make using the default tracks optional, even in submodsBlockhead2020-07-10
* Add "Fallback state" for freed routes, move p_mesecon_iface.lua to coreorwell962020-07-07
* Fix minetest.after() loop between ARS->update_route->update_signal_aspect->in...orwell962020-06-05
* Apply minetest.formspec_escape() to prevent formspec injection (H#143)MT0.4Blockhead2020-01-04
* Add inverse ARS rulesGabriel Pérez-Cerezo2019-12-05
* Fix the "red signals" bug that appeared when clicking a green signalorwell962019-11-21
* Do not throw error when sync_tcb_neighbors failsorwell962019-08-29
* Don't allow to remove TCB when a signal is assignedorwell962019-08-26
* Various small fixesGabriel Pérez-Cerezo2019-07-16
* Fix remote routesettingorwell962019-04-16
* Move LZB system to core and unify approach callback mechanismorwell962019-04-16
* Disable-ARS switch in signal and set this when cancelling an ARS routeorwell962019-03-15
* Ugly workaround for green signals bugorwell962019-03-15
* Fix cancelling "Unknown Route" when section is deleted.orwell962019-03-15
* Do not clear LZB control when invalidating.orwell962019-02-23
* possible fix for "trains standing at green signals"orwell962019-02-21
* Fix moving Signal IPs (no duplicate IPs)orwell962019-02-21
* Add ARS rules for stop railsorwell962019-02-19
* Prioritize LZB callback (possible bugfix for H#100)orwell962019-02-19
* Improve Signal IP form/workfloworwell962019-02-16
* Fix TCBS crash also for route_uiorwell962019-02-16
* Fix routesetting when TCBS is missing (H#109)orwell962019-02-12
* Fixes regarding signal assignments/tcbsorwell962019-02-09
* Signalling form auto-updateorwell962019-02-05
* Force LZB Halt settingorwell962019-02-05
* Minor Bugfixesorwell962019-02-03
* Basic functions of "stop rail", missing ARS rules and signal.orwell962019-01-24
* Point speed restriction railsorwell962019-01-24
* Fix last commit (and another warn2log)orwell962019-01-22
* Fix atc command evaluation BB commandorwell962019-01-22
* Make LZB params adjustableorwell962019-01-22
* another small fix for route_uiorwell962019-01-22
* Fix small bug in routeui and make another message log-onlyorwell962019-01-22
* disable debug print of ARSorwell962019-01-22
* Fix may_modify_section on newly created sectionsorwell962019-01-22
* Fix invalid path invalidation in ARS codeorwell962019-01-22
* Prohibit removing/changing of TCBs and sections while routes or signals are setorwell962019-01-22
* Do not run LZB traverser when path does not existorwell962019-01-21
* Fix route aspect dialogorwell962019-01-15
* Fix Routingcode ARSorwell962019-01-15
* Can disable automatic working without cancelling routeorwell962019-01-15
* Actual working ARSorwell962019-01-15
* Add Automatic Routesetting UIorwell962019-01-09
* Fix crashes:orwell962018-12-10
* Signs (static signals)orwell962018-12-08
* Shunt signals (not exactly Ks), along with fixes in other components that tho...orwell962018-12-08
* Apply speed restriction 0.5 indexes later, do not cap tarvelocity by speed_re...orwell962018-12-04
* Do not set speed_restriction for nprorwell962018-12-04
ot; #include <algorithm> #include <vector> FlagDesc flagdesc_deco[] = { {"place_center_x", DECO_PLACE_CENTER_X}, {"place_center_y", DECO_PLACE_CENTER_Y}, {"place_center_z", DECO_PLACE_CENTER_Z}, {"force_placement", DECO_FORCE_PLACEMENT}, {"liquid_surface", DECO_LIQUID_SURFACE}, {"all_floors", DECO_ALL_FLOORS}, {"all_ceilings", DECO_ALL_CEILINGS}, {NULL, 0} }; /////////////////////////////////////////////////////////////////////////////// DecorationManager::DecorationManager(IGameDef *gamedef) : ObjDefManager(gamedef, OBJDEF_DECORATION) { } size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { size_t nplaced = 0; for (size_t i = 0; i != m_objects.size(); i++) { Decoration *deco = (Decoration *)m_objects[i]; if (!deco) continue; nplaced += deco->placeDeco(mg, blockseed, nmin, nmax); blockseed++; } return nplaced; } /////////////////////////////////////////////////////////////////////////////// void Decoration::resolveNodeNames() { getIdsFromNrBacklog(&c_place_on); getIdsFromNrBacklog(&c_spawnby); } bool Decoration::canPlaceDecoration(MMVManip *vm, v3s16 p) { // Check if the decoration can be placed on this node u32 vi = vm->m_area.index(p); if (!CONTAINS(c_place_on, vm->m_data[vi].getContent())) return false; // Don't continue if there are no spawnby constraints if (nspawnby == -1) return true; int nneighs = 0; static const v3s16 dirs[16] = { v3s16( 0, 0, 1), v3s16( 0, 0, -1), v3s16( 1, 0, 0), v3s16(-1, 0, 0), v3s16( 1, 0, 1), v3s16(-1, 0, 1), v3s16(-1, 0, -1), v3s16( 1, 0, -1), v3s16( 0, 1, 1), v3s16( 0, 1, -1), v3s16( 1, 1, 0), v3s16(-1, 1, 0), v3s16( 1, 1, 1), v3s16(-1, 1, 1), v3s16(-1, 1, -1), v3s16( 1, 1, -1) }; // Check these 16 neighbouring nodes for enough spawnby nodes for (size_t i = 0; i != ARRLEN(dirs); i++) { u32 index = vm->m_area.index(p + dirs[i]); if (!vm->m_area.contains(index)) continue; if (CONTAINS(c_spawnby, vm->m_data[index].getContent())) nneighs++; } if (nneighs < nspawnby) return false; return true; } size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { PcgRandom ps(blockseed + 53); int carea_size = nmax.X - nmin.X + 1; // Divide area into parts // If chunksize is changed it may no longer be divisable by sidelen if (carea_size % sidelen) sidelen = carea_size; s16 divlen = carea_size / sidelen; int area = sidelen * sidelen; for (s16 z0 = 0; z0 < divlen; z0++) for (s16 x0 = 0; x0 < divlen; x0++) { v2s16 p2d_center( // Center position of part of division nmin.X + sidelen / 2 + sidelen * x0, nmin.Z + sidelen / 2 + sidelen * z0 ); v2s16 p2d_min( // Minimum edge of part of division nmin.X + sidelen * x0, nmin.Z + sidelen * z0 ); v2s16 p2d_max( // Maximum edge of part of division nmin.X + sidelen + sidelen * x0 - 1, nmin.Z + sidelen + sidelen * z0 - 1 ); // Amount of decorations float nval = (flags & DECO_USE_NOISE) ? NoisePerlin2D(&np, p2d_center.X, p2d_center.Y, mapseed) : fill_ratio; u32 deco_count = 0; float deco_count_f = (float)area * nval; if (deco_count_f >= 1.f) { deco_count = deco_count_f; } else if (deco_count_f > 0.f) { // For low density decorations calculate a chance for 1 decoration if (ps.range(1000) <= deco_count_f * 1000.f) deco_count = 1; } for (u32 i = 0; i < deco_count; i++) { s16 x = ps.range(p2d_min.X, p2d_max.X); s16 z = ps.range(p2d_min.Y, p2d_max.Y); int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X); if ((flags & DECO_ALL_FLOORS) || (flags & DECO_ALL_CEILINGS)) { // All-surfaces decorations // Check biome of column if (mg->biomemap && !biomes.empty()) { std::unordered_set<u8>::const_iterator iter = biomes.find(mg->biomemap[mapindex]); if (iter == biomes.end()) continue; } // Get all floors and ceilings in node column u16 size = (nmax.Y - nmin.Y + 1) / 2; std::vector<s16> floors; std::vector<s16> ceilings; floors.reserve(size); ceilings.reserve(size); mg->getSurfaces(v2s16(x, z), nmin.Y, nmax.Y, floors, ceilings); if (flags & DECO_ALL_FLOORS) { // Floor decorations for (const s16 y : floors) { if (y < y_min || y > y_max) continue; v3s16 pos(x, y, z); if (generate(mg->vm, &ps, pos, false)) mg->gennotify.addEvent( GENNOTIFY_DECORATION, pos, index); } } if (flags & DECO_ALL_CEILINGS) { // Ceiling decorations for (const s16 y : ceilings) { if (y < y_min || y > y_max) continue; v3s16 pos(x, y, z); if (generate(mg->vm, &ps, pos, true)) mg->gennotify.addEvent( GENNOTIFY_DECORATION, pos, index); } } } else { // Heightmap decorations s16 y = -MAX_MAP_GENERATION_LIMIT; if (flags & DECO_LIQUID_SURFACE) y = mg->findLiquidSurface(v2s16(x, z), nmin.Y, nmax.Y); else if (mg->heightmap) y = mg->heightmap[mapindex]; else y = mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y); if (y < y_min || y > y_max || y < nmin.Y || y > nmax.Y) continue; if (mg->biomemap && !biomes.empty()) { std::unordered_set<u8>::const_iterator iter = biomes.find(mg->biomemap[mapindex]); if (iter == biomes.end()) continue; } v3s16 pos(x, y, z); if (generate(mg->vm, &ps, pos, false)) mg->gennotify.addEvent(GENNOTIFY_DECORATION, pos, index); } } } return 0; } /////////////////////////////////////////////////////////////////////////////// void DecoSimple::resolveNodeNames() { Decoration::resolveNodeNames(); getIdsFromNrBacklog(&c_decos); } size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) { // Don't bother if there aren't any decorations to place if (c_decos.empty()) return 0; if (!canPlaceDecoration(vm, p)) return 0; // Check for placement outside the voxelmanip volume if (ceiling) { // Ceiling decorations // 'place offset y' is inverted if (p.Y - place_offset_y - std::max(deco_height, deco_height_max) < vm->m_area.MinEdge.Y) return 0; if (p.Y - 1 - place_offset_y > vm->m_area.MaxEdge.Y) return 0; } else { // Heightmap and floor decorations if (p.Y + place_offset_y + std::max(deco_height, deco_height_max) > vm->m_area.MaxEdge.Y) return 0; if (p.Y + 1 + place_offset_y < vm->m_area.MinEdge.Y) return 0; } content_t c_place = c_decos[pr->range(0, c_decos.size() - 1)]; s16 height = (deco_height_max > 0) ? pr->range(deco_height, deco_height_max) : deco_height; u8 param2 = (deco_param2_max > 0) ? pr->range(deco_param2, deco_param2_max) : deco_param2; bool force_placement = (flags & DECO_FORCE_PLACEMENT); const v3s16 &em = vm->m_area.getExtent(); u32 vi = vm->m_area.index(p); if (ceiling) { // Ceiling decorations // 'place offset y' is inverted VoxelArea::add_y(em, vi, -place_offset_y); for (int i = 0; i < height; i++) { VoxelArea::add_y(em, vi, -1); content_t c = vm->m_data[vi].getContent(); if (c != CONTENT_AIR && c != CONTENT_IGNORE && !force_placement) break; vm->m_data[vi] = MapNode(c_place, 0, param2); } } else { // Heightmap and floor decorations VoxelArea::add_y(em, vi, place_offset_y); for (int i = 0; i < height; i++) { VoxelArea::add_y(em, vi, 1); content_t c = vm->m_data[vi].getContent(); if (c != CONTENT_AIR && c != CONTENT_IGNORE && !force_placement) break; vm->m_data[vi] = MapNode(c_place, 0, param2); } } return 1; } /////////////////////////////////////////////////////////////////////////////// size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) { // Schematic could have been unloaded but not the decoration // In this case generate() does nothing (but doesn't *fail*) if (schematic == NULL) return 0; if (!canPlaceDecoration(vm, p)) return 0; if (flags & DECO_PLACE_CENTER_Y) { p.Y -= (schematic->size.Y - 1) / 2; } else { // Only apply 'place offset y' if not 'deco place center y' if (ceiling) // Shift down so that schematic top layer is level with ceiling // 'place offset y' is inverted p.Y -= (place_offset_y + schematic->size.Y - 1); else p.Y += place_offset_y; } // Check schematic top and base are in voxelmanip if (p.Y + schematic->size.Y - 1 > vm->m_area.MaxEdge.Y) return 0; if (p.Y < vm->m_area.MinEdge.Y) return 0; if (flags & DECO_PLACE_CENTER_X) p.X -= (schematic->size.X - 1) / 2; if (flags & DECO_PLACE_CENTER_Z) p.Z -= (schematic->size.Z - 1) / 2; Rotation rot = (rotation == ROTATE_RAND) ? (Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation; bool force_placement = (flags & DECO_FORCE_PLACEMENT); schematic->blitToVManip(vm, p, rot, force_placement); return 1; }