aboutsummaryrefslogtreecommitdiff
Commit message (Expand)AuthorAge
* Fix manual operation of mesecon switchesorwell962017-02-20
* Fix crash when ATC rail exists but no command is saved.orwell962017-02-20
* don't pass unexistant variable to train_step_b (fixes #46)orwell962017-02-17
* use mesecons_switch as correct dependency for luaautomationorwell962017-02-15
* fix crash on seatpc nilorwell962017-02-15
* fix #34 - end_index not set when step_a returned in phase 2orwell962017-02-15
* Proper implementation for getting on by walking into train, rework damage and...orwell962017-02-09
* Merge PR from gpcf (Get on by walking in)orwell962017-02-07
|\
| * Merge branch 'master' of https://github.com/orwell96/advtrainsGabriel Pérez-Cerezo2017-02-05
| |\
| * | Found out why collision box does not fit trainGabriel Pérez-Cerezo2017-01-29
| * | Added getting on and off by walking in and out. Default seat on subway is now...Gabriel Pérez-Cerezo2017-01-29
* | | Use identical proxy environment with swapped metatable to not having to setfe...orwell962017-02-07
* | | Check if node is actually loaded before querying get_meta()orwell962017-02-05
* | | Do not invalidate paths unnecessarilyorwell962017-02-05
* | | Fix "lock couples" checkbox on wagon properties formorwell962017-02-05
* | | Fix ATC components being randomly ignored by trains.orwell962017-02-05
* | | Fix itrainmaporwell962017-02-05
* | | Fix LuaAtc Interrupt savingorwell962017-02-05
* | | Even more bugfixesorwell962017-02-04
| |/ |/|
* | Commit 1.6.2orwell962017-02-04
* | pack for releaseorwell962017-02-03
* | fix up stuff in itrainmaporwell962017-02-03
* | Revert change to node pos hashes, and rewrite trackdb to use individual coord...orwell962017-02-03
* | Add quick position lookup by punching nodesorwell962017-02-03
* | add wallmounted light signalorwell962017-02-03
* | Fix itrainmap not workingorwell962017-02-03
* | Merge PR from mbb: add better textures and craftsorwell962017-02-02
|\ \
| * | add better textures and craftsmbblp2017-02-02
* | | Add documentation and pack for releaseorwell962017-02-02
* | | LuaAutomation: Add interrupt to the ingame API and implement initialization c...orwell962017-02-02
* | | LuaAutomation - Basic component implementationorwell962017-02-02
* | | Fix collision to work with pos node hashesorwell962017-02-02
* | | Lua automation - initial incomplete codingorwell962017-02-02
* | | Replace all table indices that were pos_to_string strings with node hashes.orwell962017-01-31
* | | Join itrainmap mod into the modpackorwell962017-01-31
* | | Remove lua_atc from advtrains main mod.orwell962017-01-31
|/ /
* | Limit dtime to prevent trains moving too far in a single steporwell962017-01-29
* | Add getter calls for raw nodedborwell962017-01-29
* | Fix wagon properties not saved on button clickorwell962017-01-29
|/
* Fix a crash, update translations and zip fileorwell962017-01-28
* Multiple major changes:orwell962017-01-28
* remove tunnelborerorwell962017-01-25
* Document door animation parametersorwell962017-01-25
* Add forced get-on/off to prevent trains being unusable due to closed doors.orwell962017-01-25
* Rewrite seating systemorwell962017-01-25
* update ziporwell962017-01-25
* Fix typo that caused crashorwell962017-01-25
* Fix find&replace mistake that broke ATC command interpretationorwell962017-01-24
* Fix crash when train went off trackorwell962017-01-24
* Create new models and textures for japanese trainorwell962017-01-24
'p' - Referring or pointing towards the 'prev' path item, the one with index-1 -- 'f' - Referring to the positive end of the path (the end with the higher index) -- 'b' - Referring to the negative end of the path (the end with the lower index) -- New path structure of trains: --Tables: -- path - path positions. 'indices' are relative to this. At the moment, at.round_vector_floor_y(path[i]) -- is the node this item corresponds to, however, this will change in the future. -- path_node - (reserved) -- path_cn - Connid of the current node that points towards path[i+1] -- path_cp - Connid of the current node that points towards path[i-1] -- When the day comes on that path!=node, these will only be set if this index represents a transition between rail nodes -- path_dist - The total distance of this path element from path element 0 -- path_dir - The direction of this path item's transition to the next path item, which is the angle of conns[path_cn[i]].c -- path_speed- Populated by the LZB system. The maximum speed (velocity) permitted in the moment this path item is passed. -- (this saves brake distance calculations every step to determine LZB control). nil means no limit. --Variables: -- path_ext_f/b - how far path[i] is set -- path_trk_f/b - how far the path extends along a track. beyond those values, paths are generated in a straight line. -- path_req_f/b - how far path items were requested in the last step -- --Distance and index: -- There is an important difference between the path index and the actual distance on the track: The distance between two path items can be larger than 1, -- but the corresponding index increment is still 1. -- Indexes in advtrains can be fractional values. If they are, it means that the actual position is interpolated between the 2 adjacent path items. -- If you need to proceed along the path by a specific actual distance, it does NOT work to simply add it to the index. You should use the path_get_index_by_offset() function. -- creates the path data structure, reconstructing the train from a position and a connid -- returns: true - successful -- nil - node not yet available/unloaded, please wait -- false - node definitely gone, remove train function advtrains.path_create(train, pos, connid, rel_index) local posr = advtrains.round_vector_floor_y(pos) local node_ok, conns, rhe, connmap = advtrains.get_rail_info_at(pos) if not node_ok then return node_ok end local mconnid = advtrains.get_matching_conn(connid, connmap) train.index = rel_index train.path = { [0] = { x=posr.x, y=posr.y+rhe, z=posr.z } } train.path_cn = { [0] = connid } train.path_cp = { [0] = mconnid } train.path_dist = { [0] = 0 } train.path_dir = { [0] = advtrains.conn_angle_median(conns[mconnid].c, conns[connid].c) } train.path_speed = { } train.path_ext_f=0 train.path_ext_b=0 train.path_trk_f=0 train.path_trk_b=0 train.path_req_f=0 train.path_req_b=0 advtrains.occ.set_item(train.id, posr, 0) return true end -- Sets position and connid to properly restore after a crash, e.g. in order -- to save the train or to invalidate its path -- Assumes that the train is in clean state -- if invert ist true, setrestore will use the end index function advtrains.path_setrestore(train, invert) local idx = train.index if invert then idx = train.end_index end local pos, connid, frac = advtrains.path_getrestore(train, idx, invert, true) train.last_pos = pos train.last_connid = connid train.last_frac = frac end -- Get restore position, connid and frac (in this order) for a train that will originate at the passed index -- If invert is set, it will return path_cp and multiply frac by -1, in order to reverse the train there. function advtrains.path_getrestore(train, index, invert) local idx = index local cns = train.path_cn if invert then cns = train.path_cp end local fli = atfloor(index) advtrains.path_get(train, fli) if fli > train.path_trk_f then fli = train.path_trk_f end if fli < train.path_trk_b then fli = train.path_trk_b end return advtrains.path_get(train, fli), cns[fli], (idx - fli) * (invert and -1 or 1) end -- Invalidates a path -- this is supposed to clear stuff from the occupation tables -- This function throws a warning whenever any code calls it while the train steps are run, since that must not happen. -- The ignore_lock parameter can be used to ignore this, however, it should then be accompanied by a call to train_ensure_init -- before returning from the calling function. function advtrains.path_invalidate(train, ignore_lock) if advtrains.lock_path_inval and not ignore_lock then atwarn("Train ",train.id,": Illegal path invalidation has occured during train step:") atwarn(debug.traceback()) end if train.path then --atdebug("path_invalidate for",train.id) local _cnt = 0 for i,p in pairs(train.path) do _cnt = _cnt + 1 if _cnt > 10000 then atdebug(train) error("Loop trap in advtrains.path_invalidate was triggered!") end advtrains.occ.clear_all_items(train.id, advtrains.round_vector_floor_y(p)) end --atdebug("occ cleared") end train.path = nil train.path_dist = nil train.path_cp = nil train.path_cn = nil train.path_dir = nil train.path_speed = nil train.path_ext_f=0 train.path_ext_b=0 train.path_trk_f=0 train.path_trk_b=0 train.path_req_f=0 train.path_req_b=0 train.dirty = true --atdebug(train.id, "Path invalidated") end -- Keeps the path intact, but invalidates all path nodes from the specified index (inclusive) -- onwards. This has the advantage that we don't need to recalculate the whole path, and we can do it synchronously. function advtrains.path_invalidate_ahead(train, start_idx, ignore_when_passed) if not train.path then -- the path wasn't even initialized. Nothing to do return end local idx = atfloor(start_idx) --atdebug("Invalidate_ahead:",train.id,"start_index",start_idx,"cur_idx",train.index) if(idx <= train.index - 0.5) then if ignore_when_passed then --atdebug("ignored passed") return end advtrains.path_print(train, atwarn) error("Train "+train.id+": Cannot path_invalidate_ahead start_idx="+idx+" as train has already passed!") end -- leave current node in path, it won't change. What might change is the path onward from here (e.g. switch) local i = idx + 1 while train.path[i] do advtrains.occ.clear_specific_item(train.id, advtrains.round_vector_floor_y(train.path[i]), i) i = i+1 end train.path_ext_f=idx train.path_trk_f=math.min(idx, train.path_trk_f) -- callbacks called anyway for current node, because of LZB advtrains.run_callbacks_invahead(train.id, train, idx) end -- Prints a path using the passed print function -- This function should be 'atprint', 'atlog', 'atwarn' or 'atdebug', because it needs to use print_concat_table function advtrains.path_print(train, printf)