void
ModConfig::DisableMod(const char* name)
{
	if (!name || !*name)
	return;

	Text* mod_name;

	ListIter<Text> iter = enabled;
	while (++iter) {
		Text* t = iter.value();

		if (*t == name) {
			mod_name = t;
			iter.removeItem();
			break;
		}
	}

	if (mod_name) {
		disabled.append(mod_name);

		ListIter<ModInfo> iter = mods;
		while (++iter) {
			ModInfo* mod_info = iter.value();
			if (mod_info->Name() == *mod_name) {
				delete iter.removeItem();
				break;
			}
		}
	}
}
Exemplo n.º 2
0
void
Scene::Collect()
{
    ListIter<Graphic> iter = graphics;

    while (++iter) {
        Graphic* g = iter.value();
        if (g->Life() == 0) {
            delete iter.removeItem();
        }
    }   

    iter.attach(sprites);

    while (++iter) {
        Graphic* g = iter.value();
        if (g->Life() == 0) {
            delete iter.removeItem();
        }
    }   

    ListIter<Light> iter1 = lights;

    while (++iter1) {
        Light* l = iter1.value();
        if (l->Life() == 0) {
            delete iter1.removeItem();
        }
    }   
}
Exemplo n.º 3
0
void
Element::HandleRadioMessage(RadioMessage* msg)
{
	if (!msg) return;

	static RadioHandler rh;

	// if this is a message from within the element,
	// then all ships should report in.  Otherwise,
	// just the leader will acknowledge the message.
	int full_report = ships.contains(msg->Sender());
	int reported    = false;

	ListIter<Ship> s = ships;
	while (++s) {
		if (rh.ProcessMessage(msg, s.value())) {
			if (full_report) {
				if (s.value() != msg->Sender())
				rh.AcknowledgeMessage(msg, s.value());
			}

			else if (!reported) {
				rh.AcknowledgeMessage(msg, s.value());
				reported = true;
			}
		}
	}
}
Exemplo n.º 4
0
void
CameraDirector::SetViewObjectGroup(ListIter<Ship> group, bool quick)
{
    if (!ship) return;

    Starshatter* stars = Starshatter::GetInstance();

    if (!stars->InCutscene()) {
        // only view solid contacts:
        while (++group) {
            Ship* s = group.value();

            if (s->GetIFF() != ship->GetIFF()) {
                Contact* c = ship->FindContact(s);
                if (!c || !c->ActLock())
                return;
            }

            if (s->Life() == 0 || s->IsDying() || s->IsDead())
            return;
        }
    }

    group.reset();

    if (external_group.size() > 1 &&
            external_group.size() == group.size()) {

        bool same = true;

        for (int i = 0; same && i < external_group.size(); i++) {
            if (external_group[i] != group.container()[i])
            same = false;
        }

        if (same) {
            SetMode(MODE_ZOOM);
            return;
        }
    }

    ClearGroup();

    if (quick) {
        mode = MODE_ORBIT;
        transition = 0;
    }
    else {
        SetMode(MODE_TRANSLATE);
    }

    external_group.append(group.container());

    ListIter<Ship> iter = external_group;
    while (++iter) {
        Ship* s = iter.value();
        region = s->GetRegion();
        Observe(s);
    }
}
Exemplo n.º 5
0
void
UVMapView::SelectInverse()
{
    ListIter<Poly> iter = polys;
    while (++iter) {
        Poly* p = iter.value();

        if (p->material != material)
            continue;

        for (int i = 0; i < p->nverts; i++) {
            WORD  p_index = iter.index();
            DWORD value   = (p_index << 16) | i;

            bool contains = false;
            auto svi = selverts.begin();
            for (; svi != selverts.end(); ++svi) {
                if (*svi == value) {
                    contains = true;
                    break;
                }
            }

            if (contains)
                selverts.erase(svi);
            else
                selverts.push_back(value);
        }
    }
}
Exemplo n.º 6
0
bool
Screen::Resize(int w, int h)
{
	// scale all root-level windows to new screen size:

	ListIter<Window> iter = window_list;
	while (++iter) {
		Window* win = iter.value();

		double  w_x = win->GetRect().x / (double) width;
		double  w_y = win->GetRect().y / (double) height;
		double  w_w = win->GetRect().w / (double) width;
		double  w_h = win->GetRect().h / (double) height;

		Rect    r;

		r.x = (int) (w_x * w);
		r.y = (int) (w_y * h);
		r.w = (int) (w_w * w);
		r.h = (int) (w_h * h);

		win->MoveTo(r);
	}

	width  = w;
	height = h;

	return true;
}
void
ModConfig::EnableMod(const char* name)
{
	if (!name || !*name)
	return;

	Text* mod_name;

	ListIter<Text> iter = disabled;
	while (++iter) {
		Text* t = iter.value();

		if (*t == name) {
			mod_name = t;
			iter.removeItem();
			break;
		}
	}

	if (mod_name) {
		enabled.append(mod_name);

		if (!IsDeployed(*mod_name)) {
			ModInfo* mod_info = new(__FILE__,__LINE__) ModInfo;
			
			if (mod_info->Load(*mod_name) && mod_info->Enable()) {
				mods.append(mod_info);
			}
		}
	}
}
void
ModConfig::FindMods()
{
	disabled.destroy();

	DataLoader* loader = DataLoader::GetLoader();

	if (loader) {
		loader->UseFileSystem(true);
		loader->ListFiles("*.dat", disabled, true);
		loader->UseFileSystem(Starshatter::UseFileSystem());

		ListIter<Text> iter = disabled;
		while (++iter) {
			Text* name = iter.value();
			name->setSensitive(false);

			if (*name == "shatter.dat"      || 
					*name == "beta.dat"         || 
					*name == "start.dat"        ||
					*name == "irunin.dat"       ||
					*name == "vox.dat"          ||
					name->contains("uninstall") ||
					enabled.contains(name))
			delete iter.removeItem();
		}
	}
}
void
CampaignPlanStrategic::ScoreDefend(Combatant* c, CombatGroup* g)
{
    if (!g || g->IsReserve())
    return;

    if (g->IsDefensible()) {
        g->SetPlanValue(g->Value());
        c->GetDefendList().append(g);

        CombatZone* zone  = campaign->GetZone(g->GetRegion());
        ZoneForce*  force = 0;

        if (zone)
        force = zone->FindForce(c->GetIFF());

        if (force)
        force->GetDefendList().append(g);
    }

    ListIter<CombatGroup> iter = g->GetComponents();
    while (++iter) {
        ScoreDefend(c, iter.value());
    }
}
Exemplo n.º 10
0
System::System(const System& s)
: type(s.type), id(s.id), ship(0), subtype(s.subtype), status(s.status),
availability(s.availability), safety(s.safety), stability(s.stability), 
crit_level(s.crit_level), net_avail(-1.0f),
mount_rel(s.mount_rel), radius(s.radius), safety_overload(0.0f),
hull_factor(s.hull_factor), energy(s.energy), capacity(s.capacity),
sink_rate(s.sink_rate),  power_level(s.power_level), power_flags(s.power_flags),
source_index(s.source_index), power_on(s.power_on), max_value(s.max_value),
explosion_type(s.explosion_type), name(s.name), abrv(s.abrv), design(s.design),
emcon(s.emcon)
{
    if (design) {
        // cast-away const
        ListIter<Component> c = (List<Component>&) s.components;
        while (++c) {
            Component* comp = new(__FILE__,__LINE__) Component(*(c.value()));
            comp->SetSystem(this);
            components.append(comp);
        }
    }

    emcon_power[0] = s.emcon_power[0];
    emcon_power[1] = s.emcon_power[1];
    emcon_power[2] = s.emcon_power[2];
}
void
NetClientConfig::Save()
{
	FILE* f;
	fopen_s(&f, "client.cfg", "w");
	if (f) {
		fprintf(f, "CLIENT_CONFIG\n\n");

		ListIter<NetServerInfo> iter = servers;
		while (++iter) {
			NetServerInfo* server = iter.value();

			if (server->save) {
				int port = (int) server->port;
				fprintf(f, "server: {\n");
				fprintf(f, "  name: \"%s\",\n", (const char*) server->name);
				fprintf(f, "  addr: \"%s\",\n", (const char*) server->hostname);
				fprintf(f, "  port: %d,\n",                   port);

				if (server->password.length())
				fprintf(f, "  pass: \"%s\",\n", (const char*) server->password);

				fprintf(f, "}\n\n");
			}
		}

		fclose(f);
	}
}
Exemplo n.º 12
0
void
GroundAI::ExecFrame(double secs)
{
    const int exec_period = 1000;

    if ((int) Game::GameTime() - exec_time > exec_period) {
        exec_time = (int) Game::GameTime();
        SelectTarget();
    }

    if (ship) {
        Shield* shield = ship->GetShield();

        if (shield)
        shield->SetPowerLevel(100);

        ListIter<WeaponGroup> iter = ship->Weapons();
        while (++iter) {
            WeaponGroup* group = (WeaponGroup*) iter.value();

            if (group->NumWeapons() > 1 && group->CanTarget(Ship::DROPSHIPS))
            group->SetFiringOrders(Weapon::POINT_DEFENSE);
            else
            group->SetFiringOrders(Weapon::AUTO);

            group->SetTarget((Ship*) target, 0);
        }

        if (carrier_ai)
        carrier_ai->ExecFrame(secs);
    }
}
void
CampaignPlanStrategic::PlaceGroup(CombatGroup* g)
{
    if (!g)
    return;

    Text        rgn  = g->GetRegion();
    CombatZone* zone = campaign->GetZone(rgn);

    // if we couldn't find anything suitable,
    // just pick a zone at random:
    if (!zone && g->IsMovable()) {
        int nzones = campaign->GetZones().size();
        int n      = RandomIndex() % nzones;
        zone       = campaign->GetZones().at(n);

        Text assigned_rgn;
        if (!campaign->GetZone(rgn)) {
            assigned_rgn = *zone->GetRegions().at(0);
            g->AssignRegion(assigned_rgn);
        }
    }

    if (zone && !zone->HasGroup(g))
    zone->AddGroup(g);

    ListIter<CombatGroup> iter = g->GetComponents();
    while (++iter)
    PlaceGroup(iter.value());
}
void
NetGameClient::ExecFrame()
{
	if (local_player) {
		if (local_player->GetObjID() == 0) {
			SendJoinRequest();
		}

		else if (active) {
			// check health of server:
			NetPeer* server_peer = link->FindPeer(server_id);
			if (server_peer && (NetLayer::GetUTC() - server_peer->LastReceiveTime() > 15)) {
				NetMsg net_disco(0, NET_DISCONNECT, 0, 0, 0);
				DoDisconnect(&net_disco);
			}

			// if server is still there,
			else if (server_peer) {

				// check if any old join announcements still need to be processed:
				ListIter<NetJoinAnnounce> iter = join_backlog;
				while (++iter) {
					NetJoinAnnounce* join_ann = iter.value();

					if (DoJoinBacklog(join_ann)) {
						iter.removeItem();
						delete join_ann;
					}
				}
			}
		}
	}

	NetGame::ExecFrame();
}
Exemplo n.º 15
0
void
NetClientDlg::ShowServers()
{
    if (!config || !lst_servers) return;

    lst_servers->ClearItems();
    lst_servers->SetSelectedStyle(ListBox::LIST_ITEM_STYLE_FILLED_BOX);
    lst_servers->SetLeading(2);

    int i = 0;
    ListIter<NetServerInfo> iter = config->GetServerList();
    while (++iter) {
        NetServerInfo* info = iter.value();

        lst_servers->AddItemWithData(info->name, (DWORD) i);
        lst_servers->SetItemText(i, 1, info->type);
        lst_servers->SetItemText(i, 2, info->password);
        lst_servers->SetItemText(i, 3, Game::GetText("NetClientDlg.offline"));
        lst_servers->SetItemText(i, 4, "0");
        lst_servers->SetItemText(i, 5, Game::GetText("NetClientDlg.not-avail"));

        i++;
    }

    ping_index   = 0;
    server_index = -1;

    if (btn_host)  btn_host->SetEnabled(false);
    if (btn_join)  btn_join->SetEnabled(false);
    if (btn_del)   btn_del->SetEnabled(false);
}
void
CampaignPlanStrategic::ExecFrame()
{
    if (campaign && campaign->IsActive()) {
        if (Campaign::Stardate() - exec_time < 300)
        return;

        ListIter<CombatZone> zone = campaign->GetZones();
        while (++zone)
        zone->Clear();

        ListIter<Combatant>  iter = campaign->GetCombatants();
        while (++iter) {
            Combatant*     c     = iter.value();
            CombatGroup*   force = c->GetForce();

            force->CalcValue();

            PlaceGroup(force);
            ScoreCombatant(c);
            ScoreNeeds(c);

            force->ClearUnlockedZones();
            AssignZones(c);
            ResolveZoneMovement(force);
        }

        exec_time = Campaign::Stardate();
    }
}
Exemplo n.º 17
0
void
SimObject::Notify()
{
	if (!notifying) {
		notifying = true;

		int nobservers = observers.size();
		int nupdate    = 0;

		if (nobservers > 0) {
			ListIter<SimObserver> iter = observers;
			while (++iter) {
				SimObserver* observer = iter.value();
				observer->Update(this);
				nupdate++;
			}

			observers.clear();
		}

		if (nobservers != nupdate) {
			::Print("WARNING: incomplete notify sim object '%s' - %d of %d notified\n",
			Name(), nupdate, nobservers);
		}

		notifying = false;
	}
	else {
		::Print("WARNING: double notify on sim object '%s'\n", Name());
	}
}
void
CampaignPlanStrategic::ScoreTarget(Combatant* c, CombatGroup* g)
{
    if (!g || g->IntelLevel() <= Intel::SECRET)
    return;

    if (g->IsTargetable()) {
        g->SetPlanValue(g->Value() * c->GetTargetStratFactor(g->Type()));
        c->GetTargetList().append(g);

        CombatZone* zone  = campaign->GetZone(g->GetRegion());
        ZoneForce*  force = 0;

        if (zone)
        force = zone->FindForce(c->GetIFF());

        if (force)
        force->GetTargetList().append(g);
    }

    ListIter<CombatGroup> iter = g->GetComponents();
    while (++iter) {
        ScoreTarget(c, iter.value());
    }
}
Exemplo n.º 19
0
void
SeekerAI::CheckDecoys(double target_distance)
{
    // if the assigned target has the burner lit,
    // ignore the decoys:
    if (orig_target && orig_target->Augmenter()) {
        SetTarget(orig_target);
        return;
    }

    if (target && 
            target == orig_target && 
            orig_target->GetActiveDecoys().size()) {

        ListIter<Shot> decoy = orig_target->GetActiveDecoys();

        while (++decoy) {
            double decoy_distance = Point(decoy->Location() - self->Location()).length();

            if (decoy_distance < target_distance) {
                if (rand() < 1600) {
                    SetTarget(decoy.value(), 0);
                    return;
                }
            }
        }
    }
}
Exemplo n.º 20
0
int
CombatGroup::CountUnits() const
{
	int n = 0;

	CombatGroup* g = (CombatGroup*) this;

	ListIter<CombatUnit> unit = g->units;
	while (++unit)
	n += unit->Count() - unit->DeadCount();

	CombatGroup* pThis = ((CombatGroup*) this);
	pThis->live_comp.clear();
	ListIter<CombatGroup> iter = g->components;
	while (++iter) {
		CombatGroup* comp = iter.value();

		if (!comp->IsReserve()) {
			int unit_count = comp->CountUnits();
			if (unit_count > 0)
			pThis->live_comp.append(comp);

			n += unit_count;
		}
	}

	return n;
}
Exemplo n.º 21
0
void
MsnWepDlg::OnLoadout(AWEvent* event)
{
	if (!elem) return;

	ShipDesign* design   = (ShipDesign*) elem->GetDesign();
	ShipLoad*   shipload = 0;

	if (loadout_list && design) {
		int   index    = loadout_list->GetListIndex();
		Text  loadname = loadout_list->GetItemText(index);

		ListIter<ShipLoad> sl = (List<ShipLoad>&) design->loadouts;
		while (++sl) {
			if (sl->name == loadname) {
				shipload = sl.value();
			}
		}

		if (!shipload) return;

		if (lbl_weight) {
			char weight[32];
			sprintf_s(weight, "%d kg", (int) ((design->mass + shipload->mass) * 1000));
			lbl_weight->SetText(weight);
		}

		if (elem->Loadouts().size() < 1) {
			MissionLoad* l = new(__FILE__,__LINE__) MissionLoad(-1, shipload->name);
			elem->Loadouts().append(l);
		}
		else {
			ListIter<MissionLoad> l = elem->Loadouts();
			while (++l) {
				// if the player chooses a std loadout,
				// tell the sim loader to use a named
				// loadout from the ship design:
				l->SetName(shipload->name);
			}
		}

		int  nstations = design->hard_points.size();
		int* loadout   = shipload->load;

		for (int i = 0; i < 8; i++)
		loads[i] = -1;

		for (int i = 0; i < nstations; i++)
		loads[i + first_station] = PointIndexToLoad(i, loadout[i]);

		for (int i = 0; i < 8; i++) {
			for (int n = 0; n < 8; n++) {
				btn_load[i][n]->SetPicture(i == loads[n] ? led_on: led_off);
			}
		}
	}
}
Exemplo n.º 22
0
void
DisplayView::Refresh()
{
	ListIter<DisplayElement> iter = elements;
	while (++iter) {
		DisplayElement* elem = iter.value();

		// convert relative rect to window rect:
		Rect elem_rect = elem->rect;
		if (elem_rect.x == 0 && elem_rect.y == 0 && elem_rect.w == 0 && elem_rect.h == 0) {
			// stretch to fit
			elem_rect.w = width;
			elem_rect.h = height;
		}
		else if (elem_rect.w < 0 && elem_rect.h < 0) {
			// center image in window
			elem_rect.w *= -1;
			elem_rect.h *= -1;

			elem_rect.x = (width  - elem_rect.w)/2;
			elem_rect.y = (height - elem_rect.h)/2;
		}
		else {
			// offset from right or bottom
			if (elem_rect.x < 0) elem_rect.x += width;
			if (elem_rect.y < 0) elem_rect.y += height;
		}

		// compute current fade,
		// assumes fades are 1 second or less:
		double fade = 0;
		if (elem->fade_in > 0)        fade = 1 - elem->fade_in;
		else if (elem->hold > 0)      fade = 1;
		else if (elem->fade_out > 0)  fade = elem->fade_out;

		// draw text:
		if (elem->text.length() && elem->font) {
			elem->font->SetColor(elem->color);
			elem->font->SetAlpha(fade);
			window->SetFont(elem->font);
			window->DrawText(elem->text, elem->text.length(), elem_rect, DT_WORDBREAK);
		}

		// draw image:
		else if (elem->image) {
			window->FadeBitmap(  elem_rect.x, 
			elem_rect.y,
			elem_rect.x + elem_rect.w,
			elem_rect.y + elem_rect.h,
			elem->image,
			elem->color * fade,
			elem->blend );

		}
	}
}
Exemplo n.º 23
0
void
CameraDirector::CycleViewObject()
{
    if (!ship) return;

    Ship* current = external_ship;
    external_ship  = 0;

    ListIter<Contact> iter = ship->ContactList();
    while (++iter && !external_ship) {
        Contact* c = iter.value();
        Ship*    c_ship = c->GetShip();

        if (c_ship && !current) {
            external_ship = c_ship;
        }
        
        else if (current && c_ship == current) {
            while (++iter && !external_ship) {
                c = iter.value();
                if (c->ActLock())
                external_ship = c->GetShip();
            }
        }
    }

    if (external_ship != current) {
        if (external_ship) {
            if (external_ship->Life() == 0 || external_ship->IsDying() || external_ship->IsDead()) {
                external_point = external_ship->Location();
                external_ship = 0;
            }
            else {
                Observe(external_ship);
            }
        }

        if (mode == MODE_ORBIT) {
            SetMode(MODE_TRANSLATE);
            ExternalRange(1);
        }
    }
}
Exemplo n.º 24
0
void
ListBox::SizeColumns()
{
    ListBoxColumn* c = columns.first();

    if (c->percent < 0.001) {
        double total = 0;

        ListIter<ListBoxColumn> iter = columns;
        while (++iter) {
            c = iter.value();
            total += c->width;
        }

        iter.reset();
        while (++iter) {
            c = iter.value();
            c->percent = c->width / total;
        }
    }

    int usable_width = rect.w;
    int used         = 0;

    if (IsScrollVisible()) {
        usable_width -= SCROLL_WIDTH + 2;
    }
    else {
        usable_width -= 3;
    }

    for (int i = 0; i < columns.size(); i++) {
        c = columns[i];

        if (i < columns.size() - 1)
        c->width = (int) (c->percent * usable_width);
        else
        c->width = usable_width - used;

        used += c->width;
    }
}
Exemplo n.º 25
0
StarSystem*
Galaxy::GetSystem(const char* name)
{
    ListIter<StarSystem> sys = systems;
    while (++sys) {
        if (!strcmp(sys->Name(), name))
        return sys.value();
    }

    return 0;
}
Exemplo n.º 26
0
StarSystem*
Galaxy::FindSystemByRegion(const char* rgn_name)
{
    ListIter<StarSystem> iter = systems;
    while (++iter) {
        StarSystem* sys = iter.value();
        if (sys->FindRegion(rgn_name))
        return sys;
    }

    return 0;
}
Exemplo n.º 27
0
void
CombatGroup::ClearUnlockedZones()
{
	if (!zone_lock)
	assigned_zone = 0;

	ListIter<CombatGroup> iter = components;
	while (++iter) {
		CombatGroup* g = iter.value();
		g->ClearUnlockedZones();
	}
}
void
CampaignPlanStrategic::BuildGroupList(CombatGroup* g, List<CombatGroup>& groups)
{
    if (!g || g->IsReserve())
    return;

    if (g->IsAssignable())
    groups.append(g);

    ListIter<CombatGroup> iter = g->GetComponents();
    while (++iter)
    BuildGroupList(iter.value(), groups);
}
Exemplo n.º 29
0
void
CombatGroup::SetAssignedSystem(const char* s)
{
	assigned_system = s;
	assigned_zone   = 0;
	zone_lock       = false;

	ListIter<CombatGroup> iter = components;
	while (++iter) {
		CombatGroup* g = iter.value();
		g->SetAssignedSystem(s);
	}
}
Exemplo n.º 30
0
void
CombatGroup::SetAssignedZone(CombatZone* z)
{
	assigned_zone   = z;

	if (!assigned_zone)
	zone_lock = false;

	ListIter<CombatGroup> iter = components;
	while (++iter) {
		CombatGroup* g = iter.value();
		g->SetAssignedZone(z);
	}
}