- if(check_train_direction)
- {
- int train_entry = train->get_entry_to_block(*block);
- if(train_entry>=0 && static_cast<unsigned>(train_entry)==entry)
- {
- if(train_conn)
- train_conn.disconnect();
- train_conn = train->signal_advanced.connect(sigc::mem_fun(this, &Signal::train_advanced));
- }
- check_train_direction = false;
- check_allocated_blocks = true;
- }
+ // XXX Totally hardcoded stuff, should be replaced with a geometry system
+ Vector center = position;
+ center.x += sin(rotation)*0.035;
+ center.y -= cos(rotation)*0.035;
+ Vector d(center.x-start.x, center.y-start.y);
+ float x = (d.x*ray.x+d.y*ray.y)/(ray.x*ray.x+ray.y*ray.y);
+ Vector nearest(start.x+ray.x*x-center.x, start.y+ray.y*x-center.y, start.z+ray.z*x-center.z);
+ if(nearest.z<0|| nearest.z>0.12)
+ return false;
+ return nearest.x*nearest.x+nearest.y*nearest.y<0.0001;
+}