pub fn assign_requests(state: &mut BWState) -> anyhow::Result<HashMap<RoomName, Request>> {
    let mut request_handlers: HashMap<RoomName, Request> = HashMap::new();
    for (id, request) in &state.requests {
        match request {
            Request {
                data:
                    RequestData::BootstrapWorkerCitizen(requests::BootstrapWorkerCitizen {
                        target_room_name,
                        ..
                    }),
                ..
            } => {
                if let Some(target_room) = state.room_states.get(target_room_name) {
                    match target_room {
                        RoomState::Base(room_state) => {
                            request_handlers.insert(room_state.room_name, request.to_owned());
                        }
                        RoomState::SetupBase(room_state) => {
                            // TODO use the get_helping_room_for_request from below if we
                            //   cant spawn the creeps we need
                            request_handlers.insert(room_state.room_name, request.to_owned());
                        }
                    }
                } else {
                    // We dont see the room, so there's nothing in there from us, so it needs help
                    // from another room
                    match get_helping_room_for_request(state, request) {
                        Ok(Some(closest_room)) => {
                            request_handlers.insert(closest_room, request.to_owned());
                        }
                        Ok(None) => {}
                        Err(err) => {
                            warn!("error get_helping_room_for_request: {}", err);
                        }
                    }
                }
            }
            Request {
                data:
                    RequestData::Citizen(requests::Citizen {
                        target_room_name, ..
                    }),
                ..
            } => {
                if let Some(target_room) = state.room_states.get(target_room_name) {
                    match target_room {
                        RoomState::Base(room_state) => {
                            request_handlers.insert(room_state.room_name, request.to_owned());
                        }
                        RoomState::SetupBase(room_state) => {
                            // HACK just use a regular vec instead or prioritize correctly
                            if let Some(rh) = request_handlers.get(&room_state.room_name) {
                                let existing_important = match &rh.data {
                                    RequestData::Citizen(data) => {
                                        data.resolve_panic
                                    },
                                    _ => false,
                                };
                                if !existing_important {
                                    request_handlers.insert(room_state.room_name, request.to_owned());
                                }
                            } else {
                                request_handlers.insert(room_state.room_name, request.to_owned());
                            }
                        }
                    }
                } else {
                    warn!("room for room_state {} is invisible ayy", target_room_name);
                }
            }
        }
    }
    Ok(request_handlers)
}
// NOTE Perhaps, instead of returning a HashMap, use an enum so requests can be handled by
//   something else than rooms?
// NOTE Later on we might want to handle _all_ spawning with these requests
NOTE Perhaps, instead of returning a HashMap, use an enum so requests can be handled by
something else than rooms.
NOTE Later on we might want to handle _all_ spawning with these requests
NOTE Perhaps instead of returning a HashMap use an enum so requests can be handled by something else than rooms . NOTE Later on we might want to handle _all_ spawning with these requests
pub fn assign_requests(state: &mut BWState) -> anyhow::Result<HashMap<RoomName, Request>> {
    let mut request_handlers: HashMap<RoomName, Request> = HashMap::new();
    for (id, request) in &state.requests {
        match request {
            Request {
                data:
                    RequestData::BootstrapWorkerCitizen(requests::BootstrapWorkerCitizen {
                        target_room_name,
                        ..
                    }),
                ..
            } => {
                if let Some(target_room) = state.room_states.get(target_room_name) {
                    match target_room {
                        RoomState::Base(room_state) => {
                            request_handlers.insert(room_state.room_name, request.to_owned());
                        }
                        RoomState::SetupBase(room_state) => {
                            // TODO use the get_helping_room_for_request from below if we
                            //   cant spawn the creeps we need
                            request_handlers.insert(room_state.room_name, request.to_owned());
                        }
                    }
                } else {
                    // We dont see the room, so there's nothing in there from us, so it needs help
                    // from another room
                    match get_helping_room_for_request(state, request) {
                        Ok(Some(closest_room)) => {
                            request_handlers.insert(closest_room, request.to_owned());
                        }
                        Ok(None) => {}
                        Err(err) => {
                            warn!("error get_helping_room_for_request: {}", err);
                        }
                    }
                }
            }
            Request {
                data:
                    RequestData::Citizen(requests::Citizen {
                        target_room_name, ..
                    }),
                ..
            } => {
                if let Some(target_room) = state.room_states.get(target_room_name) {
                    match target_room {
                        RoomState::Base(room_state) => {
                            request_handlers.insert(room_state.room_name, request.to_owned());
                        }
                        RoomState::SetupBase(room_state) => {
                            // HACK just use a regular vec instead or prioritize correctly
                            if let Some(rh) = request_handlers.get(&room_state.room_name) {
                                let existing_important = match &rh.data {
                                    RequestData::Citizen(data) => {
                                        data.resolve_panic
                                    },
                                    _ => false,
                                };
                                if !existing_important {
                                    request_handlers.insert(room_state.room_name, request.to_owned());
                                }
                            } else {
                                request_handlers.insert(room_state.room_name, request.to_owned());
                            }
                        }
                    }
                } else {
                    warn!("room for room_state {} is invisible ayy", target_room_name);
                }
            }
        }
    }
    Ok(request_handlers)
}
pub fn assign_requests ( state : & mut BWState ) -> anyhow :: Result < HashMap < RoomName , Request > > { let mut request_handlers : HashMap < RoomName , Request > = HashMap :: new ( ) ; for ( id , request ) in & state . requests { match request { Request { data : RequestData :: BootstrapWorkerCitizen ( requests :: BootstrapWorkerCitizen { target_room_name , .. } ) , .. } => { if let Some ( target_room ) = state . room_states . get ( target_room_name ) { match target_room { RoomState :: Base ( room_state ) => { request_handlers . insert ( room_state . room_name , request . to_owned ( ) ) ; } RoomState :: SetupBase ( room_state ) => { // TODO use the get_helping_room_for_request from below if we //   cant spawn the creeps we need request_handlers . insert ( room_state . room_name , request . to_owned ( ) ) ; } } } else { // We dont see the room, so there's nothing in there from us, so it needs help // from another room match get_helping_room_for_request ( state , request ) { Ok ( Some ( closest_room ) ) => { request_handlers . insert ( closest_room , request . to_owned ( ) ) ; } Ok ( None ) => { } Err ( err ) => { warn ! ( " " err ) ; } } } } Request { data : RequestData :: Citizen ( requests :: Citizen { target_room_name , .. } ) , .. } => { if let Some ( target_room ) = state . room_states . get ( target_room_name ) { match target_room { RoomState :: Base ( room_state ) => { request_handlers . insert ( room_state . room_name , request . to_owned ( ) ) ; } RoomState :: SetupBase ( room_state ) => { // HACK just use a regular vec instead or prioritize correctly if let Some ( rh ) = request_handlers . get ( & room_state . room_name ) { let existing_important = match & rh . data { RequestData :: Citizen ( data ) => { data . resolve_panic } , _ => false , } ; if ! existing_important { request_handlers . insert ( room_state . room_name , request . to_owned ( ) ) ; } } else { request_handlers . insert ( room_state . room_name , request . to_owned ( ) ) ; } } } } else { warn ! ( " " target_room_name ) ; } } } } Ok ( request_handlers ) }
NOTE Perhaps, instead of returning a HashMap, use an enum so requests can be handled by
something else than rooms?
NOTE Perhaps instead of returning a HashMap use an enum so requests can be handled by something else than rooms?
state
&mut BWState
state
&mut BWState