/*
 * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __TRAFFIC_H
#define __TRAFFIC_H

#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "list.h"

#define uloga(f, a...) fprintf(stderr, f, ##a)
#define ulog_err(f, a...) uloga(f ": %s [%d].\n", ##a, strerror(errno), errno)

#define TRAFFIC_DEBUG

#ifdef TRAFFIC_DEBUG
#define ulog(f, a...) uloga(f, ##a)
#else
#define ulog(f, a...) do {} while (0)
#endif

struct car
{
	struct list_head	car_entry;

	int			id;

	double			x;

	double			speed, prev_speed;

	double			max_allowed_speed;
	double			decel_dist;
	double			stop_dist;
	double			accel;
};

struct light
{
	struct list_head	light_entry;

	int			state;
	int			interval;

	double			x;
};

#define CAR_INF_DIST		(LONG_MAX)

extern void car_update_all(int max);
extern int car_main(int argc, char *argv[]);

extern struct list_head car_list;
extern struct list_head light_list;

#define LIGHT_RED		(1)
#define LIGHT_GREEN		(0)

#endif /* __TRAFFIC_H */

