// include/bus.h #ifndef BUS_H #define BUS_H #include #include "route.h" #include "station.h" #define MAX_BUSES 50 // 巴士状态枚举 typedef enum { BUS_MOVING, // 行驶中 BUS_STOPPING, // 停靠中 BUS_IDLE // 空闲/未启动 } BusStatus; // 巴士方向枚举 typedef enum { DIRECTION_FORWARD, // 正向(起点到终点) DIRECTION_BACKWARD // 反向(终点到起点) } BusDirection; // 巴士结构体 typedef struct Bus { int id; // 巴士编号 int routeId; // 所属线路ID BusStatus status; // 当前状态 BusDirection direction; // 行驶方向 int currentStationIndex; // 当前站点索引(在线路站点数组中的位置) double progress; // 在两站之间的进度(0.0-1.0) double speed; // 速度(km/h) double stopTimeRemaining; // 剩余停靠时间(分钟) double totalDistance; // 总行驶距离(km) double totalTime; // 总运行时间(分钟) } Bus; // 巴士管理系统 typedef struct BusSystem { Bus buses[MAX_BUSES]; int busCount; double systemTime; // 系统运行时间(分钟) } BusSystem; // 巴士系统初始化 BusSystem *createBusSystem(); void destroyBusSystem(BusSystem *system); // 巴士管理 int addBus(BusSystem *system, int routeId, int startStationIndex, BusDirection direction, double speed); Bus *getBus(BusSystem *system, int busId); void removeBus(BusSystem *system, int busId); // 巴士模拟 void updateBusSystem(BusSystem *system, const BusRoute routes[], int routeCount, const Station stations[], int stationCount, double deltaTime); void updateSingleBus(Bus *bus, const BusRoute *route, const Station stations[], int stationCount, double deltaTime); // 显示功能 void displayBus(const Bus *bus, const BusRoute routes[], int routeCount, const Station stations[], int stationCount); void displayAllBuses(const BusSystem *system, const BusRoute routes[], int routeCount, const Station stations[], int stationCount); // 查询功能 void queryBusesOnRoute(const BusSystem *system, int routeId, const BusRoute routes[], int routeCount, const Station stations[], int stationCount); void queryBusesAtStation(const BusSystem *system, int stationId, const BusRoute routes[], int routeCount, const Station stations[], int stationCount); // 自动模拟 void runSimulation(BusSystem *system, const BusRoute routes[], int routeCount, const Station stations[], int stationCount, double duration, double timeStep); #endif